Friday, February 8, 2019

Using custom monolog handlers in Laravel

You can easily add new handlers to Monolog


$manage_monolog = function(\Monolog\Logger $monolog) {
    #New monolog file name
    $filename = storage_path('logs'.DIRECTORY_SEPARATOR.'custom.log');
    $handler = new \Monolog\Handler\RotatingFileHandler($filename);

    #If you only keep this handler only
    $monolog->setHandlers(array($handler));

    #If you need to add this custom handler to existing handlers
    $monolog->pushHandler($handler);

    print_r($monolog->getHandlers());
};
$manage_monolog(\Illuminate\Support\Facades\Log::getMonolog());
\Illuminate\Support\Facades\Log::info("Its completed...");



No comments:

Post a Comment