Class XMLLogger - Stefanius67/XLogger GitHub Wiki

Full name:     \SKien\XLogger\XMLLogger
Parent class:    \SKien\XLogger\XLogger


PSR-3 compliant logger for Output to XML file.

This class creates a XML file that can be transformed with given xsl into HTML

Structure of the XML-File

 <log>
     <item>
         <timestamp>2020-07-21 18:22:58</timestamp>
         <user>SKien</user>
         <caller>/packages/XLogger/XLogTest.php (62)</caller>
         <level>ERROR</level>
         <message>bad conditions :-(</message>
     </item>
     <item>
         ...
     </item>
 </log>

Overview

Method Description
__construct Init logging level and remote username (if set).
addChildToDoc create new DOMNode and append it to given parent
alert Action must be taken immediately.
critical Critical conditions.
debug Detailed debug information.
emergency System is unusable.
error Runtime errors that do not require immediate action but should typically be logged and monitored.
getFilename Get current filename (may be some placeholders are supplemented).
getFullpath Get full path of the logfile.
info Interesting events.
log Logs with an arbitrary level.
notice Normal but significant events.
reset we just create new XML document
setFilename Set the filename for the logfile.
setFullpath Set the path and filename for the logfile.
setLogLevel Set the level from witch items should be logged.
setOptions Set Options for logging.
setPath Set the path for the logfile.
setUser Set the username.
setXSLFile Set XSL file to transform the log to HTML.
warning Exceptional occurrences that are not errors.

Methods

__construct

Init logging level and remote username (if set).

public XMLLogger::__construct(string $level = LogLevel::DEBUG)

Parameters:

Parameter Type Description
level string the min. LogLevel to be logged

See Also:

[go to top]


addChildToDoc

create new DOMNode and append it to given parent

public XMLLogger::addChildToDoc(string $strName, string $strValue = '', \DOMElement $oParent = null) : \DOMElement

Parameters:

Parameter Type Description
strName string
strValue string
oParent \DOMElement

Return Type: \DOMElement

[go to top]


log

Logs with an arbitrary level.

public XMLLogger::log(string $level, mixed $message, array $context = array()) : void

Parameters:

Parameter Type Description
level string
message mixed
context array

[go to top]


reset

we just create new XML document

public XMLLogger::reset() : void

[go to top]


setXSLFile

Set XSL file to transform the log to HTML.

public XMLLogger::setXSLFile(string $strXSLFilen) : void

The specified XSL must be:

  • located in the same directory as the log file
  • contain relative path to the log file
  • contain absolute path

Parameters:

Parameter Type Description
strXSLFilen string

[go to top]


Inherited methods

alert

Action must be taken immediately.

public AbstractLogger::alert(string $message, array $context = array()) : void

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

Parameters:

Parameter Type Description
message string
context array

[go to top]


critical

Critical conditions.

public AbstractLogger::critical(string $message, array $context = array()) : void

Example: Application component unavailable, unexpected exception.

Parameters:

Parameter Type Description
message string
context array

[go to top]


debug

Detailed debug information.

public AbstractLogger::debug(string $message, array $context = array()) : void

Parameters:

Parameter Type Description
message string
context array

[go to top]


emergency

System is unusable.

public AbstractLogger::emergency(string $message, array $context = array()) : void

Parameters:

Parameter Type Description
message string
context array

[go to top]


error

Runtime errors that do not require immediate action but should typically be logged and monitored.

public AbstractLogger::error(string $message, array $context = array()) : void

Parameters:

Parameter Type Description
message string
context array

[go to top]


getFilename

Get current filename (may be some placeholders are supplemented).

public XLogger::getFilename() : string

Return Type: string

See Also:

[go to top]


getFullpath

Get full path of the logfile.

public XLogger::getFullpath() : string

Return Type: string

See Also:

[go to top]


info

Interesting events.

public AbstractLogger::info(string $message, array $context = array()) : void

Example: User logs in, SQL logs.

Parameters:

Parameter Type Description
message string
context array

[go to top]


notice

Normal but significant events.

public AbstractLogger::notice(string $message, array $context = array()) : void

Parameters:

Parameter Type Description
message string
context array

[go to top]


setFilename

Set the filename for the logfile.

public XLogger::setFilename(string $strFilename) : void

Some placeholders can be used for date/month/year/week.

Parameters:

Parameter Type Description
strFilename string

See Also:

[go to top]


setFullpath

Set the path and filename for the logfile.

public XLogger::setFullpath(string $strFullpath) : void

In order to be able to assign logfiles chronologically and / or to a user, it is possible to use placeholders in the file name or path, which are replaced accordingly before the file is created. Following placeholders are supported:

  • {date} : will be replaced by current date (Format 'YYYY-MM-DD')
  • {month} : will be replaced by current month (Format 'YYYY-MM')
  • {year} : will be replaced by current year (Format 'YYYY')
  • {week} : will be replaced by current ISO-8601 week (Format 'YYYY_WW')
  • {name} : will be replaced by the username

Note:
If you use the placeholder for the user name, this have to be set BEFORE the call of this method. In the username, all characters except A-Z, a-z, 0-9, '_' and '-' are filtered out (to always get a valid file name)!

Parameters:

Parameter Type Description
strFullpath string

[go to top]


setLogLevel

Set the level from witch items should be logged.

public XLogger::setLogLevel(string $strLogLevel) : void

All entries with a lower level than the specified are ignored.
The relevance of the defined PSR-3 level from hight to low are:

  • EMERGENCY
  • ALERT
  • CRITICAL
  • ERROR
  • WARNING
  • NOTICE
  • INFO
  • DEBUG

Parameters:

Parameter Type Description
strLogLevel string the min. LogLevel to be logged

[go to top]


setOptions

Set Options for logging.

public XLogger::setOptions(int $iOptions) : void

Use any combination of:

  • XLogger::LOG_IP : include IP-adress in log item
  • XLogger::LOG_BT : include backtrace 'filename (line)' in log item
  • XLogger::LOG_USER : include user in log item
  • XLogger::LOG_UA : include user-agent in log item

Parameters:

Parameter Type Description
iOptions int any combination (bitwise or, '|') of the flags described

[go to top]


setPath

Set the path for the logfile.

public XLogger::setPath(string $strPath) : void

Some placeholders can be used for date/month/year/week.

Parameters:

Parameter Type Description
strPath string

See Also:

[go to top]


setUser

Set the username.

public XLogger::setUser(string $strUser) : void

Parameters:

Parameter Type Description
strUser string

[go to top]


warning

Exceptional occurrences that are not errors.

public AbstractLogger::warning(string $message, array $context = array()) : void

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Parameters:

Parameter Type Description
message string
context array

[go to top]


⚠️ **GitHub.com Fallback** ⚠️