SystemLogger
Class for writing to syslog.
use SystemLogger;
# instantiate
my $sl=SystemLogger->new(ident=>"MyProcessName",priority=>"DEBUG");
# attempt to open syslog
if (!$sl->open()) { die "Unable to open syslog: ".$sl->error(); }
# log to syslog
$sl->log("I have a bad feeling about this.","WARNING");
# close syslog (if open)
$sl->close();
Class for handling writing to syslog in an easy manner.
Instantiates the SystemLogger-class.
Accepts the following parameters:
facility This is the facility to syslog to. Optional. Defaults to $Sys::Syslog::LOG_DAEMON;
ident This is the identifier to use when syslogging. SCALAR. Optional (but rather recommended). defaults to "DUMMY".
priority Sets the priority of the logging. SCALAR. Optional. Defaults to "ERR". This sets what to write to the syslog. If set to a certain level, such as "WARNING" it will syslog everything from level "WARNING" and up to and including "CRIT". Valid levels are in correct order: DEBUG, INFO, WARNING, ERR and CRIT. DEBUG is the most "talkative" level, while "CRIT" is the least.
Returns a SystemLogger instance.
Open syslog for use.
No input parameters accepted.
Attempts to open syslog for use.
Returns 1 upon success, 0 upon failure. Please check the error()- method to find out more about a potential failure.
Writes a log entry to syslog.
Accepted input is in the following order: message, priority.
Message is the message to write to syslog. SCALAR. Required.
Priority is the message priority. SCALAR. Optional. Defaults to "INFO". Valid levels are: DEBUG, INFO, WARNING, ERR and CRIT.
Only messages that are at the priority-level set in the constructor or higher will be written to syslog. Other messages are just dropped and method still returning success.
Returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.
Converts a textual priority to int.
Accepted input is "priority". SCALAR. Optional. Defaults to "ERR".
Valid priority input: DEBUG, INFO, WARNING, ERR and CRIT.
Returns the int for the specified priority, or 1 if not recognized (=INFO).
Convert int to textual priority.
Accepted input is priority int. SCALAR. Optional. Defaults to 1 (INFO).
Valid priority input: 0 (DEBUG), 1 (INFO), 2 (WARNING), 3 (ERR), 4 (CRIT).
Returns the textual priority or "INFO" if not specified or recognized.
Closes the syslog.
No input accepted.
No return value set.
Return if syslog has been opened or not?
No input accepted.
Returns 1 for open, 0 for not open.
Returns last error from the instance.
No input accepted.
Returns the last error or blank if none.