Log

The Log library provides a consistent API and format for logging.

You must always use this module after threads::shared.

Synopsis

use threads::shared;
use Assure1::Log;

our $Log = new Assure1::Log({
    LogFile  => $LogFile,
    LogLevel => $LogLevel
    AppID    => $AppID
});

$Log->Message($Level, $Message);
$Log->Message($Level, [$Message1, $Message2, ...]);

Constructor

The Log library contains the constructor described below.

new

Creates a logging instance.

new(\%options)

Options

Config   -> (optional) Non-default configuration file
LogFile  -> Full path to log file
LogLevel -> Level string {OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE}
AppID    -> (optional) Unique application ID

Returns

Log instance

Methods

The Graph library contains the methods described below.

ChangeLogLevel

Changes the logging level.

ChangeLogLevel($LogLevel)

Arguments

LogLevel -> Level string {OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE}

ChangeLogFile

Changes the log file.

ChangeLogFile($LogFile)

Arguments

LogFile  -> Full path to log file

Close

Flushes and closes the log file. Will reopen file if Message is called after closing.

GetLogLevel

Gets the name of the log level that matches the specified ID.

GetLogLevel($LogLevelID)

Arguments

LogLevelID -> Level number

Returns

0 => 'OFF'
1 => 'FATAL'
2 => 'ERROR'
3 => 'WARN'
4 => 'INFO'
5 => 'DEBUG'
6 => 'TRACE'

GetLogLevelID

Gets the log level ID that matches the specified name.

GetLogLevelID($LogLevel)

Arguments

LogLevel -> Level string {OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE}

Returns

'OFF'   => 0
'FATAL' => 1
'ERROR' => 2
'WARN'  => 3
'INFO'  => 4
'DEBUG' => 5
'TRACE' => 6

IsLevel

Checks the log level by name.

IsLevel($LogLevel)

Arguments

LogLevel -> Level string {OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE}

Returns

0 => 'False'
1 => 'True'

Message

Sends a log message with a specific log level. The message can be a scalar or an array reference of multiple log messages.

Message($LogLevel, $Message)

Arguments

LogLevel -> Level string {OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE}
Message  -> String of a single message or an array reference of multiple string messages

Reopen

Forces the specified log file to close and re-open.

Reopen($LogFile)

Arguments

LogFile  -> Full path to log file