在我的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"