Log::ger::Manual::ForLogAny - Log::ger for Log::Any users
version 0.015
Log::Any is one of the first logging libraries on CPAN which promotes separation of producers and consumers. This means, instead of having to configure logging output in your module like this:
package MyLib; use Log::SomeLib; my $log = Log::SomeLib->new( output => ..., level => ..., ); sub mymethod { $log->warn("blah ..."); }
you just log:
package MyLibrary; use Log::Any '$log'; sub mymethod { $log->warn("blah ..."); }
and the configuration of outputs and leels is done on the application side.
Log::ger can be used in procedural style in addition to OO style. Aside from preference, this gives the benefit of being able to optimize away unneeded logging statements to avoid runtime overhead (see Log::ger::Plugin::OptAway). A procedural wrapper for Log::Any could also be written to accomplish the same, but this is native in Log::ger.
Log::ger has a smaller startup overhead compared to Log::Any. Log::Any used to be very light also (startup overhead under 1ms) until version 0.15.
Log::ger gives you customizable levels and routine names.
Log::ger allows you to log in a custom format, e.g. using block a la Log::Contextual, raw data structure as JSON, etc.
To ease migrating, Log::ger::Like::LogAny is provided. You can change this line in your code:
use Log::Any;
into:
use Log::ger::Like::LogAny;
and this:
my $log = Log::Any->get_logger;
my $log = Log::Any::Like::LogAny->get_logger;
use Log::Any '$log';
use Log::ger::Like::LogAny '$log';
Install Log::ger::Output::LogAny then in your application:
use Log::ger::Output 'LogAny';
This will send logs produced via Log::ger to Log::Any.
Install Log::Any::Adapter::LogGer then in your application:
use Log::Any::Adapter 'LogGer';
This will send logs produced via Log::Any to Log::ger.
In Log::Any, this is a way to set an adapter temporarily:
{ Log::Any::Adapter->set({lexically => \my $lex}, 'Name', ...); ... } # when $lex goes out of scope, the adapter setting is removed
One way to do this in Log::ger:
my $saved = Log::ger::Util::save_hooks('create_logml_routine'); # or create_log_routine Log::ger::Output->set('Name', ...); ... Log::ger::Util::restore_hooks('create_logml_routine', $saved);
A nicer interface may be provided in the future.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2017 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Log::ger::Manual, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::ger::Manual
CPAN shell
perl -MCPAN -e shell install Log::ger::Manual
For more information on module installation, please visit the detailed CPAN module installation guide.