[GH-ISSUE #1962] Configuration of "main" log / No rotation #844

Closed
opened 2026-03-04 03:01:23 +03:00 by kerem · 4 comments
Owner

Originally created by @micter59 on GitHub (Apr 1, 2025).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1962

PHP 8.2
Symfony 7.2.3
Monolog 3.10.0

Hello, I'm using monolog with Symfony.
I configured the "main" log for rotation, but it seems rotation never happens.
Here's the config I put in monolog.yaml to configure the service :

when@dev:
    monolog:
        handlers:
            main:
                type: rotating_file
                path: "%kernel.logs_dir%/%kernel.environment%_main.log"
                level: debug
                channels: [ "!security", "!audit" ]
                max_files: 30
            security:
                type: rotating_file
                path: "%kernel.logs_dir%/%kernel.environment%_security.log"
                level: debug
                channels: [ "security" ]
                max_files: 10
            audit:
                type: rotating_file
                path: "%kernel.logs_dir%/%kernel.environment%_audit.log"
                level: debug
                channels: [ "audit" ]
                max_files: 10

For security and audit handlers, everything is ok. I've got log files each day, with names like "dev_audit-YYYY-MM-DD.log" or "dev_security-YYYY-MM-DD.log". Same configuration is done for "main" handler, but the logs never rotates. And I saw that the log file is called "dev.log", and not "dev_main.log" as configured.

Do you see anything I missed in the configuration please ?

Thank you.

Michaël

Originally created by @micter59 on GitHub (Apr 1, 2025). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1962 PHP 8.2 Symfony 7.2.3 Monolog 3.10.0 Hello, I'm using monolog with Symfony. I configured the "main" log for rotation, but it seems rotation never happens. Here's the config I put in monolog.yaml to configure the service : ```yaml when@dev: monolog: handlers: main: type: rotating_file path: "%kernel.logs_dir%/%kernel.environment%_main.log" level: debug channels: [ "!security", "!audit" ] max_files: 30 security: type: rotating_file path: "%kernel.logs_dir%/%kernel.environment%_security.log" level: debug channels: [ "security" ] max_files: 10 audit: type: rotating_file path: "%kernel.logs_dir%/%kernel.environment%_audit.log" level: debug channels: [ "audit" ] max_files: 10 ``` For security and audit handlers, everything is ok. I've got log files each day, with names like "dev_audit-YYYY-MM-DD.log" or "dev_security-YYYY-MM-DD.log". Same configuration is done for "main" handler, but the logs never rotates. And I saw that the log file is called "dev.log", and not "dev_main.log" as configured. Do you see anything I missed in the configuration please ? Thank you. Michaël
kerem 2026-03-04 03:01:23 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@stof commented on GitHub (Apr 1, 2025):

And I saw that the log file is called "dev.log", and not "dev_main.log" as configured.

Do you have other configuration in your project that may be overriding the configuration of your main handler ? That's the only explanation I see for that behavior.

<!-- gh-comment-id:2769356108 --> @stof commented on GitHub (Apr 1, 2025): > And I saw that the log file is called "dev.log", and not "dev_main.log" as configured. Do you have other configuration in your project that may be overriding the configuration of your `main` handler ? That's the only explanation I see for that behavior.
Author
Owner

@micter59 commented on GitHub (Apr 1, 2025):

I don't know really. For me, the only configuration is in this yaml file, and before the code I mentionned earlier, I've just the declaration of a new channel :

monolog:
    channels: ['audit']

This shouldn't interfere with the main handler, for what I understand.

<!-- gh-comment-id:2769422185 --> @micter59 commented on GitHub (Apr 1, 2025): I don't know really. For me, the only configuration is in this yaml file, and before the code I mentionned earlier, I've just the declaration of a new channel : ```yaml monolog: channels: ['audit'] ``` This shouldn't interfere with the main handler, for what I understand.
Author
Owner

@micter59 commented on GitHub (Apr 3, 2025):

Sorry this was a silly question. I've just found I have "monolog.yaml" file in "packages/dev", in "packages/prod" and directly in "packages"...

Just a last question about this : what is recommended ?

  1. One file in "packages"
  2. Each file in the dev/prod/test sub-folder ?
<!-- gh-comment-id:2775877197 --> @micter59 commented on GitHub (Apr 3, 2025): Sorry this was a silly question. I've just found I have "monolog.yaml" file in "packages/dev", in "packages/prod" and directly in "packages"... Just a last question about this : what is recommended ? 1) One file in "packages" 2) Each file in the dev/prod/test sub-folder ?
Author
Owner

@Seldaek commented on GitHub (Oct 24, 2025):

IMO all in one monolog.yaml is clearer so you have the overview and are less likely to do such mistakes.. when@dev: syntax lets you split env specific configs in the same file already.

<!-- gh-comment-id:3441735550 --> @Seldaek commented on GitHub (Oct 24, 2025): IMO all in one monolog.yaml is clearer so you have the overview and are less likely to do such mistakes.. `when@dev:` syntax lets you split env specific configs in the same file already.
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#844
No description provided.