NAME

VUser::Log - Logging support for vuser

SYNOPSIS

use VUser::Log qw(:levels);
my $log = new VUser::Log($cfg, $ident);
my $msg = "Hello World";
$log->log($msg); # Log $msg at level LOG_NOTICE
$log->log(LOG_DEBUG, $msg); # Log $msg at level LOG_DEBUG
$log->log(LOG_DEBUG, 'Crap! %s', $msg); # Logs 'Crap! Hello World'

DESCRIPTION

Generic logging module for vuser.

Creating a New VUser::Log

$log = VUser::Log->new($cfg, $ident);
$log = VUser::Log->new($cfg, $ident, $section);
$cfg

A reference to a tied Config::IniFiles hash.

$ident

The identifier for this log object. This will be used to tag each log line as being from this object. This is similar to how syslog behaves.

$section

This tells VUser::Log which section of the configuration (represented by $cfg) to look for settings in. If not specified, vuser will be used.

Logging

When you decided that it's time to log some info you call the VUser::Log object's log() method. log() can be called in one of three ways.

  1. $log->log($level, $pattern, @args);

    $level is the log level to use. You can import the LOG_* constants into your namespace with use VUser::Log qw(:levels);.

    $pattern is a formatting pattern as used by printf().

    @args are the value for any placeholders in $pattern.

  2. $log->log($level, $message);

    You can omit the pattern and simply pass a text string to log.

  3. $log->log($message);

    You can even omit the log level and the message will be logged with a level of LOG_NOTICE.

Log Levels

The levels are, in increasing order of importance: DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, EMERG. ERR is provided as a synonym for ERROR.

You can import the LOG_* constants for use where ever log levels are needed by using use VUser::Log qw(:levels).

Use in Extensions

Extensions do not need to create a new VUser::Log object. You can simply use $main::log or do something like this:

my $log;
sub init
{
    ...
    $log = $main::log;
    ...
}

After that, you can use $log anywhere in your extension.

CONFIGURATION

[vuser]
# The log system to use.
log type = Syslog
log level = notice

Note: Each log module will have it's own configuration.

LOGGING MODULES

VUser::Log uses subclasses to do the actual logging.

REQUIRED METHODS

Subclasses of VUser::Log must override, at least, these methods.

init

Any module specific initialization should be done here. init() takes only one argument, a reference to the config hash created by Config::IniFiles.

write_msg

This method will do the actual writting of the log messages. It takes two parameters, the log level and the message.

AUTHORS

Randy Smith <perlstalker@vuser.org>

LICENSE

This file is part of vuser.

vuser is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

vuser is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with vuser; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA