|
| | 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) |
| |
|
|
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 | $TIMESTAMP_FORMAT = 'Y-m-d\TH:i:s' |
| |
|
|
| $msgBuffer |
| |
|
| $msgOutput |
| |
|
| $logfile = null |
| |
|
| $showTimestamp = false |
| |
|
| $showInstanceId = false |
| |
|
| $useFileCV = false |
| |
|
| $cv |
| |
|
| static | $logLevels |
| |
| static | $logStyles |
| |
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)
- Copyright
- Copyright 2018 AV-RD e.U. (License: GNU General Public License (v3))
- See also
-
| 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.
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
-
| $filename | Name 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 |
| 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.
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
-
| $folder | The target folder to move the logfile to. |
| $filename | The 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:
- 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
-
| boolean | flag 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
-
| boolean | flag 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
-
| DomainException | If $logstyle is not a valid output format option. |
- See also
- $logStyles
-
isValidOutputFormat()
| Logger::writeToLogfile |
( |
|
$lines | ) |
|
Writes log buffer to a file.
Initial value:= array(
self::LEVEL_ERROR,
self::LEVEL_ALWAYS,
self::LEVEL_WARNING,
self::LEVEL_NORMAL,
self::LEVEL_INFO,
self::LEVEL_DEBUG
)
Initial value:= array(
'classic' => self::OUT_STYLE_CLASSIC,
'cv' => self::OUT_STYLE_FILECV
)
The documentation for this class was generated from the following file:
- /home/pb/avrd/projects/cinbox/bin/include/Logger.php