How to include logging in a Perl module?
I'd like to include logging in a Perl module I am writing, but maintain portability so that applications that use it are not bound to a specific logging mechanism, such as Log::Log4Perl.
I've considered;
- Logging to STDERR and leaving it to the application to r开发者_C百科edirect these messages to it's own logging mechanism (as mentioned in the Log::Log4Perl FAQ).
- Including no logging in the module at all.
I suspect there is a better way.
Log::Any
Log::Any allows CPAN modules to safely and efficiently log messages, while letting the application choose (or decline to choose) a logging mechanism such as Log::Dispatch or Log::Log4perl.
Whatever way you end up doing, you're going to have to pick one, and that's going to tie it to a mechanism. So may as well pick one.
Why not check if Log::Log4Perl is available? If it is, great, use it. If not, either implement a callback that your users can hook into, or a minimal set of API to let them control what (or if) you log at all?
精彩评论