[GH-ISSUE #154] Monolog + E-Mail/Swift + Buffer = no E-Mail #50

Closed
opened 2026-03-04 02:11:41 +03:00 by kerem · 6 comments
Owner

Originally created by @raziel057 on GitHub (Jan 30, 2013).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/154

Hello,

After my Symfony project is allready finished I wanted to include some logging. With Monolog I quickly able to log into files, but I want some E-Mails if an error occurs.
I copy the config from the documentation, but I don't recieve any E-Mail.

    My config:
            mail:
                type: fingers_crossed
                action_level: error
                handler: buffered
            buffered:
                type: buffer
                handler: swift
            swift:
                type:       swift_mailer
                from_email: example@example.de
                to_email:   example@example.de
                subject:    An Error Occurred!
                level:      debug

If I change it to:

My config:
        mail:
            type: fingers_crossed
            action_level: error
            handler: swift
        swift:
            type:       swift_mailer
            from_email: example@example.de
            to_email:   example@example.de
            subject:    An Error Occurred!
            level:      debug

So disable the buffer. I get E-Mails, but to many (thats the reason for the buffer ...).

How can I activate the buffer and still get E-Mails? Is there any bug in the BufferHandler?

Here is my composer.json config:

    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.1.7",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.1.*",
        "twig/extensions": "1.0.*@dev",
        "symfony/assetic-bundle": "2.1.*",
        "symfony/swiftmailer-bundle": "2.1.*",
        "symfony/monolog-bundle": "2.1.*",
        "sensio/distribution-bundle": "2.1.*",
        "sensio/framework-extra-bundle": "2.1.*",
        "sensio/generator-bundle": "2.1.*",
        "jms/security-extra-bundle": "1.2.*",
        "jms/di-extra-bundle": "1.1.*",
        "kriswallsmith/assetic": "1.1.*@dev",
        "friendsofsymfony/jsrouting-bundle": "1.0.*",
        "phpexcel/phpexcel": "dev-master",
        "genemu/form-bundle": "2.1.*",
        "whiteoctober/tcpdf-bundle": "dev-master",
        "avalanche123/imagine-bundle": "dev-master"
    },
Originally created by @raziel057 on GitHub (Jan 30, 2013). Original GitHub issue: https://github.com/Seldaek/monolog/issues/154 Hello, After my Symfony project is allready finished I wanted to include some logging. With Monolog I quickly able to log into files, but I want some E-Mails if an error occurs. I copy the config from the documentation, but I don't recieve any E-Mail. ``` My config: mail: type: fingers_crossed action_level: error handler: buffered buffered: type: buffer handler: swift swift: type: swift_mailer from_email: example@example.de to_email: example@example.de subject: An Error Occurred! level: debug ``` If I change it to: ``` My config: mail: type: fingers_crossed action_level: error handler: swift swift: type: swift_mailer from_email: example@example.de to_email: example@example.de subject: An Error Occurred! level: debug ``` So disable the buffer. I get E-Mails, but to many (thats the reason for the buffer ...). How can I activate the buffer and still get E-Mails? Is there any bug in the BufferHandler? Here is my composer.json config: ``` "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.7", "doctrine/orm": ">=2.2.3,<2.4-dev", "doctrine/doctrine-bundle": "1.1.*", "twig/extensions": "1.0.*@dev", "symfony/assetic-bundle": "2.1.*", "symfony/swiftmailer-bundle": "2.1.*", "symfony/monolog-bundle": "2.1.*", "sensio/distribution-bundle": "2.1.*", "sensio/framework-extra-bundle": "2.1.*", "sensio/generator-bundle": "2.1.*", "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*", "kriswallsmith/assetic": "1.1.*@dev", "friendsofsymfony/jsrouting-bundle": "1.0.*", "phpexcel/phpexcel": "dev-master", "genemu/form-bundle": "2.1.*", "whiteoctober/tcpdf-bundle": "dev-master", "avalanche123/imagine-bundle": "dev-master" }, ```
kerem closed this issue 2026-03-04 02:11:41 +03:00
Author
Owner

@raziel057 commented on GitHub (Jan 30, 2013):

I analysed and there is no problem in the BufferHandler and in the SwiftMailerHandler too. The send method of Swift_Mailer is called with a message and the Swift_Transport_Spool is used as transport. As result, the email is flag as sent, so all seems to be good. I need to check the trace on the smtp server to view the difference when using a buffer...

<!-- gh-comment-id:12880498 --> @raziel057 commented on GitHub (Jan 30, 2013): I analysed and there is no problem in the BufferHandler and in the SwiftMailerHandler too. The send method of Swift_Mailer is called with a message and the Swift_Transport_Spool is used as transport. As result, the email is flag as sent, so all seems to be good. I need to check the trace on the smtp server to view the difference when using a buffer...
Author
Owner

@pborreli commented on GitHub (Jan 30, 2013):

I know it won't help you with the actual problem but why don't you want to keep write log to file + sens emails, this is the configuration I use and it works :

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped
        grouped:
            type:    group
            members: [streamed, buffered]
        streamed:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        buffered:
            type:    buffer
            handler: swift
        swift:
            type:       swift_mailer
            from_email: error@example.com
            to_email:   error@example.com
            subject:    An Error Occurred!
            level:      debug
<!-- gh-comment-id:12880648 --> @pborreli commented on GitHub (Jan 30, 2013): I know it won't help you with the actual problem but why don't you want to keep write log to file + sens emails, this is the configuration I use and it works : ``` monolog: handlers: main: type: fingers_crossed action_level: error handler: grouped grouped: type: group members: [streamed, buffered] streamed: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug buffered: type: buffer handler: swift swift: type: swift_mailer from_email: error@example.com to_email: error@example.com subject: An Error Occurred! level: debug ```
Author
Owner

@raziel057 commented on GitHub (Jan 30, 2013):

Yes I tried it too, it's the final configuration I want to use but for the moment I test with the minimal config (with buffer) to find the problem.

<!-- gh-comment-id:12880723 --> @raziel057 commented on GitHub (Jan 30, 2013): Yes I tried it too, it's the final configuration I want to use but for the moment I test with the minimal config (with buffer) to find the problem.
Author
Owner

@raziel057 commented on GitHub (Jan 30, 2013):

I found the problem. It comes from the fact I configured SwiftMailer with a spool type memory. If I remove it the email is sent correctly.

swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    port:      %mailer_port%
    username:  %mailer_user%
    password:  %mailer_password%
#    spool:     { type: memory }

It can be a problem of order in which the process are executed?

<!-- gh-comment-id:12881311 --> @raziel057 commented on GitHub (Jan 30, 2013): I found the problem. It comes from the fact I configured SwiftMailer with a spool type memory. If I remove it the email is sent correctly. ``` swiftmailer: transport: %mailer_transport% host: %mailer_host% port: %mailer_port% username: %mailer_user% password: %mailer_password% # spool: { type: memory } ``` It can be a problem of order in which the process are executed?
Author
Owner

@Seldaek commented on GitHub (Jan 30, 2013):

This is a duplicate of https://github.com/symfony/symfony-standard/issues/425 - the memory spool is currently not flushed at the very end of the request.

<!-- gh-comment-id:12883393 --> @Seldaek commented on GitHub (Jan 30, 2013): This is a duplicate of https://github.com/symfony/symfony-standard/issues/425 - the memory spool is currently not flushed at the very end of the request.
Author
Owner

@raziel057 commented on GitHub (Jan 30, 2013):

Ok thanks for the link to the original ticket!

<!-- gh-comment-id:12883740 --> @raziel057 commented on GitHub (Jan 30, 2013): Ok thanks for the link to the original ticket!
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#50
No description provided.