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
<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>
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. |
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:
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
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 |
we just create new XML document
public XMLLogger::reset() : void
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 |
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 |
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 |
Detailed debug information.
public AbstractLogger::debug(string $message, array $context = array()) : void
Parameters:
Parameter | Type | Description |
---|---|---|
message |
string | |
context |
array |
System is unusable.
public AbstractLogger::emergency(string $message, array $context = array()) : void
Parameters:
Parameter | Type | Description |
---|---|---|
message |
string | |
context |
array |
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 |
Get current filename (may be some placeholders are supplemented).
public XLogger::getFilename() : string
Return Type: string
See Also:
Get full path of the logfile.
public XLogger::getFullpath() : string
Return Type: string
See Also:
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 |
Normal but significant events.
public AbstractLogger::notice(string $message, array $context = array()) : void
Parameters:
Parameter | Type | Description |
---|---|---|
message |
string | |
context |
array |
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:
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 |
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 |
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 |
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:
Set the username.
public XLogger::setUser(string $strUser) : void
Parameters:
Parameter | Type | Description |
---|---|---|
strUser |
string |
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 |