NAME

Log::Fine::Formatter::Template - Format log messages using template

SYNOPSIS

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);

DESCRIPTION

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.

SUPPORTED PLACEHOLDERS

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                        |
+---------------+-----------------------------------+

METHODS

format

Formats the given message for the given level

Parameters

  • level

    Level at which to log (see Log::Fine::Levels)

  • message

    Message to log

  • skip

    Controls caller skip level

Returns

The formatted log message as specified by {template}

MICROSOFT WINDOWS CAVEATS

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

  • $EGID

Under MS Windows, these values will invariably be set to 0.

SEE ALSO

perl, Log::Fine::Formatter

AUTHOR

Christopher M. Fuhrman, <cfuhrman at panix.com>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Log::Fine

You can also look for information at:

REVISION INFORMATION

$Id: f78a096ee27dd4cb9ce072d059118bfa1383cc64 $

COPYRIGHT & LICENSE

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.