Log::Info - Wrapper around Log::Log4perl
This tool is now just a wrapper around Log::Log4perl. The author recommends that you use that module instead; this module is maintained purely to provide a migration path thereto.
All documentation for using Log::Info has been excised, except for that which will aid migration.
use Log::Info qw( :log_levels :default_channels Log Logf ); # The Log::Info default channels appear in Log::Log4perl as loggers called # colon-lowercase-<channelname>, e.g., INFO appears as ':info'. # # note, use init, not init_once, since Log::Info has already called init # if you have used :default_channels to auto-create the default channels # (or else contrived to call Log() or Logf() already) Log::Log4perl::init (+{ 'log4perl.rootLogger' => 'WARN, tempfile', 'log4perl.appender.tempfile' => 'Log::Log4perl::Appender::File', 'log4perl.appender.tempfile.filename' => $tempfn, 'log4perl.appender.tempfile.layout' => 'Log::Log4perl::Layout::PatternLayout', 'log4perl.appender.tempfile.layout.ConversionPattern' => '[%P:%p] %F >%c< - %m%n', 'log4perl.logger.:info' => 'INFO', 'log4perl.appender.:info' => 'Log::Log4perl::Appender::Screen', 'log4perl.appender.:info.stderr' => 1, 'log4perl.appender.:info.layout' => 'Log::Log4perl::Layout::PatternLayout', 'log4perl.appender.:info.layout.ConversionPattern' => '[%r] %F %L %c - %m%n', }); # you can still call Log, Logf, in the old Log::Info style, # just for migration... Log(CHAN_INFO, LOG_ERR, 'this is an error message'); # ...but now you should use Log::Log4perl Log::Log4perl->get_logger->warn('l1 warn'); # here we can even use the Log::Info Log::Log4perl->get_logger(':info')->warn('l2 warn');
Each of the following channels exist by default, and have their channel level set to undef. Only CHAN_INFO has a sink by default; called SINK_STDERR (a name exported with the :default_channels tag), which is a filehandle to STDERR, and is set at level LOG_WARNING.
undef
:default_channels
Each channel and sink name will be exported upon request, or together using the :default_channels tag.
Intended for progress reports, e.g., done 1 of 3 files, or 20% through.
done 1 of 3 files
20% through
Default level: LOG_WARNING
Intended for debugging messages, such as those you might output with --debug flag on.
--debug
Intended for output of statistical information; e.g., found 300 items or output file is 30M, parsing took 79s.
found 300 items
output file is 30M, parsing took 79s
Intended for warning and error messages, and those that would be output by -v.
-v
Messages that would be used with warn should be logged at level LOG_WARNING, those for a -v flag with level LOG_INFO (and LOG_DEBUG|"LOG_DEBUG" for increased verbosity).
warn
LOG_DEBUG|"LOG_DEBUG"
die messages should be logged at LOG_ERR|"LOG_ERR" level. LOG_EMERG should be reserved for conditions detected which have a significant, time-critical effect on the operating system as a whole (e.g., anything which will cause the operating system to hang or crash).
die
LOG_ERR|"LOG_ERR"
LOG_ALERT should be used for conditions which may affect the correct operation of the operating system, but will not cause the system to fail (e.g., detected filesystem faults).
LOG_CRIT should be used to indicate that some problem has been identified that is likely to adversely affect the correct operation of a system (other than the operating system) of which this program is a part, not including that this program is going to fail. An example of this is an error in a shared configuration file.
LOG_NOTICE should be used for abnormal, but not worrying conditions. For example, if a grep-like program might log a message for each file read at level LOG_INFO, but log at LOG_NOTICE files which it has not permissions to read.
Here is a fine kettle of fish.
This sink sniffs its filehandle (upon sink creation), and if it smells like a TTY, it uses it as a progress bar. Otherwise, it just sets up a file/filehandle sink as usual.
In progress-bar mode, incoming messages are examined. If they look like
m!\[([\d_,.]+/[\d_,.]+|[\d_,.]+%)(\s+[^]]*)?\s+Done\]!
Then that is treated as progress information, and the bar updated accordingly.
Filehandle to output to, or name of file. Beware: if you present a filehandle, you probably want to provide a glob ref (e.g., \*STDERR); the *foo{THING} will never act as a terminal. undef defaults to STDERR.
\*STDERR
*foo{THING}
Optional A sink message cutoff level. Defaults to undef
Default translator units provided for communal edification.
(UDT => "Un*x-Date-Time"). Prefix each message with the date and time, first in Un*x (seconds since Jan 1, 1970) format, then as the scalar gmtime output. gmtime is deliberately chosen to avoid weirdness over, say, daylight-savings time changes.
Create a new channel.
chan is not already a channel name $chan =~ /^[\w-]+$/;
name of channel. Translates directly to a Log::Log4perl channel name.
Optional. Logging level; defaults to LOG_NOTICE. Pass undef to log all messages.
delete an existing channel. Implicitly deletes all attached sinks.
chan is an existing channel name
name of channel to delete
Channel name to test for
Whether the name channel is known to Log::Info
set output cutoff level on channel
channel to set output cutoff level on
level to set to; subsequent log entries will only be written if they have level <= lvl.
Add a translator to a channel.
The channel to add the translator to.
The translator to add. The translator will be called in order after any previously added translators, and will be given the results of the log string having been through those translators. The results of the translation provided by this translator will be passed to any translators installed after this one, and to any sink-specific translators.
$chan is an existing channel name $sink =~ /^[\w-]+$/;
channel to add sink to
name of sink
sink type as string. See params for acceptable types.
Output cutoff level. Set to 'undef' to accept any messages accepted by the channel. This level is checked after the channel level; therefore, if this level is higher than the channel level, it will have no effect.
A hashref of type-specific parameters. Recognized keys are type specific:
Output to file. If the file exists, it will be appended to. Each message (call to Log) will be newline-terminated. Keys are:
Filename
Optional; maximum filesize. Files will be closed, datestamped (name will have date appended) and a new file opened if this size is about to be exceeded. Defaults to 1Gb.
Output to filehandle. Creation of, and closing of, the filehandle are the responsibility of the client. Do not delete the filehandle without closing the sink first. Each message (call to Log) will be newline-terminated. Keys are:
Filehandle to output to. May be an IO handle (*foo{IO}), a glob ref, a glob, or an instance of IO::Handle.
Callback subroutine. Keys are:
Subr to call back to (once for each call to Log). String will be passed to subr. No line terminator will be added.
Log to syslog service. Any LOG_X value provided by this module is a valid syslog level; any level that is provided that is not valid for syslog is rounded down to the nearest value. Any level that is less than all valid values is defaulted to LOG_EMERG. The message is logged with the basename of the running script, and pid.
syslog
LOG_X
Due to an artifact of Sys::Syslog, messages have a space appended when they appear in the log.
Keys are:
Optional; facility to pass to syslog to log messages under. Valid values are the FTY_ constants.
FTY_
Remove a sink from a channel.
Name of the channel to delete the sink from.
Name of the sink to delete.
channel whose sink to amend
sink to set output level of
Add a translator to a channel sink.
The sink to add the translator to.
The translator to add. The translator will be called in order after any previously added (sink-specific) translators, all of which are called after any channel translators, and will be given the results of the log string having been through those translators. The results of the translation provided by this translator will be passed to any (sink-specific) translators installed after this one.
log a message
channel to log to
message log level. Only if the log level is equal to or less than the channel log level will it be logged. For each sink, if the sink also has a level, the message will be logged to that sink only if the message level is equal to or below the sink level as well as the channel level.
The string to log. Do not append a line terminator; the sinks will do so themselves if necessary.
As for Log
As for "sprintf" in sprintf.
Add handlers to warn(), die(), to log messages to the log system. Any existing handlers are invoked after those added.
The die handler logs the message to CHAN_INFO at LOG_ERR. The warn handler logs the message to CHAN_INFO at LOG_WARNING.
CHAN_INFO
LOG_ERR
LOG_WARNING
This also traps Carp messages.
Carp
None
Set up output channel (for string based command-line options).
name of the channel to log to.
value of option presented by user. If this option looks like a simple number, it is treated as a log level (see below). If this option looks like a simple file name (m!^[A-Za-z0-9_.\\/-]+$), it will be treated as an output file (but output with the 'FH' type, so no auto-rotate, and special files will work). If this option looks like m!^:\d+!, the numeric value will be treated as a file descriptor, and output sent there. If this value is defined, but a blank string, then output will be sent to stderr.
m!^[A-Za-z0-9_.\\/-]+$
m!^:\d+!
If a value of the form \+\d+ precedes a file descriptor, or succeeds a filename, then the numeric value is used to set the log level of the output sink. If not set, it defaults to LOG_INFO, which is equivalent to +1. Hence, +0 is equivalent to LOG_INFO - 1.
\+\d+
LOG_INFO
+1
+0
LOG_INFO - 1
If this value is not defined, then no action is taken (this is to allow compatibility with options processors, where a value is left undefined if its option is never invoked).
If this value is defined but empty (''), then the log level is set to LOG_INFO (first time), and the output sent to STDERR. If the option is seen again, still with an empty string value, and with the same channel & sink names, then the log level is increased one place. This is to allow -v -v -v(or -vvv)-style options.
''
-v -v -v
-vvv
name of the option invoked (used for error messages).
the name of the sink to create.
Optional If true, generate a sink with SINK_TERM_PROGRESS
%m strings will get expanded to $! in SYSLOG sinks; this is a bug, and may get fixed at any time.
%m
SYSLOG
Email the author.
Martyn J. Pearce fluffy@cpan.org
fluffy@cpan.org
Copyright (c) 2001, 2002, 2003, 2005, 2010 Martyn J. Pearce. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head2'
To install Log::Info, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Info
CPAN shell
perl -MCPAN -e shell install Log::Info
For more information on module installation, please visit the detailed CPAN module installation guide.