This is interface for the log used in OpxCore and basics for building PSR-3
loggers.
composer require opxcore/log-interface
OpxCore\Log\Exceptions\LogException::class
is base for any logger exceptions. It
extends Psr\Log\InvalidArgumentException
for PSR-3 compatibility and should be used as is or as parent for any logger
exceptions.
OpxCore\Log\AbstractLogger::class
is abstract class implementing
Psr\Log\LoggerInterface
for PSR-3 compatibility.
AbstractLogger defines several common methods to be used in loggers:
-
formatMessage(string $level, string $message, array $context = []): string
returns formatted interpolated message with log level and timestamp. -
interpolateMessage(string $message, array $context): string
interpolates the message with content. See PSR-3-logger-interface . If'exception'
key presents in context array and has any ofException::class
its stacktrace will be included to log message. -
getTimestamp(): string
returns current timestamp in ISO8601 format. -
Log levels shorthands:
emergency()
,alert()
,critical()
,error()
,warning()
,notice()
,info()
,debug()