您是否有使用Symfony 5.1的Mailer组件通过电子邮件发送日志的示例配置。
在Symfony博客中,我们宣布了这一特性,但我无法在monolog.yaml中设置正确的配置
https://symfony.com/blog/new-in-symfony-5-1-misc-improvements-part-3:这就是为什么在Symfony 5.1中,我们添加了一个新的单一日志处理程序,它使用邮件组件通过电子邮件发送日志。
发布于 2020-06-24 21:23:03
不幸的是,这一添加只涵盖了monolog-bridge中的actuall MailerHandler类。这不包括在monolog-bundle中配置它的可能性(如果这些组件分布在多个包中,这就是缺点)。
在monolog-bundle中的PR仍然是开放的,可以在这里找到:Add Symfony Mailer support #354。
如果您不想等待monolog包中的更改,您可以通过将处理程序定义为服务,然后在monolog配置中将其与service类型一起使用来使用它。
所以定义你的服务:
services:
# this configures the "mail" as a prototype, so you can
# define the sender and recipient mail addresses here
symfony_mailer_service_template:
class: Symfony\Component\Mime\Email
calls:
- ['from', ['webapp@example.com']]
- ['to', ['ops@example.com']]
- ['subject', ['Logs']]
symfony_mailer_service:
class: Symfony\Bridge\Monolog\Handler\MailerHandler
arguments:
- '@mailer.mailer'
- '@symfony_mailer_service_template'
- !php/const Monolog\Logger::DEBUG # log level
- true # bubble然后在你的邮件配置中,你可以这样使用它:
monolog:
handlers:
main:
type: fingers_crossed
handler: deduplicated
deduplicated:
type: deduplication
handler: symfony_mailer
symfony_mailer:
type: service
id: symfony_mailer_servicehttps://stackoverflow.com/questions/62554976
复制相似问题