opxcore / log-interface
The OpxCore logger interface.
Installs: 87
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/opxcore/log-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 = []): stringreturns formatted interpolated message with log level and timestamp. -
interpolateMessage(string $message, array $context): stringinterpolates the message with content. See PSR-3-logger-interface . If'exception'key presents in context array and has any ofException::classits stacktrace will be included to log message. -
getTimestamp(): stringreturns current timestamp in ISO8601 format. -
Log levels shorthands:
emergency(),alert(),critical(),error(),warning(),notice(),info(),debug()