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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?