Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Milliseconds in \Monolog\Formatter\LineFormatter (PHP)

I use Cascade'ed Monolog and configure loggers using YAML. This is a part of my config:

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

This is a formatted log line:

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

What is the right format value for \Monolog\Formatter\LineFormatter to get timestamp with milliseconds?

like image 563
Alex Gusev Avatar asked Nov 09 '22 04:11

Alex Gusev


1 Answers

In my Symfony 2.6 project I've a custom log processor so I've implemented the log as service, if it can help here is the piece of code of the service.yml declaration; if you look at logger_formatter, the second argument of the class contructor is the date format:

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"
like image 106
Davide BlackGear Avatar answered Nov 15 '22 11:11

Davide BlackGear