开发者

How to include logging in a Perl module?

开发者 https://www.devze.com 2023-04-10 00:28 出处:网络
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'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;

  1. 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).
  2. 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消