Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import logging routines into the current namespace #50

Open
preaction opened this issue Dec 8, 2016 · 0 comments
Open

Import logging routines into the current namespace #50

preaction opened this issue Dec 8, 2016 · 0 comments

Comments

@preaction
Copy link
Owner

Log::Log4perl has an :easy mode to help people easily get started with Log4perl. It has some caveats, but it is a lot easier to do:

use Log::Log4perl qw( :easy );
DEBUG "I'm debugging!";

Than it is to do:

use Log::Log4perl;
my $LOG = Log::Log4perl->get_logger();
$LOG->debug( "I'm debugging!" );

Log::Any is a bit easier still: We already have a shortcut for getting a logger:

use Log::Any qw( $LOG );
$LOG->debug( "I'm debugging!" );
die $LOG->ERROR( "Unable to do the thing: %s", $! );

But we have to remember about $LOG always. Instead, we could totally, on-demand, build a bunch of subroutines in the importing namespace that set the right category and use the formatting versions of the log methods (debugf() instead of just debug()) and return the formatted log message as expected. This way, using Log::Any requires less knowledge:

use Log::Any qw( :easy );
DEBUG "I'm debugging!";
die ERROR "Unable to do the thing: %s", $!;

We need to make sure this has the same (or similar) performance profile as the other ways, or else nobody will use it. We also likely need to do two flavors: One for the log4perl log levels, and one for the syslog log levels.

We also need to be careful about just blindly using the package name as a category, as Log4perl also needs: https://metacpan.org/pod/distribution/Log-Log4perl/lib/Log/Log4perl.pm#Pitfalls-with-Categories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant