NAME

Net::SolarWinds::Log - Simple file logging module

SYNOPSIS

use Net::SolarWinds::Log;

my $log=new Net::SolarWinds::Log('/some/log/file.log');

$log->log_info("This will not be logged");
$log->log_error("This will be logged");

$log->set_loglevel(Net::SolarWinds::Log->LOG_INFO);

$log->log_info("This will now be logged");
$log->log_error("This will still be logged");

DESCRIPTION

This package provides a very simple somewhat standardized logging interface. The module itself extends Net::SolarWinds::FileRotationBase and inherits all of its features.

Exports

The following constants can be exported using the standard exporter syntax

use Net::SolarWinds::Log (qw(LOG_NONE LOG_ERROR LOG_WARN LOG_INFO LOG_DEBUG));

Default Log level

The default log level is LOG_ERROR or 1. In the default state only errors are logged.

OO Methods

  • Object constructor

    The object constructor takes key=>'value' argument pairs example:

    my $log=new Net::SolarWinds::Log(
        filename=>'/full/path/to/file.log',
        loglevel=>4,
        
        # optional, if not set the system hostname will be used
        hostname=>'somehost'
        
        # ignored when filename is set
        basefilename=>'myapp',
        folder=>'/var/myappfolder',
    
    );

    When the constructor is called with a single argument it is assumed to be the fully quallified name of the log file to manage and rotate.

    my $log=new Net::SolarWinds::Log('/some/log/file.log');
  • my $hash=$self->lookback(stack_level);

    This method returns a hash that provides information about who called this function relative to the stack_level argument. The class default value is 4.

    Example result

    {
    	# the fully qualified package that this method ran under
    	package=>'main',
    	
    	# the package and subrouteen this was called under
    	sub=>'main::some_method',
    	
    	# the source file ( may be eval or undef )
    	filename=>'/path/to/my/Script',
    	
    	# the line in wich the function was called
    	# if the internals are unsure the value is undef
    	line=>11
    }
  • my $string=$log->format_log('LEVEL=ERROR|WARN|INFO|DEBUG',"some log");

    Formats your log entry as:

    HOSTNAME PID TIMESTAMP LEVEL STACK_TRACE DATA \n

    Special notes: any undef value will be converted to a string value of 'undef'.

  • $log->log_info("message");

    Logs to a file if the log level is LOG_INFO or greater.

  • $log->log_error("message");

    Logs to a file if the log level is LOG_error or greater.

  • $log->log_die("Some message");

    Logs the message then dies.

  • $log->log_warn("message");

    Logs to a file if the log level is LOG_WARN or greater.

  • $log->log_always("message");

    Logs to a file if the log level is LOG_ALWAYS or greater.

  • $log->log_debug("message");

    Logs to a file if the log level is LOG_DEBUG or greater.

  • $log->write_to_log('LEVEL=ERROR|WARN|INFO|DEBUG','message');

    Writes 'message' to the log file with formatting representing 2 levels aboive itself in the stack.

  • my $loglevel=$log->get_loglevel;

    Returns the current runtime loglevel.

  • $log->set_loglevel(level);

    Used to set the current loglevel to the level.

Author

Michael Shipper