From: Steven L. <le...@wr...> - 2008-01-25 19:50:38
|
The wrapper-level variable probably should be localized by any class that wraps L4p: there's no guarantee that no-one will call an un-wrapped method in L4p and botch the sequcnes. =head1 Using Log::Log4perl from wrapper classes If you don't use C<Log::Log4perl> as described above, but from a wrapper class (like your own Logging class which in turn uses C<Log::Log4perl>), the pattern layout will generate wrong data for %F, %C, %L and the like. Reason for this is that C<Log::Log4perl>'s loggers assume a static caller depth to the application that's using them. If you're using one (or more) wrapper classes, C<Log::Log4perl> will indicate where your logger classes called the loggers, not where your application called your wrapper, which is probably what you want in this case. But don't despair, there's a solution: Just increase the value of C<$Log::Log4perl::caller_depth> (defaults to 0) by one for every wrapper that's in between your application and C<Log::Log4perl>, then C<Log::Log4perl> will compensate for the difference. Using a local variable avoids problems with anyone who uses Log4perl directly; using ||= allows people to wrap YOUR wrappers without accidentally resetting the value too low. sub debug { local $Log::Log4perl::caller_depth ||= 1; ... } -- Steven Lembark +1 888 359 3508 Workhorse Computing 85-09 90th St le...@wr... Woodhaven, NY 11421 |