[GH-ISSUE #784] Is it possible to better format logs with "big" context arrays ? #298

Closed
opened 2026-03-04 02:13:56 +03:00 by kerem · 1 comment
Owner

Originally created by @bgaillard on GitHub (May 11, 2016).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/784

Hi, for a very critical peace of code I have to output logs associated to "big" context arrays.

Here is a sample.

$this->logger->info(
    'Sample log {ctxParam1} ... {ctxParam2} ...',
    [
        'ctxParam1' => "value1",
        'ctxParam2' => "value2",
        'ctxParam3' => "value3",
        'ctxParam4' => "value4",
        'ctxParam5' => "value5",
        'ctxParam6' => "value6",
    ]

The output is the following.

[2016-05-11 16:38:13] LoggerName.INFO: Sample log value1 ... value2 .... {"ctxParam1":"value1","ctxParam2":"value2","ctxParam3":"value3","ctxParam4":"value4","ctxParam5":"value5","ctxParam6":"value6"} []

So everything is displayed on a single line which is not really easy to read. Instead I would like to change the display to something like that.

[2016-05-11 16:38:13] LoggerName.INFO: Sample log value1 ... value2 .... 
{
    "ctxParam1" : "value1",
    "ctxParam2" : "value2",
    "ctxParam3" : "value3",
    "ctxParam4" : "value4",
    "ctxParam5" : "value5",
    "ctxParam6" : "value6"
}

Is it possible ? How can I do it ?

Originally created by @bgaillard on GitHub (May 11, 2016). Original GitHub issue: https://github.com/Seldaek/monolog/issues/784 Hi, for a very critical peace of code I have to output logs associated to "big" context arrays. Here is a sample. ``` php $this->logger->info( 'Sample log {ctxParam1} ... {ctxParam2} ...', [ 'ctxParam1' => "value1", 'ctxParam2' => "value2", 'ctxParam3' => "value3", 'ctxParam4' => "value4", 'ctxParam5' => "value5", 'ctxParam6' => "value6", ] ``` The output is the following. ``` [2016-05-11 16:38:13] LoggerName.INFO: Sample log value1 ... value2 .... {"ctxParam1":"value1","ctxParam2":"value2","ctxParam3":"value3","ctxParam4":"value4","ctxParam5":"value5","ctxParam6":"value6"} [] ``` So everything is displayed on a single line which is not really easy to read. Instead I would like to change the display to something like that. ``` [2016-05-11 16:38:13] LoggerName.INFO: Sample log value1 ... value2 .... { "ctxParam1" : "value1", "ctxParam2" : "value2", "ctxParam3" : "value3", "ctxParam4" : "value4", "ctxParam5" : "value5", "ctxParam6" : "value6" } ``` Is it possible ? How can I do it ?
kerem closed this issue 2026-03-04 02:13:56 +03:00
Author
Owner

@Seldaek commented on GitHub (May 20, 2016):

It's not possible by default, but you could implement your own formatter that extends the LineFormatter and replaces \n with real new lines for example. TBH we already have too many options on it I have to say so I am quite reluctant to add even more.

<!-- gh-comment-id:220682573 --> @Seldaek commented on GitHub (May 20, 2016): It's not possible by default, but you could implement your own formatter that extends the LineFormatter and replaces \n with real new lines for example. TBH we already have too many options on it I have to say so I am quite reluctant to add even more.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#298
No description provided.