| Log-Fine documentation | view source | Contained in the Log-Fine distribution. |
Log::Fine::Formatter::Template - Format log messages using template
Formats log messages for output using a user-defined template spec.
use Log::Fine::Formatter::Template;
use Log::Fine::Handle::Console;
# instantiate a handle
my $handle = Log::Fine::Handle::Console->new();
# instantiate a formatter
my $formatter = Log::Fine::Formatter::Template
->new(
name => 'template0',
template => "[%%TIME%%] %%LEVEL%% (%%FILENAME%%:%%LINENO%%) %%MSG%%\n",
timestamp_format => "%y-%m-%d %h:%m:%s"
);
# set the formatter
$handle->formatter( formatter => $formatter );
# When displaying user or group information, use the effective
# user ID
my $formatter = Log::Fine::Formatter::Template
->new(
name => 'template0',
template => "[%%TIME%%] %%USER%%@%%HOSTNAME%% %%%LEVEL%% %%MSG%%\n",
timestamp_format => "%y-%m-%d %h:%m:%s",
use_effective_id => 1,
);
# format a msg
my $str = $formatter->format(INFO, "Resistence is futile", 1);
The template formatter allows the user to specify the log format via a template, using placeholders as substitutions. This provides the user an alternative way of formatting their log messages without the necessity of having to write their own formatter object.
Note that if you desire speed, consider rolling your own Log::Fine::Formatter module.
Placeholders are case-insensitive. %%msg%% will work just as well
as %%MSG%%
+---------------+-----------------------------------+
| %%TIME%% | Timestamp |
+---------------+-----------------------------------+
| %%LEVEL%% | Log Level |
+---------------+-----------------------------------+
| %%MSG%% | Log Message |
+---------------+-----------------------------------+
| %%PACKAGE%% | Caller package |
+---------------+-----------------------------------+
| %%FILENAME%% | Caller filename |
+---------------+-----------------------------------+
| %%LINENO%% | Caller line number |
+---------------+-----------------------------------+
| %%SUBROUT%% | Caller Subroutine |
+---------------+-----------------------------------+
| %%HOSTLONG%% | Long Hostname including domain |
+---------------+-----------------------------------+
| %%HOSTSHORT%% | Short Hostname |
+---------------+-----------------------------------+
| %%LOGIN%% | User Login |
+---------------+-----------------------------------+
| %%GROUP%% | User Group |
+---------------+-----------------------------------+
Formats the given message for the given level
Level at which to log (see Log::Fine::Levels)
Message to log
Controls caller skip level
The formatted log message as specified by {template}
Under Microsoft Windows operating systems (WinXP, Win2003, Vista, Win7, etc), Log::Fine::Formatters::Template will use the following environment variables for determining user and group information:
$UID$EUID$GID$EGIDUnder MS Windows, these values will invariably be set to 0.
Please report any bugs or feature requests to
bug-log-fine-formatter-template at rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Log-Fine.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Log::Fine
You can also look for information at:
$Id: 629b9aea8554c845762c6ae1f7d6861c7a3117bc $
Christopher M. Fuhrman, <cfuhrman at panix.com>
perl, Log::Fine::Formatter
Copyright (c) 2008, 2009, 2010 Christopher M. Fuhrman, All rights reserved.
This program is free software licensed under the...
The BSD License
The full text of the license can be found in the LICENSE file included with this module.
| Log-Fine documentation | view source | Contained in the Log-Fine distribution. |