Overall / notable changes:
Overall / notable changes:
8.1.0.Monolog\Logger::API can be used to distinguish between a Monolog 3, 2 or 1
install when writing integration code.Monolog\LogRecord object
with public (and mostly readonly) properties. e.g. instead of doing
$record['context'] use $record->context.
In formatters or handlers if you rather need an array to work with you can use $record->toArray()
to get back a Monolog 1/2 style record array. This will contain the enum values instead of enum cases
in the level and level_name keys to be more backwards compatible and use simpler data types.FormatterInterface, HandlerInterface, ProcessorInterface, etc. changed to contain LogRecord $record
instead of array $record parameter types. If you want to support multiple Monolog versions this should
be possible by type-hinting nothing, or array|LogRecord if you support PHP 8.0+. You can then code
against the $record using Monolog 2 style as LogRecord implements ArrayAccess for BC.
The interfaces do not require a LogRecord return type even where it would be applicable, but if you only
support Monolog 3 in integration code I would recommend you use LogRecord return types wherever fitting
to ensure forward compatibility as it may be added in Monolog 4.Monolog\LevelLogger::DEBUG, Logger::ERROR, etc. are now deprecated in favor of the Level enum.
e.g. instead of Logger::WARNING use Level::Warning if you need to pass the enum case
to Monolog or one of its handlers, or Level::Warning->value if you need the integer
value equal to what Logger::WARNING was giving you.Logger::$levels has been removed.Logger::getLevels has been removed in favor of Monolog\Level::VALUES or Monolog\Level::cases().setExceptionHandler now requires a Closure instance and not just any callable.$logLevels property you must now override the
getLevelColor method instead.normalizeRecord method is available as an extension point which is called
only when converting the LogRecord to an array. You may need this if you overrode
format previously as parent::format now needs to receive a LogRecord still
so you cannot modify it before.$logLevels property you must now override the
toSyslogPriority method instead.Closure instance
and not just a callable.Closure instance
and not just a callable.$logLevels property you must now override the
toRollbarLevel method instead.Closure instance
and not just a callable.$levelMap property you must now override the
toZendMonitorLevel method instead.reset() now requires a void return type.Monolog\Logger::API can be used to distinguish between a Monolog 1 and 2
install of Monolog when writing integration code.
Removed non-PSR-3 methods to add records, all the add* (e.g. addWarning)
methods as well as emerg, crit, err and warn.
DateTime are now formatted with a timezone and microseconds (unless disabled). Various formatters and log output might be affected, which may mess with log parsing in some cases.
The datetime in every record array is now a DateTimeImmutable, not that you
should have been modifying these anyway.
The timezone is now set per Logger instance and not statically, either via ->setTimezone or passed in the constructor. Calls to Logger::setTimezone should be converted.
HandlerInterface has been split off and two new interfaces now exist for
more granular controls: ProcessableHandlerInterface and
FormattableHandlerInterface. Handlers not extending AbstractHandler
should make sure to implement the relevant interfaces.
HandlerInterface now requires the close method to be implemented. This
only impacts you if you implement the interface yourself, but you can extend
the new Monolog\Handler\Handler base class too.
There is no more default handler configured on empty Logger instances, if you were relying on that you will not get any output anymore, make sure to configure the handler you need.
datetime is not sent anymore. Only timestamp is sent to Loggly.warning.channel routing key instead of warn.channel
as in 1.x.{date} and the date format must be set
to one of the predefined FILEPER* constants to avoid issues with file rotation.
See setFilenameFormat.