Log::Facile - Perl extension for facile logging
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 "TEMPLATE", "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($Log::Facile::TEMPLATE, 'HOSTNAME', $hostname); $logger->set($Log::Facile::TEMPLATE, 'TEMPLATE', 'HOSTNAME - DATE (LEVEL) MESSAGE'); $logger->info('template changed.');
dev01 - 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 ./using_Log_Facile.pl line 22
Log::Facile provides so facile logging that is intended for personal tools.
Default constructor. Create and return a new Log::Facile instance.
The constructor that accepts the initial value of "log_file".
The constructor that accepts the initial values of "log_file" and "swap_dir".
The getter. You will be croaked if arg key has not been defined.
The available items are "log_file", "level_debug", "level_info", "level_error", "level_warn", "level_fatal", "swap_dir", "date_format" and "debug_flag".
The getter of log template items. You will be croaked if $template_key has not been defined.
Default available items are "TEMPLATE", "DATE", "LEVEL" and "MESSAGE".
The setter. You will be croaked if arg key has not been defined.
The setter of log template items. This accessor accepts value as a new item for log template if $template_key has not been defined.
Logging $message_str at DEBUG level.
Logging $message_str at INFO level.
Logging $message_str at WARN level.
Logging $message_str at ERROR level.
Logging $message_str at FATAL level.
Swapping old log files to "swap_dir".
Swapping old log files to arg $swap_dir.
Kazuhiro Sera, <webmaster@seratch.net>
Copyright (C) 2008-2009 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.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Log::Facile, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Facile
CPAN shell
perl -MCPAN -e shell install Log::Facile
For more information on module installation, please visit the detailed CPAN module installation guide.