NAME
Log::Facile - Perl extension for facile logging
SYNOPSIS
use Log::Facile;
my $logger = Log::Facile->new('/foo/var/log/tmp.log');
$logger->info('Log::Facile instance created!');
$logger->debug('flag off');
$logger->error('error occurred! detail.......');
$logger->warn('warning');
$logger->fatal('fatal error!');
$logger->set('debug_flag', 1);
$logger->debug('flag on');
This sample puts following logging.
2008/08/25 01:01:49 [INFO] Log::Facile instance created!
2008/08/25 01:01:49 [ERROR] error occurred! detail.......
2008/08/25 01:01:49 [WARN] warning
2008/08/25 01:01:49 [FATAL] fatal error!
2008/08/25 01:01:49 [DEBUG] flag on
Log swapping sample is following.
$logger->swap('/foo/var/log/old');
or
$logger->set('swap_dir', '/foo/var/log/old');
$logger->swap();
This time swapped log filename is 'tmp.log.1'. This file will be renamed 'tmp.log.2' while upcoming log swapping. I mean, the incremented number means older.
You can change date output format from default('yyyy/mm/dd hh:mi:ss').
$logger->set('date_format', 'yyyy-mm-dd hh-mi-ss');
$logger->info('date format changed');
$logger->set('date_format', 'yymmdd hhmiss');
$logger->info('date format changed');
This logger outputs date in following format.
2008-11-29 19-23-03 [INFO] date format changed
081129 192304 [INFO] date format changed
This is how to change level display string.
$logger->set('level_debug', 'DBG')
->set('level_info', 'INF')
->set('level_error', 'ERR');
$logger->info('Log::Facile instance created!');
$logger->debug('flag off');
$logger->error('error occurred! detail.......');
Outputs followings.
2008/11/30 04:28:51 [INF] Log::Facile instance created!
2008/11/30 04:28:51 [DBG] flag off
2008/11/30 04:28:51 [ERR] error occurred! detail.......
The default log template is
'TEMPLATE' => 'DATE [LEVEL] MESSAGE',
The defauilt log items are 'DATE', 'LEVEL' and 'MESSAGE'. It is able to edit default ones or add more items.
You can modify the log template like this.
$logger->set('date_format', 'dd/mm/yy hh:mi:ss');
$logger->set('template', 'HOSTNAME', $hostname);
$logger->set('template', 'TEMPLATE', 'HOSTNAME - DATE (LEVEL) MESSAGE');
$logger->info('template changed.');
Outputs followings.
localhost - 07/12/08 01:40:11 (INFO) template changed.
Aside, the accessors in this module checks your typo.
$logger->set('level_errror', 'ERR')
will be croaked.
invalid field name :-P - level_errror at ./sample.pl line 22
DESCRIPTION
Log::Facile provides so facile logging that is intended for personal tools.
AUTHOR
Kazuhiro Sera, <webmaster@seratch.net>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Kazuhiro Sera
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.8 or, at your option, any later version of Perl 5 you may have available.