[GH-ISSUE #48] Monolog swiftmailer handler sends one mail per log entry #12

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

Originally created by @olegstepura on GitHub (Nov 15, 2011).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/48

with this configuration:

    mail:
      type: fingers_crossed
      action_level: error
      handler: mailed
      buffer_size: 100
    mailed:
      type: swift_mailer
      from_email: error_box @ gmail.com
      to_email: error_box @ gmail.com
      subject: Errors logged
      level: debug
      formatter: my_formatter

seems like swiftmailer is used to send one log line per message. That is really a bad idea since

  1. Some mail servers may start blocking send requests sent that often
  2. Some mail servers that receive such a big amount of mail may consider it is spam
  3. It creates bigger traffic and is longer to send 100 mails instead of 1

Swiftmailer handler must have some buffer to send multiple messages per mail.

@see https://groups.google.com/forum/#!topic/symfony-devs/IZ4a_-Oyt2c

Originally created by @olegstepura on GitHub (Nov 15, 2011). Original GitHub issue: https://github.com/Seldaek/monolog/issues/48 with this configuration: ``` mail: type: fingers_crossed action_level: error handler: mailed buffer_size: 100 mailed: type: swift_mailer from_email: error_box @ gmail.com to_email: error_box @ gmail.com subject: Errors logged level: debug formatter: my_formatter ``` seems like swiftmailer is used to send one log line per message. That is really a bad idea since 1. Some mail servers may start blocking send requests sent that often 2. Some mail servers that receive such a big amount of mail may consider it is spam 3. It creates bigger traffic and is longer to send 100 mails instead of 1 Swiftmailer handler must have some buffer to send multiple messages per mail. @see https://groups.google.com/forum/#!topic/symfony-devs/IZ4a_-Oyt2c
kerem closed this issue 2026-03-04 02:11:20 +03:00
Author
Owner

@stof commented on GitHub (Nov 15, 2011):

Simply wrap it in the BufferHandler. It is exactly what it is for.

The reason why it is in a separate handler is that it allows you to buffer other handlers as well without duplicating the logic.

<!-- gh-comment-id:2744805 --> @stof commented on GitHub (Nov 15, 2011): Simply wrap it in the BufferHandler. It is exactly what it is for. The reason why it is in a separate handler is that it allows you to buffer other handlers as well without duplicating the logic.
Author
Owner

@olegstepura commented on GitHub (Nov 15, 2011):

Can you please give an example for symfony configuration?

<!-- gh-comment-id:2744946 --> @olegstepura commented on GitHub (Nov 15, 2011): Can you please give an example for symfony configuration?
Author
Owner

@stof commented on GitHub (Nov 15, 2011):

    mail:
      type: fingers_crossed
      action_level: error
      handler: buffered
    buffered:
      type: buffer
      handler: swift
    swift:
      type: swift_mailer
      from_email: error_box @ gmail.com
      to_email: error_box @ gmail.com
      subject: Errors logged
      level: debug
      formatter: my_formatter

Note that I kept the FingersCrossedHandler wrapping the BufferHandler so that you get a mail only when an error occurs.

<!-- gh-comment-id:2745012 --> @stof commented on GitHub (Nov 15, 2011): ``` yaml mail: type: fingers_crossed action_level: error handler: buffered buffered: type: buffer handler: swift swift: type: swift_mailer from_email: error_box @ gmail.com to_email: error_box @ gmail.com subject: Errors logged level: debug formatter: my_formatter ``` Note that I kept the FingersCrossedHandler wrapping the BufferHandler so that you get a mail only when an error occurs.
Author
Owner

@Seldaek commented on GitHub (Nov 15, 2011):

Right, I guess the mail handler shouldn't be fixed directly, but adding this example to the docs (here and/or as a symfony cookbook) would be nice.

<!-- gh-comment-id:2745151 --> @Seldaek commented on GitHub (Nov 15, 2011): Right, I guess the mail handler shouldn't be fixed directly, but adding this example to the docs (here and/or as a symfony cookbook) would be nice.
Author
Owner

@olegstepura commented on GitHub (Nov 15, 2011):

Cool, thanks, it worked! And yes, that definitely must be described in a cookbook article (maybe in "How to use Monolog to write Logs").

Thanks again!

<!-- gh-comment-id:2745301 --> @olegstepura commented on GitHub (Nov 15, 2011): Cool, thanks, it worked! And yes, that definitely must be described in a cookbook article (maybe in "How to use Monolog to write Logs"). Thanks again!
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#12
No description provided.