Created
May 18, 2015 05:07
-
-
Save adinauer/616438ebe1981e922492 to your computer and use it in GitHub Desktop.
Laravel JSON Logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this to bootstrap/app.php to override the default logging configuration | |
$app->singleton( | |
'Illuminate\Foundation\Bootstrap\ConfigureLogging', | |
'App\Bootstrap\ConfigureLogging' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Bootstrap; | |
// app/Bootstrap/ConfigureLogging.php | |
use Illuminate\Log\Writer; | |
use Illuminate\Contracts\Foundation\Application; | |
use Illuminate\Foundation\Bootstrap\ConfigureLogging as BaseLoggingConfiguration; | |
use Monolog\Formatter\JsonFormatter; | |
use Monolog\Handler\RotatingFileHandler; | |
class ConfigureLogging extends BaseLoggingConfiguration { | |
/** | |
* Configure the Monolog handlers for the application. | |
* | |
* @param \Illuminate\Contracts\Foundation\Application $app | |
* @param \Illuminate\Log\Writer $log | |
* @return void | |
*/ | |
protected function configureSingleHandler(Application $app, Writer $log) | |
{ | |
//sets the path to custom app/log/single-xxxx-xx-xx.log file. | |
$log->useFiles(base_path() . '/log/single.log'); | |
} | |
/** | |
* Configure the Monolog handlers for the application. | |
* | |
* @param \Illuminate\Contracts\Foundation\Application $app | |
* @param \Illuminate\Log\Writer $log | |
* @return void | |
*/ | |
protected function configureDailyHandler(Application $app, Writer $log) | |
{ | |
//sets the path to custom app/log/daily-xxxx-xx-xx.log file. | |
$log->useDailyFiles(base_path() . '/logs/daily.log', 5); | |
$formatter = new JsonFormatter(); | |
$handler = new RotatingFileHandler(base_path() . '/logs/daily.json', 5); | |
$handler->setFormatter($formatter); | |
$log->getMonolog()->pushHandler($handler); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment