Log::Log4Cli -- Lightweight logger for command line tools
Version 0.22
use Log::Log4Cli; $Log::Log4Cli::COLORS->{DEBUG} = 'green'; # redefine color (Term::ANSIColor notation) $Log::Log4Cli::LEVEL = 4; # set loglevel $Log::Log4Cli::POSITIONS = 1; # force file:line marks (also enables if loglevel > 4) log_fd(\*STDOUT); # print to STDOUT (STDERR by default) log_error { "blah-blah, it's an error" }; $Log::Log4Cli::COLOR = 0; # now colors disabled my $guts = { some => "value" }; log_trace { # block executed when appropriate level enabled only require Data::Dumper; return "Guts:\n" . Data::Dumper->Dump([$guts]); }; die_info 'All done', 0;
Lightweight, but sufficient and user friendly logging for command line tools with minimal impact on performance, optional configuration and no non-core dependencies.
All subroutines described below are exported by default.
die_fatal "Something terrible happened", 8;
Log message and exit with provided code. In eval blocks Carp::croak used instead of exit(). All arguments are optional. If second arg (exit code) omitted die_fatal, die_alert and die_info will exit with 127, 0 and 0 respectively.
Carp::croak
127
0
log_error { "Something went wrong!" };
Execute passed code block and write it's return value if loglevel permit so. Set $Log::Log4Cli::COLOR to false value to disable colors.
$Log::Log4Cli::COLOR
Get/set file descriptor for log messages. STDERR is used by default.
STDERR
Only builtin loglevels supported:
FATAL -1 'bold red', ERROR 0 'red', ALERT 0 'bold yellow', WARN 1 'yellow', INFO 2 'cyan', DEBUG 3 'blue', TRACE 4 'magenta'
Colors may be changed, see "SYNOPSIS". Default loglevel is ERROR (0).
ERROR
Log::Dispatch, Log::Log4perl
Term::ANSIColor
Copyright 2016-2018 Michael Samoglyadov.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Log::Log4Cli, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Log4Cli
CPAN shell
perl -MCPAN -e shell install Log::Log4Cli
For more information on module installation, please visit the detailed CPAN module installation guide.