Laravel 5 日志中的最大文件数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29348326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:15:31  来源:igfitidea点击:

Max files in Laravel 5 logs

phplaravellaravel-5

提问by rap-2-h

How can I define the maximum number of log files in Laravel 5. I use daily log rotate, and I have "only" 5 log files in storage, I want to have the past 30 days, but I don't know how to do this, and I did not found any clue.

如何在 Laravel 5 中定义最大日志文件数。我使用每日日志轮换,并且我“只有”5 个日志文件在存储中,我想要过去 30 天,但我不知道该怎么做这个,我没有发现任何线索。

回答by rap-2-h

Ok, it's now possible since v5.0.23. You just need to update laravel, and add this in your config/app.phpfile:

好的,现在可以从 v5.0.23 开始。你只需要更新 Laravel,并将其添加到你的config/app.php文件中:

'log_max_files' => 30

On Laravel 5.6You can find config/logging.phpfile:

在 Laravel 5.6 上你可以找到config/logging.php文件:

    'daily' => [
        'driver' => 'daily',
        'path' => storage_path('logs/laravel.log'),
        'level' => 'debug',
        'days' => 30, // 0 for unilimitted logs
    ],

回答by GustavoLima

On Laravel 5.6 open file config/logging.phpon array daily change: 'days' => 30

在 Laravel 5.6 上打开config/logging.php数组每日更改的文件:'days' => 30

If you want unlimited logs just put 0 instead 30.

如果您想要无限的日志,只需输入 0 而不是 30。

回答by Cunning

There is a function in ConfigureLoggingor LogServiceProvideror so (Since I'm using an old checkout I'm not sure where exactly), something called useDailyFiles. In that the file name and maximum file number is set and the default looks something like this:

有一个函数ConfigureLoggingLogServiceProvider称为左右(由于我使用的是旧结帐我不知道到底在哪),东西useDailyFiles。其中文件名和最大文件数已设置,默认值如下所示:

$log->useDailyFiles(storage_path().'/logs/laravel.log', 5);

$log->useDailyFiles(storage_path().'/logs/laravel.log', 5);

Change the last parameter (5) to your desired number of files.

将最后一个参数 (5) 更改为所需的文件数。