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?
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With