我使用Cascade'ed Monolog并使用YAML配置记录器。这是我配置的一部分:
formatters:
dashed:
class: Monolog\Formatter\LineFormatter
format: "%datetime%-%channel%.%level_name% - %message%\n"
这是一个格式化的日志行:
2016-12-13 17:49:16-app.INFO - <message>
format
获取时间戳的正确\Monolog\Formatter\LineFormatter
值是多少?
答案 0 :(得分: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"