plack/Plack — pull request #461 by jwittkoski (2014-06-11 02:43:25+00:00)
Title: Add caller_depth arg

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.