Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handling mismatched log levels #1

Merged
merged 3 commits into from

2 participants

@karenetheridge

Okay, after a lot of fiddling this is what I decided:

F-- it with making the code handle this. It would require mapping log levels twice just to go through the psgix.logger coderef. It's easier to simply do this:

my $logger = Log::Dispatch->new(...);
enable 'LogDispatch', logger => $logger;

enable 'Log::Contextual', logger => $logger;

...which would mean that code buried in the $app that does log_critical { $message }; doesn't go through psgix.logger at all, therefore nothing is being broken in the PSGI standard. Of course the $app is also free to do $env->{'psgix.logger'}->({level => 'fatal', message => $message}), if it wants to avoid knowledge of what type of logger is being used.

So, the patches are limited to doc updates. I've split the wording improvements out as a separate commit in case you want to reject the other one.

Sorry again for the confusion. :/

@miyagawa
Owner

Ah I see, yes, there's a logger option supported just for this. i actually forgot about that and great you can make a good use of it.

@miyagawa miyagawa merged commit 5f939ba into miyagawa:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 50 additions and 14 deletions.
  1. +20 −4 .gitignore
  2. +15 −5 README
  3. +15 −5 lib/Plack/Middleware/Log/Contextual.pm
View
24 .gitignore
@@ -1,6 +1,22 @@
-MYMETA.*
-META.yml
-Makefile
+/META.yml
+/MYMETA.*
+/Makefile
+/Makefile.old
+/MANIFEST
+/MANIFEST.bak
+/blib/
+/pm_to_blib
+/.build
+!.gitignore
+*.bs
+/xs/*.c
+*.o
+cover_db
+*.gc??
+test-mydeps-*
+nytprof*
+/inc/
+!.gitignore
+*.sw*
inc/
-pm_to_blib
*~
View
20 README
@@ -32,7 +32,7 @@ SYNOPSIS
DESCRIPTION
Plack::Middleware::Log::Contextual is a PSGI middleware component that
integrates Log::Contextual with your application. It works as a
- standalone and could also be used in combination with PSGI logger
+ standalone and could also be used in combination with a PSGI logger
framework.
CONFIGURATION
@@ -54,7 +54,7 @@ CONFIGURATION
PSGI logger mode
This middleware also works with the middleware components that support
- "psgix.logger" extention, such as Plack::Middleware::SimpleLogger,
+ "psgix.logger" extension, such as Plack::Middleware::SimpleLogger,
Plack::Middleware::LogDispatch or Plack::Middleware::ConsoleLogger.
use Plack::Builder;
@@ -65,11 +65,21 @@ CONFIGURATION
$psgi_app;
};
- Note that the PSGI logger should be applied before this middleware.
+ Note that the PSGI logger should be applied before this middleware
+ ("psgix.logger" is set by the other middleware, and used by this one).
Unlike the standalone mode where you configure the minimum (and maximum)
level in the logger, you should configure the minimum "level" in the
- middleware configuration like seen above. It defaults to "debug".
+ middleware configuration as shown above. It defaults to "debug".
+
+ Note that the specifications for "psgix.logger" state that the supported
+ levels are ONLY debug, info, warn, error and fatal. If your application
+ emits messages at different levels than these, it is recommended that
+ you pass the logger object directly to this middleware, to bypass the
+ "psgix.logger" coderef (see "Standalone mode"), or limit your use of log
+ levels to those that overlap (for example for Log::Dispatch, only emit
+ messages with the levels debug, info, warn and error, avoiding notice,
+ critical, alert and emergency).
AUTHOR
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
@@ -82,5 +92,5 @@ LICENSE
under the same terms as Perl itself.
SEE ALSO
- Log::Contextual Plack
+ Log::Contextual Plack PSGI::Extensions
View
20 lib/Plack/Middleware/Log/Contextual.pm
@@ -80,7 +80,7 @@ Plack::Middleware::Log::Contextual - integrate Log::Contextual with Plack/PSGI l
Plack::Middleware::Log::Contextual is a PSGI middleware component that
integrates L<Log::Contextual> with your application. It works as a
-standalone and could also be used in combination with PSGI logger
+standalone and could also be used in combination with a PSGI logger
framework.
=head1 CONFIGURATION
@@ -105,7 +105,7 @@ calls get propagated to the logger object you configured.
=head2 PSGI logger mode
This middleware also works with the middleware components that support
-C<psgix.logger> extention, such as L<Plack::Middleware::SimpleLogger>,
+C<psgix.logger> extension, such as L<Plack::Middleware::SimpleLogger>,
L<Plack::Middleware::LogDispatch> or L<Plack::Middleware::ConsoleLogger>.
use Plack::Builder;
@@ -116,13 +116,23 @@ L<Plack::Middleware::LogDispatch> or L<Plack::Middleware::ConsoleLogger>.
$psgi_app;
};
-Note that the PSGI logger should be applied B<before> this middleware.
+Note that the PSGI logger should be applied B<before> this middleware
+(C<psgix.logger> is set by the other middleware, and used by this one).
Unlike the standalone mode where you configure the minimum (and
maximum) level in the logger, you should configure the minimum
-C<level> in the middleware configuration like seen above. It defaults
+C<level> in the middleware configuration as shown above. It defaults
to C<debug>.
+Note that the L<specifications for C<psgix.logger>|PSGI::Extensions> state that
+the supported levels are ONLY debug, info, warn, error and fatal. If your
+application emits messages at different levels than these, it is recommended
+that you pass the logger object directly to this middleware, to bypass the
+C<psgix.logger> coderef (see L</"Standalone mode">), or limit your use of log
+levels to those that overlap (for example for L<Log::Dispatch>, only emit
+messages with the levels debug, info, warn and error, avoiding notice,
+critical, alert and emergency).
+
=head1 AUTHOR
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
@@ -138,6 +148,6 @@ it under the same terms as Perl itself.
=head1 SEE ALSO
-L<Log::Contextual> L<Plack>
+L<Log::Contextual> L<Plack> L<PSGI::Extensions>
=cut
Something went wrong with that request. Please try again.