duan198727 2013-06-06 21:21
浏览 34
已采纳

Symfony2 - Monolog - 升级或降低自定义记录器

Using Symfon2 and its Monolog framework to for logging, I am having some trouble.

On the one hand, I have a service configured with my own logger. It is working properly and I get to "info" and "err" messages without problems.

services:
  my_logger:
    class: Monolog\Logger
    arguments: [my_info]
    calls:
        - [pushHandler, [@my_log_handler]]

  my_log_handler:
    class: Monolog\Handler\StreamHandler
    arguments: [%kernel.root_dir%/logs/my_info.log, 100]

Using the following in the controller causes proper messages to be written $this->get('my_logger')->info('info message'); $this->get('my_logger')->err('error message');

Here comes my question

Once I have placed planty of those ->err and ->info logging messages, how I tell the configuration to just write those written through the err method?

At the beginning may be I need many information, and for that reason I would write many info messages. But in a while, I may prefer to level up the logging messages through setting the action level to warning or error, avoiding the info logs to be written.

Any idea?

  • 写回答

1条回答 默认 最新

  • douji1999 2013-06-06 23:16
    关注

    You just need to tweak the level at which your handler is listening. In this case it means changing the 100 to something higher like 400 for errors. So that gives you:

      my_log_handler:
        class: Monolog\Handler\StreamHandler
        arguments: [%kernel.root_dir%/logs/my_info.log, 400]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀