SwiftMailer Logger - Does it work?

Hi,

There is a Logger class included with SwiftMailer. Has anyone been able to get it to work?

per the comments in the yii\swiftmailer\Logger class, I’ve added this to my application’s components section in the config:




    'log' => [

        'targets' => [

            [

                'class' => 'yii\log\FileTarget',

                'categories' => ['yii\swiftmailer\Logger::add'],

                'logFile' => '@app/runtime/logs/email.log',

            ],

        ],

    ],



but, when I send a message:


Yii::$app->mailer->compose()

            ->setTo('some_email@address.com')

            ->setSubject($this->subject)

            ->setTextBody($this->body)

            ->send();



The message is sent, but I expect to see a log entry in email.log for this message, but I see nothing - (the email.log log file’s not even created).

If I understand it correctly, the Logger.php class is supposed to output all the Yii::info calls in the Yii Swiftmailer functions. But it’s not doing that.

Has anyone gotten this to work?

-Charlie

Ah - OK, I figured it out.

You need to add:


'enableSwiftMailerLogging' => true,

to your mailer config:


    'components' => [

        'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',

            'enableSwiftMailerLogging' => true,

            'viewPath' => '@app/mail',

            'useFileTransport' => false,

            'transport' => [

                // your transport here

             ],

        ],

    ],