The \*(c`log::loglite\*(c' class helps us create simple logs for our application.
use Log::LogLite; my $LOG_DIRECTORY = "/where/ever/our/log/file/should/be"; my $ERROR_LOG_LEVEL = 6; # create new Log::LogLite object my $log = new Log::LogLite($LOG_DIRECTORY."/error.log", $ERROR_LOG_LEVEL); ... # we had an error $log->write("Could not open the file ".$file_name.": $!", 4);
In order to have a log we have first to create a \*(C`Log::LogLite\*(C' object. The c<Log::LogLite> object is created with a logging level. The default logging level is 5. After the \*(C`Log::LogLite\*(C' object is created, each call to the \*(C`write\*(C' method may write a new line in the log file. If the level of the message is lower or equal to the logging level, the message will be written to the log file. The format of the logging messages can be controled by changing the template, and by defining a default message. The class uses the IO::LockedFile class.
The constructor. \s-1FILEPATH\s0 is the path of the log file. \s-1LEVEL\s0 is the defined logging level - the \s-1LEVEL\s0 data member. \s-1DEFAULT_MESSAGE\s0 will define the \s-1DEFAULT_MESSAGE\s0 data member - a message that will be added to the message of each entry in the log (according to the \s-1TEMPLATE\s0 data member, see below). The levels can be any levels that the user chooses to use. There are, though, recommended levels:
0 the application is unusable 1 the application is going to be unusable 2 critical conditions 3 error conditions 4 warning conditions 5 normal but significant condition 6 informational 7+ debug-level messages
The default value of \s-1LEVEL\s0 is 5. The default value of \s-1DEFAULT_MESSAGE\s0 is "". Returns the new object.
If \s-1LEVEL\s0 is less or equal to the \s-1LEVEL\s0 data member, or if \s-1LEVEL\s0 is undefined, the string in \s-1MESSAGE\s0 will be written to the log file. Does not return anything.
Access method to the \s-1LEVEL\s0 data member. If \s-1LEVEL\s0 is defined, the \s-1LEVEL\s0 data member will get its value. Returns the value of the \s-1LEVEL\s0 data member.
Access method to the \s-1DEFAULT_MESSAGE\s0 data member. If \s-1MESSAGE\s0 is defined, the \s-1DEFAULT_MESSAGE\s0 data member will get its value. Returns the value of the \s-1DEFAULT_MESSAGE\s0 data member.
If this flag is set to true, the <called_by> string will hold the file that calls the subroutine and the line where the call is issued. The default value is zero.
Access method to the \s-1TEMPLATE\s0 data member. The \s-1TEMPLATE\s0 data member is a string that defines how the log entries will look like. The default \s-1TEMPLATE\s0 is: '[<date>] <<level>> <called_by><default_message><message>' Where: <date> will be replaced by a string that represent the date. For example: 09/01/2000 17:00:13 <level> will be replaced by the level of the entry. <called_by> will be replaced by a call trace string. For example: CGIDaemon::listen > MyCGIDaemon::accepted <default_message> will be replaced by the value of the DEFAULT_MESSAGE data member. <message> will be replaced by the message string that is sent to the C<write> method. Returns the value of the \s-1TEMPLATE\s0 data member.
Rani Pinchuk, [email protected]
Copyright (c) 2001-2002 Ockham Technology N.V. & Rani Pinchuk. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
IO::LockedFile\|(3)