First thing first, look at the class
vendor/monolog/monolog/src/Monolog/Logger.php which is responsible with writing the log messages. This class implements all the functions to add debug, info, alert, notice, critical or error messages (as per PSR-3) and they all call the following method:
* Adds a log record at an arbitrary level.
* This method allows for compatibility with common interfaces.
* @param mixed $level The log level
* @param string $message The log message
* @param array $context The log context
* @return bool Whether the record has been processed
public function log($level, $message, array $context = array())
$level = static::toMonologLevel($level);
return $this->addRecord($level, $message, $context);
Say I call the method like this:
$logger->log('ERROR','my custom error message', [['id'=>'1', 'name' => 'test'], ['var1'=>'value1']]);
This call will log in
var/log/system.log the following content:
] main.ERROR: my custom error message
I specified the message level ERROR, the message string AND I also printed an array with data also known as context. This is very useful when you also want to print which data was used when the error appeared, it helps a lot in the debug process.
As you can see, the array before last got populated with the JSON representation of my provided data array. You will also see this in exceptions handling where the exception can be passed as context.
As for the last array, I didn't see it in action so far, but I know it's the extra key that we see in
addRecord() method from
$record = array(
'message' => (string) $message,
'context' => $context,
'level' => $level,
'level_name' => $levelName,
'channel' => $this->name,
'datetime' => $ts,
'extra' => array(),
How do I know this? By looking at the class
vendor/monolog/monolog/src/Monolog/Formatter/LineFormatter.php which is used to format the log lines, where the first thing you see is this:
const SIMPLE_FORMAT = "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
format() method of this class, the record's content is processed and formatted and you can see that the 'context' and 'extra' keys are prepared to be written in the format given by the
So all I can tell about the second array, is that this is the content from extra key, but I haven't worked with it, nor see it used so far. If you search for 'extra' in the
vendor/monolog/monolog you will see other formatters and handlers using it, so there is a use to it, we just didn't see it in action in the logs.