Skip to content

Instantly share code, notes, and snippets.

@vlakoff
Created April 1, 2017 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlakoff/35f52e99f9ce887c80c0df1fa01f2914 to your computer and use it in GitHub Desktop.
Save vlakoff/35f52e99f9ce887c80c0df1fa01f2914 to your computer and use it in GitHub Desktop.
Custom logging in Laravel: one dir per month, one file per day
<?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