好的,我终于可以解决它了。相当多的扩展是必要的,但我不需要编辑任何供应商文件,这很好。所以,就这样吧:
新文件app/Bootstrap/ConfigureLogging.php:
命名空间应用\引导程序;
使用 Illuminate\Contracts\Foundation\Application;
使用 App\Support\Log\Writer;
使用 Monolog\Logger 作为 Monolog;
类 ConfigureLogging 扩展 \Illuminate\Foundation\Bootstrap\ConfigureLogging {
受保护的函数 configureDailyWithChmodHandler(Application $app, Writer $log)
{
$log->useDailyFilesWithChmod(
$app->storagePath().'/logs/laravel.log',
$app->make('config')->get('app.log_max_files', 5)
);
}
受保护的函数 registerLogger(Application $app)
{
$app->instance('log', $log = new Writer(
新独白($app->environment()), $app['events'])
);
返回$日志;
}
}
在app/Console/Kernel.php我已经添加到顶部:
使用 Illuminate\Contracts\Events\Dispatcher;
使用 Illuminate\Contracts\Foundation\Application;
然后我添加了这个构造函数:
公共函数 __construct(Application $app, Dispatcher $events)
{
$idx = array_search('Illuminate\Foundation\Bootstrap\ConfigureLogging', $this->bootstrappers);
如果($idx){
array_splice($this->bootstrappers, $idx, 1, 'App\Bootstrap\ConfigureLogging');
}
父::__construct($app, $events);
}
必须在app/Http/Kernel.php 中进行类似的更改:
使用照明\路由\路由器;
使用 Illuminate\Contracts\Foundation\Application;
...
公共函数__construct(应用程序$app,路由器$router)
{
$idx = array_search('Illuminate\Foundation\Bootstrap\ConfigureLogging', $this->bootstrappers);
如果($idx){
array_splice($this->bootstrappers, $idx, 1, 'App\Bootstrap\ConfigureLogging');
}
父::__construct($app, $router);
}
然后app/Support/Handler/RotatingFileHandler.php:
命名空间应用\支持\处理程序;
类 RotatingFileHandler 扩展 \Monolog\Handler\RotatingFileHandler{
受保护的函数写入(数组 $record)
{
父::写($记录);
if ($this->mustRotate) {
chmod($this->url, 0666);
}
}
}
还有app/Support/Log/Writer.php:
命名空间应用\支持\日志;
使用 App\Support\Handler\RotatingFileHandler;
类 Writer 扩展 \Illuminate\Log\Writer{
公共函数 useDailyFilesWithChmod($path, $days = 0, $level = 'debug')
{
$this->monolog->pushHandler(
$handler = new RotatingFileHandler($path, $days, $this->parseLevel($level))
);
$handler->setFormatter($this->getDefaultFormatter());
}
}
最后替换config/app.php中的“log”选项:
'日志' => 'dailyWithChmod'
您可能需要运行 composer dump-autoload 才能找到新类。
如果你有任何问题并且 Laravel 没有显示任何错误,将 ini_set('display_errors', 'on'); 添加到你的内核应该会有所帮助。