Symfony2.1によるmonologの設定
あるアプリケーションをSymfony2.0系からSymfony2.1に移行していた時にmonologの設定で少しはまったので備忘録を。
Symfony2.0系では下記のようなmonologの設定をしていて、正常にdebug以上はログに記述し、error以上のログはメールで受け取れていた。
monolog: handlers: main: type: fingers_crossed action_level: debug handler: grouped # streamed, bufferedに渡す grouped: type: group members: [streamed, buffered] # debug以上をログファイルに書き込み streamed: type: stream path: %kernel.logs_dir%/%kernel.environment%.log level: debug # error以上をメールする buffered: type: buffer handler: swift swift: type: swift_mailer from_email: %system_mail_from% to_email: %log_mail_to% subject: "エラーだよ!" level: error
上記の設定のまま、Symfony2.1に移行するとメールが一切受け取れなくなった。
ソースを追ってみると、SwiftMailer自体にはログ情報は渡っているが、最終的に下記のソースの部分まで処理が行き送信自体されていない。
vendor/swiftmailer/swiftmailer/lib/classes/Swift/Plugins/MessageLogger.php
<?php ~ /** * Invoked immediately after the Message is sent. * * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { }
しょうがないので、色々ネットで調べてみると下記の記事を見つけた。
In fact, the problem is a known issue and is present when using a buffered swift_mailer Monolog handler with a memory spool.
http://forum.symfony-project.org/viewtopic.php?t=47160&p=167193
As a workaround, to avoid any problems, comment the "spool: { type: memory }" in config.yml
See the following threads:
https://github.com/Seldaek/monolog/issues/154
https://github.com/symfony/symfony-standard/issues/425
結局、ここに書いてあるconfig.ymlのswiftmailerの設定でspool: { type: memory }をコメントアウトしたらちゃんと動いたのでよかった!