laravel 5.2 custom log file for different tasks

后端 未结 10 1032
再見小時候
再見小時候 2021-01-30 00:36

Can we create a custom log file for different purposes in laravel 5.2 like for order related log entries that should be in order.log and for payment related stuff the entry shou

10条回答
  •  不知归路
    2021-01-30 00:47

    There is a simple way:

    use Monolog\Logger;
    use Monolog\Handler\StreamHandler;
    
    $log = ['orderId' => 10,
            'description' => 'Some description'];
    
    //first parameter passed to Monolog\Logger sets the logging channel name
    $orderLog = new Logger('order');
    $orderLog->pushHandler(new StreamHandler(storage_path('logs/order.log')), Logger::INFO);
    $orderLog->info('OrderLog', $log);
    

    Output in logs/order.log:

    [2017-04-30 00:00:00] order.INFO: OrderLog {"orderId":10, "description":"Some description"} []
    

提交回复
热议问题