Symfony 2:登录到特定文件 [英] Symfony 2 : Log into a specific file

查看:84
本文介绍了Symfony 2:登录到特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发布问题之前,我进行了很多搜索.我没有找到明确的答案,所以就在这里.

I searched a lot before posting my question. I didn't find a clear answer, so here it is.

我想将消息记录在与dev.log或prod.log不同的日志文件中.我的意思是一个不会被Symfony核心消息污染的文件.我听说过Monolog中的记录器和处理程序,但这还不是很清楚.

I want to log messages in a different log file as dev.log or prod.log. I mean a file which won't be poluted by Symfony core messages. I heard about logger and handler in monolog, but it's not very clear.

如何记录控制器中的消息,模型到特定的日志文件?

How can I log messages from my controllers, model to a specific log file ?

推荐答案

您必须将信息添加到services.yml文件,而不是config.yml文件:

You have to add the info to the services.yml file, not the config.yml file:

因此在services.yml(services.xml )中,您拥有

So in services.yml (or services.xml) you have

my_service.logger:
    class:     Symfony\Bridge\Monolog\Logger
    arguments: [app]
    calls:
        - [pushHandler, [@my_service.logger_handler]]

my_service.logger_handler:
    class:     Monolog\Handler\StreamHandler       
    arguments: [%kernel.logs_dir%/%kernel.environment%.admin.log, 200]

并在控制器操作中使用:

and in your controller action you use:

$logger = $this->get('my_service.logger');

这篇关于Symfony 2:登录到特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆