opxcore / log-interface
The OpxCore logger interface.
Requires
- php: ^7.4
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.5.0
README
This is interface for the log used in OpxCore and basics for building PSR-3
loggers.
Installing
composer require opxcore/log-interface
Logger basics
LogException
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.
AbstractLogger
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()