Created
April 1, 2017 04:21
-
-
Save vlakoff/35f52e99f9ce887c80c0df1fa01f2914 to your computer and use it in GitHub Desktop.
Custom logging in Laravel: one dir per month, one file per day
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 | |
// logs in one dir per month, one file per day | |
// storage/logs/YYYY-MM/YYYY-MM-DD.log | |
// paste in bootstrap/app.php, after $app assignation | |
// reference: https://laravel.com/docs/5.4/errors#custom-monolog-configuration | |
$app->configureMonologUsing(function () { | |
$dir = storage_path('logs/'.date('Y-m')); | |
is_dir($dir) || mkdir($dir, 0777, true); // if possible, use stricter permissions e.g. 0755 | |
$file = $dir.'/'.date('Y-m-d').'.log'; | |
$level = config('app.log_level', 'debug'); | |
logger()->useFiles($file, $level); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment