[GH-ISSUE #1459] Set date format in Logger #616

Closed
opened 2026-03-04 02:16:26 +03:00 by kerem · 4 comments
Owner

Originally created by @delrio-design on GitHub (May 5, 2020).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1459

Some background: I am using Fluent Bit as a log forwarder for a containerized PHP application with Monolog, and want to standardize date formats across my log streams.

Some formatters, such as LineFormatter and NormalizeFormatter allow this already. I am using JsonFormatter for structured logs, it inherits from NormalizeFormatter, but I don't believe I can set the date format without subclassing it and overriding the normalize method myself. I would like to be able to set the date format globally or consistently per formatter. Given that some streams require certain date formats for ingestion by third party services, it would be nice if each step from logger to handler to stream inherited the default or global date format unless explicitly set.

Originally created by @delrio-design on GitHub (May 5, 2020). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1459 Some background: I am using Fluent Bit as a log forwarder for a containerized PHP application with Monolog, and want to standardize date formats across my log streams. Some formatters, such as LineFormatter and NormalizeFormatter allow this already. I am using JsonFormatter for structured logs, it inherits from NormalizeFormatter, but I don't believe I can set the date format without subclassing it and overriding the normalize method myself. I would like to be able to set the date format globally or consistently per formatter. Given that some streams require certain date formats for ingestion by third party services, it would be nice if each step from logger to handler to stream inherited the default or global date format unless explicitly set.
kerem 2026-03-04 02:16:26 +03:00
  • closed this issue
  • added the
    Feature
    label
Author
Owner

@Seldaek commented on GitHub (May 11, 2020):

Indeed JsonFormatter relies on jsonSerialize's implementation on Monolog\DateTimeImmutable.

I think fixing it to allow choosing a date format sounds possible and reasonable, but I am not sure about adding a default global date format option, that sounds like it's going to be a mess to handle.

<!-- gh-comment-id:626925902 --> @Seldaek commented on GitHub (May 11, 2020): Indeed JsonFormatter relies on jsonSerialize's implementation on `Monolog\DateTimeImmutable`. I think fixing it to allow choosing a date format sounds possible and reasonable, but I am not sure about adding a default global date format option, that sounds like it's going to be a mess to handle.
Author
Owner

@delrio-design commented on GitHub (May 18, 2020):

Indeed JsonFormatter relies on jsonSerialize's implementation on Monolog\DateTimeImmutable.

I think fixing it to allow choosing a date format sounds possible and reasonable, but I am not sure about adding a default global date format option, that sounds like it's going to be a mess to handle.

Thanks for the consideration! You're right about the global format, that's a broad request.

<!-- gh-comment-id:630411631 --> @delrio-design commented on GitHub (May 18, 2020): > Indeed JsonFormatter relies on jsonSerialize's implementation on `Monolog\DateTimeImmutable`. > > I think fixing it to allow choosing a date format sounds possible and reasonable, but I am not sure about adding a default global date format option, that sounds like it's going to be a mess to handle. Thanks for the consideration! You're right about the global format, that's a broad request.
Author
Owner

@Seldaek commented on GitHub (May 21, 2020):

If you feel like sending a PR for adding this to JsonFormatter please do :)

<!-- gh-comment-id:632287130 --> @Seldaek commented on GitHub (May 21, 2020): If you feel like sending a PR for adding this to JsonFormatter please do :)
Author
Owner

@Shiva-Kandagatla commented on GitHub (Sep 5, 2020):

I'm also stuck on the exact same problem. @delrio-design Can you please explain a bit more how you solved it.

<!-- gh-comment-id:687580687 --> @Shiva-Kandagatla commented on GitHub (Sep 5, 2020): I'm also stuck on the exact same problem. @delrio-design Can you please explain a bit more how you solved it.
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#616
No description provided.