Open
Conversation
Author
|
I also looked at using Log4perl's wrapper_register but similar to using Log::Log4perl::caller_depth it requires the "downstream" caller to determine whether Log::Log4perl is in use which might be problematic. Adding this optional caller_depth argument to Plack::Middleware::Log4perl allows "downstream" callers to specify the additional caller depth without knowing or caring which middleware logging module is currently in use. If the current middleware doesn't use or need it it will be silently ignored. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional argument caller_depth to the psgix.logger anonymous sub so that callers can add additional layers of caller_depth to Log4perl output that is using Plack::Middleware::Log4perl PatternLayout config values which include the file or line number (like %F, %l and %L).
Without the ability to have the caller additionally adjust the caller depth, a psgix.logger using Log4perl always shows the immediate caller and not (necessarily) the "original" caller.
For example, when using Dancer::Logger::PSGI, the Dancer logging keywords have three additional calling layers so the %F, %l and %L placeholders point to Dancer/Logger/PSGI.pm instead of the "original" caller.
Originally I addressed this problem by using local and adjusting $Log::Log4perl::caller_depth in Dancer::Logger::PSGI which works. However, because psgix.logger is an anonymous sub, the caller to psgix.logger (Dancer::Logger::PSGI in this case) doesn't doesn't know whether the currently configured Plack logger is Log4perl or something else (like Log::Dispatch) and therefore whether $Log::Log4perl::caller_depth is even available.
Of course, to get this all to work Dancer::Logger::PSGI would also have to be modified to set the caller_depth argument when calling psgix.logger.
Perhaps there is a cleaner way to address this problem? Dancer::Logger::PSGI could just check whether Logger::Log4perl is loaded and set $Log::Log4perl::caller_depth only in that case.