NAME Logger.pm 
Object oriented interface to handling logfiles
VERSION
- Author:
-
Andrew DeFaria <Andrew@ClearSCM.com>
- Revision:
-
Revision 1.23
- Created:
-
Fri Mar 12 10:17:44 PST 2004
- Modified:
-
Modifed 2012/01/06 22:00:09
SYNOPSIS
Perl module for consistent creation and writing to logfiles
$log = Logger->new (
path => "/tmp"
timestamped => "yes",
append => "yes",
);
$log->msg ("This message might appear on STDOUT");
$log->log ("Stuff this message into the logfile");
if (!$log->logcmd ("ls /non-existant-dir")) {
$log->err ("Unable to proceed", 1);
} # if
$log->maillog (
to => "Andrew\@ClearSCM.com",
subject => "Logger test",
heading => "Results of Logging"
);
DESCRIPTION
Logger creates a log object that provides easy methods to log messages, errors, commands, etc. to log files. Logfiles can be created as being transient in that they will automatically disappear (unless you call the err method). You can capture the output of commands into log files and even have them autoamatically timestamped. Finally you can have logfiles automatically mailed.
ROUTINES
The following routines are exported:
new (<parms>)
Construct a new Logger object. The following OO style arguments are supported:
Parameters:
- name:
Name of the leaf portion of the log file. Default is the name of the script with ".log" appended to the logfile name. So if the calling script was called "getdb" the default log file would be called "getdb.log" (Default: Script name).
- path:
Path to create the logfile in (Default: Current working directory)
- disposition:
One of "temp" or "perm". Logfiles that are of disposition temp will be deleted when the process ends unless any calls have been made to the err method (Default: perm)
- timestamped:
If set to 0 then no timestamps will be used. If set to 1 then all lines logged will be preceeded with a timestamp (Default: 0)
- append:
If defined the logfile will be appended to (Default: Overwrite)
- extension
If defined an alternate extension to use for the log file (e.g. log.html)
Returns:
- Logger object
append ($filename)
Appends $filename to the end of the current logfile
Parameters:
- $filename
Filename to append to the logfile
Returns:
- Nothing
name
Returns the leaf portion of logfile name.
Parameters:
- None
Returns:
- Leaf node of log file name
fullname
Returns the full pathname to the logfile
Parameters:
- None
Returns:
- Full pathname to the logfile
msg ($msg, $nolinefeed)
Similar to log except verbose (See Display.pm) is used to possibly additionally write the $msg to STDOUT.
Parameters:
- $msg:
Message to display
- $nolinefeed:
If defined no linefeed is displayed at the end of the message.
Returns:
- Nothing
disp ($msg, $nolinefeed)
Similar to log except display (See Display.pm) is used to write the $msg to STDOUT and to the log file.
Parameters:
- $msg:
Message to display
- $nolinefeed:
If defined no linefeed is displayed at the end of the message.
Returns:
- Nothing
incrementErr ($msg, $errno)
Increments the error count by $increment
Parameters:
- $increment
Amount to increment (Default: 1)
Returns:
- Nothing
err ($msg, $errno)
Writes an error message to the log file. Error messages are prepended with "ERROR" and optionally "#$errno" (if $errno is specified), followed by the message. If $errno was specified then the string " - terminating" is appended to the message. Otherwise the number of errors in the log are incremented and used to determine the logfile's disposition at close time.
Parameters:
- $msg:
Message to display
- $errno:
Error number to display (also causes termination).
Returns:
- Nothing
maillog (<parms>)
Mails the current logfile. "Parms" are the same as the parameters described for Mail.pm.
Parameters:
- <See Mail.pm>
Supports all parameters that Mail::mail supports.
Returns:
- None
log ($msg, $nolinefeed)
Writes $msg to the log file. Note this is a "silent" log in that $msg is simply written to the logfile and not possibly also echoed to STDOUT (See the msg method).
Parameters:
- $msg:
Message to write to log file
- $nolinefeed:
If defined no linefeed is displayed at the end of the message.
Returns:
- Nothing
logcmd ($cmd)
Execute the command in $cmd storing all output into the logfile
- $cmd:
The command $cmd is executed with the results logged to the logfile.
Returns:
- Scalar representing the exit status of $cmd and an array of the commands output.
loglines
Returns an array of lines from the current logfile.
Parameters:
- None
Returns:
- Array of lines from the logfile
warn ($msg, $warnno)
Similar to error but logs the message as a warning. Increments the warnings count in the object thus also affecting its disposition at close time. Does not terminate the process if $warnno is specified.
Parameters:
- $msg:
Message to write to the logfile
- $warnno:
Warning number to put in the warn message (if specified)
Returns:
- Nothing
errors ()
Returns the number of errors encountered
Parameters:
- None
Returns:
- $errors
warnings ()
Returns the number of warnings encountered
Parameters:
- None
Returns:
- $warnings
CONFIGURATION AND ENVIRONMENT
DEBUG: If set then $debug in this module is set.
VERBOSE: If set then $verbose in this module is set.
DEPENDENCIES
Perl Modules
ClearSCM Perl Modules
INCOMPATABILITIES
None yet...
BUGS AND LIMITATIONS
There are no known bugs in this module.
Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
LICENSE AND COPYRIGHT
This Perl Module is freely available; 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 Perl Module 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 (http://www.gnu.org/copyleft/gpl.html) for more details.
You should have received a copy of the GNU General Public License along with this Perl Module; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. reserved.