Skip to content

Commit

Permalink
Fixes logging from controllers (fixes #36)
Browse files Browse the repository at this point in the history
Raisin::API exports `app` which has `log` method registered by a
logging plugin.
  • Loading branch information
Artur Khabibullin committed Aug 10, 2017
1 parent b2b4003 commit 8c9c140
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,15 @@ Or use [Raisin::Logger](https://metacpan.org/pod/Raisin::Logger) with a `fallbac

plugin 'Logger', fallback => 1;

Exports `log` subroutine.
The plugin registers a `log` subroutine to [Raisin](https://metacpan.org/pod/Raisin). Below are examples of
how to use it.

log(debug => 'Debug!');
log(warn => 'Warn!');
log(error => 'Error!');
app->log(debug => 'Debug!');
app->log(warn => 'Warn!');
app->log(error => 'Error!');

`app` is a [Raisin](https://metacpan.org/pod/Raisin) instance, so you can use `$self` instead of `app` where
it is possible.

See [Raisin::Plugin::Logger](https://metacpan.org/pod/Raisin::Plugin::Logger).

Expand Down
2 changes: 2 additions & 0 deletions examples/sample-app/lib/RESTApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ middleware 'CrossOrigin',

plugin 'Logger', outputs => [['Screen', min_level => 'debug']];

app->log(debug => 'Loading Raisin...');

swagger_setup(
title => 'Users & hosts API',
description => 'An example of API documentation.',
Expand Down
12 changes: 8 additions & 4 deletions lib/Raisin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -993,11 +993,15 @@ Or use L<Raisin::Logger> with a C<fallback> option:
plugin 'Logger', fallback => 1;
Exports C<log> subroutine.
The plugin registers a C<log> subroutine to L<Raisin>. Below are examples of
how to use it.
log(debug => 'Debug!');
log(warn => 'Warn!');
log(error => 'Error!');
app->log(debug => 'Debug!');
app->log(warn => 'Warn!');
app->log(error => 'Error!');
C<app> is a L<Raisin> instance, so you can use C<$self> instead of C<app> where
it is possible.
See L<Raisin::Plugin::Logger>.
Expand Down
8 changes: 6 additions & 2 deletions lib/Raisin/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ use Carp;
use Raisin;
use Raisin::Entity;

my @APP_CONF_METHODS = qw(api_default_format api_format api_version middleware
mount plugin register_decoder register_encoder);
my @APP_CONF_METHODS = qw(
app
api_default_format api_format api_version
middleware mount plugin
register_decoder register_encoder
);
my @APP_EXEC_METHODS = qw(new run);
my @APP_METHODS = qw(req res param include_missing session present error);
my @HOOKS_METHODS = qw(before before_validation after_validation after);
Expand Down

0 comments on commit 8c9c140

Please sign in to comment.