| Log::Fine::Formatter::Template - Format log messages using template |
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->setFormatter( 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,
);
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 the Log::Fine::Levels manpage)
Message to log
Controls caller skip level
The formatted log message as specified by {template}
perl, the Log::Fine::Formatter manpage
Christopher M. Fuhrman, <cfuhrman at panix.com>
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.
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: 6330475f91a479049edbae8feb6823a4b9742ad9 $
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::Formatter::Template - Format log messages using template |