简体   繁体   中英

Laravel Monolog LineFormatter datetime pattern

I am trying to create custom log in laravel and i am using monlog\LineFormatter class to formatt my final log

'events' => [
            'driver' => 'daily',
            'formatter' =>LineFormatter::class,
            'formatter_with' => [
                'format' => "[%datetime%] %channel%.%level_name%: %context%\n",
            ],
            'path' => storage_path('logs/events.log'),
            'level' => 'info'
        ] 

No i am getting logs in my log file as below

[2022-01-27T08:30:33.627980+00:00] local.INFO: {"request-id":"5f9c3819-97b3-4439-87ab-30c58bffd2a5","event_name":"cancel_pending_withdraw","message":"action webhook sent"}

I want date time format to be like

[2022-01-27T08:30:33.627980+00:00]  ==> [2022-01-27 08:30:33]

How i can change this formatter through monolog Lineformatter.

So I got the solution for this the simplest way to do this is as follow

'events' => [
            'driver' => 'daily',
            'formatter' =>LineFormatter::class,
            'formatter_with' => [
                'format' => "[%datetime%] %channel%.%level_name%: %context%\n",
                'dateFormat' => "Y-m-d H:i:s"
            ],
            'path' => storage_path('logs/unique-events.log'),
            'level' => 'info'
        ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM