The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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 "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('template', 'HOSTNAME', $hostname);
  $logger->set('template', 'TEMPLATE', 'HOSTNAME - DATE (LEVEL) MESSAGE');

  $logger->info('template changed.');

Outputs followings.

  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  

DESCRIPTION

Log::Facile provides so facile logging that is intended for personal tools.

METHODS

new()

Default constructor. Create and return a new Log::Facile instance.

new($log_file_path)

The constructor that accepts the initial value of "log_file".

new($log_file_path, $swap_dir)

The constructor that accepts the initial values of "log_file" and "swap_dir".

get($key)

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".

get('template', $template_key)

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".

set($key, $value)

The setter. 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".

set('template', $template_key, $value)

The setter of log template items. This accessor accepts value as a new item for log template if $template_key has not been defined.

Default available items are "TEMPLATE", "DATE", "LEVEL" and "MESSAGE".

debug($message_str)

Logging $message_str at DEBUG level.

info($message_str)

Logging $message_str at INFO level.

warn($message_str)

Logging $message_str at WARN level.

error($message_str)

Logging $message_str at ERROR level.

fatal($message_str)

Logging $message_str at FATAL level.

swap()

Swapping old log files to "swap_dir".

swap($swap_dir)

Swapping old log files to arg $swap_dir.

AUTHOR

Kazuhiro Sera, <webmaster@seratch.net>

COPYRIGHT AND LICENSE

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:

Around line 538:

You forgot a '=back' before '=head1'