opxcore/log-interface

The OpxCore logger interface.

1.0.9 2021-02-04 16:16 UTC

This package is auto-updated.

Last update: 2024-11-05 00:22:12 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

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 of Exception::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()