Log message structure
Within monolog log messages are passed around as Monolog\LogRecord objects, for example to processors or handlers.
The table below describes the properties available.
|message||string||The log message. When the
|level||Monolog\Level case||Severity of the log message. See log levels described in 01-usage.md.|
|context||array||Arbitrary data passed with the construction of the message. For example the username of the current user or their IP address.|
|channel||string||The channel this message was logged to. This is the name that was passed when the logger was created with
|datetime||Monolog\DateTimeImmutable||Date and time when the message was logged. Class extends
|extra||array||A placeholder array where processors can put additional data. Always available, but empty if there are no processors registered.|
At first glance
extra look very similar, and they are in the sense that they both carry arbitrary data that is related to the log message somehow.
The main difference is that
context can be supplied in user land (it is the 3rd parameter to
Psr\Log\LoggerInterface methods) whereas
extra is internal only
and can be filled by processors. The reason processors write to
extra and not to
context is to prevent overriding any user-provided data in
All properties except
extra are read-only.
Note: For BC reasons with Monolog 1 and 2 which used arrays,
ArrayAccessso you can access the above properties using
$record['message']for example, with the notable exception of
level->getName()which must be referred to as