且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel:如何记录信息到单独的文件

更新时间:2023-02-17 12:11:50

是否要专门将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.