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

Public Member Functions

 setOutputFormat ($logstyle)
 
 addOutputOption ($output, $logLevel, $prefixes, $showTimestamp=false, $showInstanceId=false)
 
 setOutputOption ($output, $option, $value)
 
 getPrefixShort ()
 
 getPrefixLong ()
 
 getPrefixScreen ()
 
 getPrefixMixed ()
 
 setLogfile ($filename)
 
 getLogfile ()
 
 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)
 
 logPlain ($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)
 

Static Public Member Functions

static isValidOutputFormat ($logstyle)
 
static validateOutputFormat ($logstyle)
 

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 OUT_STYLE_CLASSIC = 0
 
const OUT_STYLE_FILECV = 1
 
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'
 

Private Attributes

 $msgBuffer
 
 $msgOutput
 
 $logfile = null
 
 $showTimestamp = false
 
 $showInstanceId = false
 
 $useFileCV = false
 
 $cv
 

Static Private Attributes

static $logLevels
 
static $logStyles
 

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.nosp@m.-rd..nosp@m.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
$msgBuffer
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.

Logger::getLogfile ( )

Gives the name of the logfile (path + filename) as string. If filename is empty (or not set yet), it returns False.

Returns
string if set, False if not (or empty).
Return values
$filenameName of the logfile (path+filename).
Logger::getPrefixLong ( )

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

Logger::getPrefixMixed ( )

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.

Logger::getPrefixScreen ( )

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.

Logger::getPrefixShort ( )

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.

static Logger::isValidOutputFormat (   $logstyle)
static

Checks if the given $logstyle is a valid option. You can also use validateOutputFormat(), if you use Exception handling.

See also
$logStyles
validateOutputFormat()
Returns
True if valid, False if not.
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::logPlain (   $msg)

Writes the message to the logfile, without any headers, prefix or anything. Just plain, as-is. Currently, it's identical to calling "writeToLogFile()".

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.

Logger::outputMsgBuffer ( )

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

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

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

Logger::setOutputFormat (   $logstyle)

Change output format. Current options for $logstyle:

  • 0: classic
  • 1: fileCV
See also
$logStyles
Logger::showInstanceId (   $flag)

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
$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
$showTimestamp
static Logger::validateOutputFormat (   $logstyle)
static

Similar to isValidOutputFormat(), but already throws an exception including an error message.

Exceptions
DomainExceptionIf $logstyle is not a valid output format option.
See also
$logStyles
isValidOutputFormat()
Logger::writeToLogfile (   $lines)

Writes log buffer to a file.

Member Data Documentation

Logger::$logLevels
staticprivate
Initial value:
= array(
self::LEVEL_ERROR,
self::LEVEL_ALWAYS,
self::LEVEL_WARNING,
self::LEVEL_NORMAL,
self::LEVEL_INFO,
self::LEVEL_DEBUG
)
Logger::$logStyles
staticprivate
Initial value:
= array(
'classic' => self::OUT_STYLE_CLASSIC,
'cv' => self::OUT_STYLE_FILECV
)

The documentation for this class was generated from the following file: