Laravel:如何记录信息以分隔文件

2021-12-18 00:00:00 php laravel laravel-5 laravel-5.1 monolog

如何在Laravel 5.1中为logging INFO指定一个单独的文件?

How to specify a separate file for logging INFO in Laravel 5.1?

任何立即的帮助都将是非常可观的.谢谢

Any immediate help will be highly appreciable. Thanks

推荐答案

是否要将 info 专门记录到一个日志文件并将另一种日志类型记录到另一个位置?在这种情况下,我的解决方案可能无济于事,但仍然有用.

Do you want to specifically log info to one log file and another log type to another location? My solution might not help in that case, but could still be useful.

要将日志文件写入另一个位置,请使用方法 useDailyFilesuseFiles,然后使用 info 方法将日志文件记录到您刚刚指定的路径中.像这样:

To write a log file to another location, use the method useDailyFiles or useFiles, and then info to log to the log file at the path you just specified. Like so:

    Log::useDailyFiles(storage_path().'/logs/name-of-log.log');
    Log::info([info to log]);

这两种方法的第一个参数是日志文件的路径(如果它不存在则创建),对于 useDailyFiles 第二个参数是 Laravel 将记录的天数在擦除旧日志之前.默认值是无限制的,所以在我的例子中我没有输入值.

The first parameter for both methods is the path of the log file (which is created if it doesn't already exist) and for useDailyFiles the second argument is the number of days Laravel will log for before erasing old logs. The default value is unlimited, so in my example I haven't entered a value.

相关文章