2016-12-13 104 views
5

我使用Cascade「編Monolog和使用YAML配置記錄器。這是我的配置的一部分:毫秒獨白格式化 LineFormatter(PHP)

formatters: 
    dashed: 
     class: Monolog\Formatter\LineFormatter 
     format: "%datetime%-%channel%.%level_name% - %message%\n" 

這是一個格式化的日誌行:

2016-12-13 17:49:16-app.INFO - <message> 

什麼是\Monolog\Formatter\LineFormatter正確format值以得到時間戳和毫秒?

回答

0

在我的Symfony 2.6項目我有一個自定義日誌處理器,所以我已經實現了日誌的服務,如果它能夠幫助這裏的一塊service.yml聲明的代碼;如果你看一下logger_formatter,類構造器的第二個參數是日期格式:

mybundle.logger: 
     class:  Symfony\Bridge\Monolog\Logger 
     arguments: [mybundle] # channel 
     calls: 
      - [pushHandler, [@mybundle.logger_handler]] 
      - [pushProcessor, [@mybundle.logger_processor]] 

mybundle.logger_processor: 
     class:  myBundle\Logging\LogProcessor 
     arguments: ["@session"] 

mybundle.logger_handler: 
     class:  myBundle\Logging\myBundleRotatingFileHandler #Monolog\Handler\RotatingFileHandler 
     arguments: ["@session", %kernel.logs_dir%/LOGGER_SID/%kernel.environment%.mybundle.log, 0, 400] #DEBUG = 100; INFO = 200; NOTICE = 250; WARNING = 300; ERROR = 400; CRITICAL = 500; ALERT = 550; EMERGENCY = 600; 
     calls: 
      - [setFormatter, [@mybundle.logger_formatter]] 
      - [setFilenameFormat, ['{filename}','Y-m-d']] 

mybundle.logger_formatter: 
     class: Monolog\Formatter\LineFormatter 
     arguments: 
      - "[%%datetime%%]\t%%extra.remote_addr%%\t%%level_name%%\t%%message%%\t%%extra.request_uri%%\n" 
      - "Y-m-d H:i:s.u"