NAME

HeliosX::Logger::Log4perl - HeliosX::Logger subclass implementing logging to Log4perl for Helios

SYNOPSIS

# in your helios.ini
loggers=HeliosX::Logger::Log4perl
log4perl_conf=/path/to/log4perl.conf
log4perl_category=logging.category
log4perl_watch_interval=10

# log4perl supports lots of options, so you can get creative
# log everything to log4perl, but specify which services go to which categories
[global]
internal_logging=off
loggers=HeliosX::Logger::Log4perl
log4perl_conf=/etc/helios_log4perl.conf

# log all the MyApp::* services to the same log4perl category 
[MyApp::MetajobBurstService]
log4perl_category=MyApp
[MyApp::IndexerService]
log4perl_category=MyApp
[MyApp::ReportingService]
log4perl_category=MyApp

[YourApp]
# we won't specify a category here, so Helios will default to category 'YourApp'

DESCRIPTION

This class extends the HeliosX::Logger class to provide a shim between HeliosX::ExtLoggerService and Log::Log4perl. This allows Helios applications using HeliosX::ExtLoggerService to use Log4perl logging facilities.

For information about configuring Log4perl, see the Log::Log4perl documentation.

HELIOS.INI CONFIGURATION

log4perl_conf [REQUIRED]

The location of the Log4perl configuration file. This can be one conf file for all of your HeliosX::ExtLoggerService services (specified in the [global] section), or you can have different conf files for different services.

See the Log4perl documentation for details about configuring Log4perl itself.

log4perl_category

The Log4perl "category" to log messages for this service. You can declare this only in the [global] section, which will cause all HeliosX::ExtLoggerService services to log to one category. Or, you can declare it in the [global] section and in certain individual service sections, which will allow certain services to log to their own category but others to default to the global one. If not specified, the Log4perl category will default to the service name/jobtype (from getJobType()).

log4perl_watch_interval

If specified, Log4perl will reread the log4perl_conf file every specified number of seconds and update its configuration accordingly. If this isn't specified, any changes to your conf file will require a service restart.

IMPLEMENTED METHODS

init($config, $jobType)

The init() method verifies log4perl_conf is set in helios.ini and can be read. It then calls Log::Log4perl::init() or (if log4perl_watch_interval is set) Log::Log4perl::init_and_watch() to set up the Log4perl system for logging.

logMsg($job, $priority_level, $message)

The logMsg() method logs the given message to the configured log4perl_category with the given $priority_level.

Priority Translation

Helios was originally developed using Sys::Syslog as its sole logging system. It eventually developed its own internal logging subsystem, and HeliosX::ExtLoggingService and HeliosX::Logger are new developments to further modularize Helios's logging capabilities and make it useful in more environments. Due to this history, however, the base Helios system and HeliosX::ExtLoggerService define 8 logging priorities versus Log4perl's 5. HeliosX::Logger::Log4perl translates on-the-fly several of the priority levels defined in HeliosX::LogEntry::Levels to Log4perl's levels:

HeliosX::LogEntry::Levels  Log::Log4perl::Level
LOG_EMERG                  $FATAL
LOG_ALERT                  $FATAL
LOG_CRIT                   $FATAL
LOG_ERR                    $ERROR
LOG_WARNING                $WARN
LOG_NOTICE                 $INFO
LOG_INFO                   $INFO
LOG_DEBUG                  $DEBUG

assembleMsg($job, $priority_level, $msg)

Given the information passed to logMsg(), assembleMsg() returns the text string to be logged to the Log4perl category. Separating this step into its own method allows you to easily override the default message format if you so choose. Simply subclass HeliosX::Logger::Log4perl and override assembleMsg() with your own message formatting method.

SEE ALSO

HeliosX::ExtLoggerService, HeliosX::Logger, Log::Log4perl

AUTHOR

Andrew Johnson, <lajandy at cpan dotorg>

COPYRIGHT AND LICENSE

Copyright (C) 2009 by Andrew Johnson

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.

WARRANTY

This software comes with no warranty of any kind.