Net::Daemon::Log(3pm)

Net::Daemon::Log3pm

Utility functions for logging

Usage

  # Choose logging method: syslog or Win32::EventLog
  $self->{'facility'} = 'mail'; # Default: Daemon
  $self->{'logfile'} = undef;   # Default
  # Choose logging method: stderr
  $self->{'logfile'} = 1;
  # Choose logging method: IO handle
  my $file = IO::File->new("my.log", "a");
  $self->{'logfile'} = $file;
  # Debugging messages (equivalent):
  $self->Log('debug', "This is a debugging message");
  $self->Debug("This is a debugging message");
  # Error messages (equivalent):
  $self->Log('err', "This is an error message");
  $self->Error("This is an error message");
  # Fatal error messages (implies 'die')
  $self->Fatal("This is a fatal error message");

Warning

THIS IS ALPHA SOFTWARE. It is *only* 'Alpha' because the interface (API) is not finalised. The Alpha status does not reflect code quality or stability.

Overview

Net::Daemon::Log is a utility class for portable logging messages. By default it uses syslog (Unix) or Win32::EventLog (Windows), but logging messages can also be redirected to stderr or a log file.

Generic Logging

    $self->Log($level, $msg, @args);

This is the generic interface. The logging level is in syslog style, thus one of the words 'debug', 'info', 'notice', 'err' or 'crit'. You'll rarely need info and notice and I can hardly imagine a reason for crit (critical). In 95% of all cases debug and err will be sufficient.

The logging string $msg is a format string similar to printf.

Utility methods

    $self->Debug($msg, @args);
    $self->Error($msg, @args);
    $self->Fatal($msg, @args);

These are replacements for logging with levels debug and err. The difference between the latter two is that Fatal includes throwing a Perl exception.

Chossing a logging target

By default logging will happen to syslog (Unix) or EventLog (Windows). However you may choose logging to stderr by setting

    $self->{'logfile'} = 1;

This is required if neither of syslog and EventLog is available. An alternative option is setting

    $self->{'logfile'} = $handle;

where $handle is any object supporting a print method, for example an IO::Handle object. Usually the logging target is choosen as soon as you call $self->Log() the first time. However, you may force choosing the target by doing a

    $self->OpenLog();

before calling Log the first time.

Multithreading

The Multithreading capabitities of this class are depending heavily on the underlying classes Sys::Syslog, Win32::EventLog or IO::Handle. If they are thread safe, you can well assume that this package is too. (The exception being that you should better call $self->OpenLog() before threading.)

Releases

12 releases since Debian 3.0 (Woody); the text changed 8 times.

  1. 3.0
  2. 3.1
  3. 4.0–5.0
  4. 6.0
  5. 7–8
  6. 9–10
  7. 11
  8. 12
  9. 13

From libnet-daemon-perl 0.49-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.