NAME
Log::Trivial - Very simple tool for writing very simple log files
SYNOPSIS
use Log::Trivial;
my $logger = Log::Trivial->new(log_file => "path/to/my/file.log");
$logger->set_level(3);
$logger->log(comment => "foo");
DESCRIPTION
Use this module when you want use "Yet Another" very simple, light weight log file writer.
METHODS
new
The constructor can be called empty or with a number of optional parameters.
$logger = Log::Trivial->new();
or
$logger = Log::Trivial->new(
log_file => "/my/config/file",
log_level=> "2");
set_log_file
The log file can be set after the constructor has been called. Simply set the path to the file you want to use as the log file.
$logger->set_log_file("/path/to/log.file");
set_log_mode
Log::Trivial runs in two modes. The default mode is Multi mode: in this mode the file will be opened and closed for each log file write. This may be slower but allows multiple applications to write to the log file at the same time. The alternative mode is called single mode: once you start to write to the log no other application honouring flock will write to the log. Single mode is potentially faster, and may be appropiate if you know that only one copy of your application can should be writing to the log at any given point in time
$logger->set_log_mode("multi"); # Sets multi mode (the default)
or
$logger->set_log_mode("single"); # Sets single mode
set_log_level
Log::Trivial uses very simple aribtatary logging level logic. Level 0 is the highest priority log level, the lowest is the largest number possible in Perl on your platform. You set the global log level for your application using this function, and only log events of this level or higher priority will be logged.
$logger->set_log_level(4);
write
Write a log file entry.
$logger->write(
comment => "My comment to be logged",
level => 3);
or
$logger->write("My comment to be logged");
It will fail if the log file hasn't be defined, or isn't writeable. It will return the string written on sucess.
If you don't specify a log level, it will default to the current log level and therefore log the event. Therefore if you always wish to log something either specify a level of 0 or never specify a log level.
Log file enteries are time stamped and have a newline carriage return added automatically.
get_error
In normal operation the module should never die. All errors are non-fatal. If an error occurs it can a method will return undef and the error can be read with the get_error method. Only the most recent error is stored.
$logger->write("Log this") || print $logger->get_error;
LOG FORMAT
The log file format is very simple and fixed:
Time & date [tab] Your log comment [carriage return new line]
Prerequisites
At the moment the module only uses core modules. The test suite optionally uses Pod::Coverage
, Test::Pod::Coverage
and Test::Pod
, which will be skipped if you don't have them.
History
See Changes file.
Defects and Limitations
Patches Welcome... ;-)
To Do
Much better test suite.
EXPORT
None.
AUTHOR
Adam Trickett, <atrickett@cpan.org>
SEE ALSO
perl, Log::Agent, Log::Log4perl, Log::Dispatch, Log::Simple
COPYRIGHT
This version as Log::Trivial
, Copyright iredale consulting 2005
OSI Certified Open Source Software.
This program 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.
This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.