Lumen
中默认的文件名是被硬编码在 Application
类中了的,要实现这样的效果,必须重写 Laravel\Lumen\Application@getMonologHandler()
方法。
1 2 3
| $app = new Laravel\Lumen\Application( realpath(__DIR__.'/../') );
|
1 2 3
| $app = new App\Application( realpath(__DIR__.'/../') );
|
- 新增文件:
app/Application.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <?php
namespace App;
use Laravel\Lumen\Application as LumenBase; use Monolog\Formatter\LineFormatter; use Monolog\Handler\StreamHandler; use Monolog\Logger;
class Application extends LumenBase { protected function getMonologHandler() { return ( new StreamHandler(storage_path(env( 'APP_LOG_PATH', 'logs/'.date('Y-m-d').'.log' )), Logger::DEBUG )) ->setFormatter(new LineFormatter(null, null, true, true)); } }
|
在/storage/logs/
即可看到以类似 2018-08-07.log
命名的日志文件