Class XLogger - Stefanius67/XLogger GitHub Wiki

Full name:     \SKien\XLogger\XLogger
Parent class:    \Psr\Log\AbstractLogger
This is an abstract class that cannot be instantiated directly


abstract class for several types of logger.

Class implements the PSR-3 LoggerInferface through AbstractLogger.

Constants

Constant Description
LOG_IP include IP-adress in log item
LOG_BT include backtrace (caller) in log item
LOG_USER include user in log item
LOG_UA include user-agent in log item

Overview

Method Description
__construct Init logging level and remote username (if set).
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.
notice Normal but significant events.
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.
warning Exceptional occurrences that are not errors.

Methods

__construct

Init logging level and remote username (if set).

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

Parameters:

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

See Also:

[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]


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]


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]


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]


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** ⚠️