How to enable logging in a Perl module?

I would like to include an entry in the Perl module that I am writing, but I support portability so that applications that use it do not bind to a specific logging mechanism, for example Login :: Log4Perl .

I thought:

  • Logging into STDERR and transferring it to the application to redirect these messages to its own logging mechanism (as indicated in the Log :: Log4Perl FAQ ).
  • The inclusion is not registered at all in the module.

I suspect there is a better way.

+6
source share
2 answers

Log :: Any

Log :: Any allows CPAN modules to log messages securely and efficiently, allowing the application to select (or refuse to choose) a logging mechanism such as Log :: Dispatch or Log :: Log4perl.

+11
source

No matter what you do, you will need to choose one, and this will attach it to the mechanism. So may also choose one.

Why not check if Log :: Log4Perl is available? If so, use it. If not, either make a callback that your users can connect to, or a minimal set of APIs that allows them to control what (or if) you register at all?

0
source

Source: https://habr.com/ru/post/898524/


All Articles