Logger class abstract

Framework\Log\Logger

Class Logger.

Defined in libraries/log/src/Logger.php

Properties #

$destination
Logs destination.
$config
-
$level
Active log level.
$lastLog
-
$debugCollector
-

$destination

protected string $destination

Logs destination.

$config

protected array $config

$level

protected \Framework\Log\LogLevel $level = \Framework\Log\LogLevel::DEBUG

Active log level.

$lastLog

protected ?\Framework\Log\Log $lastLog = NULL

$debugCollector

protected \Framework\Log\Debug\LogCollector $debugCollector

Methods #

__construct()
Logger constructor.
getDestination()
-
getLastLog()
Get the last accepted log in the current instance.
getLevel()
-
log()
Logs with an arbitrary level.
logAlert()
Level 6: Action must be taken immediately.
logCritical()
Level 5: Critical conditions.
logDebug()
Level 0: Detailed debug information.
logEmergency()
Level 7: System is unusable.
logError()
Level 4: Runtime errors that do not require immediate action but should typically be logged and monitored.
logInfo()
Level 1: Interesting events.
logNotice()
Level 2: Normal but significant events.
logWarning()
Level 3: Exceptional occurrences that are not errors.
setDebugCollector()
-
setLevel()
-
getConfig()
-
makeId()
-
replaceContext()
-
setConfig()
-
setDestination()
-
write()
-

__construct()

public function __construct(string $destination, \Framework\Log\LogLevel|int $level = \Framework\Log\LogLevel::DEBUG, array $config = array ( ))

Logger constructor.

Parameters
  • string $destination
  • \Framework\Log\LogLevel|int $level
  • array $config

getDestination()

public function getDestination(): string
Returns string

getLastLog()

public function getLastLog(): ?\Framework\Log\Log

Get the last accepted log in the current instance.

Returns ?\Framework\Log\Log - The last Log or null if the last was not accepted

getLevel()

public function getLevel(): \Framework\Log\LogLevel
Returns \Framework\Log\LogLevel

log()

public function log(\Framework\Log\LogLevel|int $level, string $message, array $context = array ( )): bool

Logs with an arbitrary level.

Parameters
  • \Framework\Log\LogLevel|int $level
  • string $message
  • array $context
Returns bool

logAlert()

public function logAlert(string $message, array $context = array ( )): bool

Level 6: Action must be taken immediately.

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

Parameters
  • string $message
  • array $context
Returns bool

logCritical()

public function logCritical(string $message, array $context = array ( )): bool

Level 5: Critical conditions.

Example: Application component unavailable, unexpected exception.

Parameters
  • string $message
  • array $context
Returns bool

logDebug()

public function logDebug(string $message, array $context = array ( )): bool

Level 0: Detailed debug information.

Parameters
  • string $message
  • array $context
Returns bool

logEmergency()

public function logEmergency(string $message, array $context = array ( )): bool

Level 7: System is unusable.

Parameters
  • string $message
  • array $context
Returns bool

logError()

public function logError(string $message, array $context = array ( )): bool

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

Parameters
  • string $message
  • array $context
Returns bool

logInfo()

public function logInfo(string $message, array $context = array ( )): bool

Level 1: Interesting events.

Example: User logs in, SQL logs.

Parameters
  • string $message
  • array $context
Returns bool

logNotice()

public function logNotice(string $message, array $context = array ( )): bool

Level 2: Normal but significant events.

Parameters
  • string $message
  • array $context
Returns bool

logWarning()

public function logWarning(string $message, array $context = array ( )): bool

Level 3: Exceptional occurrences that are not errors.

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

Parameters
  • string $message
  • array $context
Returns bool

setDebugCollector()

public function setDebugCollector(\Framework\Log\Debug\LogCollector $debugCollector): static
Parameters
  • \Framework\Log\Debug\LogCollector $debugCollector
Returns static

setLevel()

public function setLevel(\Framework\Log\LogLevel|int $level): static
Parameters
  • \Framework\Log\LogLevel|int $level
Returns static

getConfig()

protected function getConfig(): array
Returns array

makeId()

protected function makeId(): string
Returns string

replaceContext()

protected function replaceContext(string $message, array $context): string
Parameters
  • string $message
  • array $context
Returns string

setConfig()

protected function setConfig(array $config): static
Parameters
  • array $config
Returns static

setDestination()

protected function setDestination(string $destination): static
Parameters
  • string $destination
Returns static

write()

protected abstract function write(\Framework\Log\Log $log): bool
Parameters
  • \Framework\Log\Log $log
Returns bool