[GH-ISSUE #1947] Is it possible to truncate ALL log messages so that they don't exceed a particular length? #840

Open
opened 2026-03-04 03:01:17 +03:00 by kerem · 1 comment
Owner

Originally created by @armclosinglock on GitHub (Feb 18, 2025).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1947

Monolog version 3

Is it possible to truncate all messages to not exceed a length of say 5000, or 10000 characters?

I see that in Monolog version 3, messages are immutable so the following does NOT work.

$record['message'] = substr($record['message'], 0, 5000);

I tried something like

$record->withMessage(substr($record['message'],0, 5000));

as well, but I ran into a strange error running compose install in the pipeline that seems to be related to this change that I don't quite understand.

Originally created by @armclosinglock on GitHub (Feb 18, 2025). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1947 Monolog version 3 Is it possible to truncate all messages to not exceed a length of say 5000, or 10000 characters? I see that in Monolog version 3, messages are immutable so the following does NOT work. ```php $record['message'] = substr($record['message'], 0, 5000); ``` I tried something like ```php $record->withMessage(substr($record['message'],0, 5000)); ``` as well, but I ran into a strange error running compose install in the pipeline that seems to be related to this change that I don't quite understand.
Author
Owner

@Seldaek commented on GitHub (Mar 15, 2025):

That should happen in the formatter IMO, or if you do it in a processor you should be able to use withMessage you just have to make sure you return the new (cloned & modified) record instance.

<!-- gh-comment-id:2726540100 --> @Seldaek commented on GitHub (Mar 15, 2025): That should happen in the formatter IMO, or if you do it in a processor you should be able to use withMessage you just have to make sure you return the new (cloned & modified) record instance.
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#840
No description provided.