CInbox (Common-Inbox)  0.1
Common functionality for ingesting files for archiving.
Public Member Functions | Public Attributes | Static Public Attributes
Logger Class Reference

List of all members.

Public Member Functions

 addOutputOption ($output, $logLevel, $prefixes, $showTimestamp=false, $showInstanceId=false)
 setOutputOption ($output, $option, $value)
 getPrefixShort ()
 getPrefixLong ()
 getPrefixScreen ()
 getPrefixMixed ()
 setLogfile ($filename)
 showTimestamp ($flag)
 showInstanceId ($flag)
 addMessage ($logLevel, $message, $source=null, $lineNumber=null)
 outputMsgBuffer ()
 printToScreen ($lines)
 writeToLogfile ($lines)
 formatAsText ($msgBuffer, $targetlogLevel, $prefixes)
 logAlways ($msg)
 logError ($msg)
 logWarning ($msg)
 logMsg ($msg)
 logInfo ($msg)
 logDebug ($msg)
 logException ($msg, $e)
 logErrorPhp ($msg=null)
 logNewline ($lines=1)
 logHeader ($msg)
 getHeadline ($char=self::HEADLINE_CHAR1, $width=self::HEADLINE_WIDTH1)
 getTimestamp ($format=null)
 setLogLevel ($output, $logLevel)
 moveLogfile ($folder=null, $filename=null)

Public Attributes

const LEVEL_NONE = 0
const LEVEL_DEBUG = 1
const LEVEL_INFO = 2
const LEVEL_NORMAL = 3
const LEVEL_WARNING = 5
const LEVEL_ALWAYS = 10
const LEVEL_ERROR = 20
const OUT_SCREEN = 1
const OUT_TEXTFILE = 2
const OUT_OPT_LOGLEVEL = 0
const OUT_OPT_PREFIXES = 1
const OUT_OPT_TIMESTAMPS = 2
const OUT_OPT_INSTANCEID = 3
const HEADLINE_CHAR1 = '='
const HEADLINE_CHAR2 = '-'
const HEADLINE_CHAR3 = '+'
const HEADLINE_WIDTH1 = 60
 $instanceId

Static Public Attributes

static $TIMESTAMP_FORMAT = 'Y-m-d\TH:i:s'

Detailed Description

Handles logging messages to different outputs, such as screen or files. It supports adding a preformatted timestamp, as well as the messages' loglevel to the output.

Additionally it offers a few handy ways of formatting the text output, such as adding a horizontal line, etc.

Author:
Peter Bubestinger-Steindl (pb@av-rd.com)
See also:

Member Function Documentation

Logger::addMessage ( logLevel,
message,
source = null,
lineNumber = null 
)

Puts a log message on the internal message buffer. It does NOT output anything. It only stores the message for being output later on by functions like outputMsgBuffer().

This is the main routine for logging messages.

See also:
$this->msgBuffer
$this->outputMsgBuffer()
Logger::addOutputOption ( output,
logLevel,
prefixes,
showTimestamp = false,
showInstanceId = false 
)

Configure formatting of an output option.

Logger::formatAsText ( msgBuffer,
targetlogLevel,
prefixes 
)

Formats current contents of the message buffer as text and returns it as an array of lines.

Logger::getHeadline ( char = self::HEADLINE_CHAR1,
width = self::HEADLINE_WIDTH1 
)

Returns a horizontal line consisting of '=' characters. Can be used for markdown-style headlines.

Sets long prefixes (=1 word) for each type of log message.

Similar to getPrefixScreen(), but keeps the 1-letter abbreviations for non-error/warning messages. Makes it easier for operators to spot problems when reading the logs.

Screen output does not prefix all messages, so it's easier to read. It still prefixes important / irregular messages though, such as errors/warning and debug messages.

Sets short prefixes (=1 letter) for each type of log message.

Logger::getTimestamp ( format = null)

Returns a pre-formatted timestamp string. Default format is self::TIMESTAMP_FORMAT.

Logger::logErrorPhp ( msg = null)

Logs error message, but adds information from PHP's internal error handler.

error_get_last()

Logger::logException ( msg,
e 
)

Logs the given exception $e as error message.

Logger::logHeader ( msg)

Logs a pre-formatted block that makes it possible to indicate a new logging session.

Logger::logNewline ( lines = 1)

Write an empty line into the logs. Used for visual spacing between entries.

Logger::moveLogfile ( folder = null,
filename = null 
)

Relocate the logfile to a new folder or change its name.

Parameters:
$folderThe target folder to move the logfile to.
$filenameThe target filename to rename the logfile to.

You can set either $folder or $filename - or both. But you have to set at least one of them.

Outputs the current message buffer to different output formats (screen, file, etc). The message buffer is cleared afterwards.

See also:
$this->msgOutput
$this->showTimestamp()
$this->showInstanceId()
Logger::printToScreen ( lines)

Simply prints the contents of an array of text-lines to the screen.

Used to set the boolean flag whether to show the instance ID of the logger class object in log messages.

The instance ID can be used to identify each Logger object instance and is useful to debug which Logger object was used where.

Parameters:
booleanflag Turn instance ID on/off (true = show instance ID, false = hide instance ID).
See also:
$this->showInstanceId
Logger::showTimestamp ( flag)

Used to set the boolean flag whether to show the timestamp in log messages.

Parameters:
booleanflag Turn timestamp on/off (true = show timestamp, false = hide timestamp).
See also:
$this->showTimestamp
Logger::writeToLogfile ( lines)

Writes log buffer to a file.


The documentation for this class was generated from the following file:
 All Classes Functions Variables