laravel 日志

日志
直接写日志 Log::info('user_id:'.$uid,$arr);
按文件写日志
$arr = array('wallet' => $users_wallet, 'fc_currency' => $fc_currency);
  Log::useFiles(storage_path('apiWalletMyMoney.log'));
        Log::info('user_id:'.$uid,$arr);
在ide_helper添加
  public static function useFiles($path, $level = 'debug')
{
    \Illuminate\Log\Writer::useFiles($path, $level);
}

按天写日志
$allInfo = ['url' => $url,];
Log::useDailyFiles(storage_path('logs/appRequest/appRequestLog.log'), 180, 'debug');
Log::info('appRequestLog',$allInfo);

在ide_helper添加
 public static function useDailyFiles($path, $days = 0, $level = 'debug')
{
    \Illuminate\Log\Writer::useDailyFiles($path, $days, $level);
 }

其他

### 写入日志信息

你可以使用 `Log` [门面](http://laravelacademy.org/post/8708.html)记录日志信息,如上所述,日志系统提供了定义在 [RFC 5424 规范](https://tools.ietf.org/html/rfc5424)中的八种日志级别:**emergency**、**alert**、**critical**、**error**、**warning**、 **notice**、**info** 和 **debug**:

Log::emergency($error);
Log::alert($error);
Log::critical($error);
Log::error($error);
Log::warning($error);
Log::notice($error);
Log::info($error);
Log::debug($error);

上下文信息

上下文数据也会以数组形式传递给日志方法,然后和日志信息一起被格式化和显示:

Log::info('User failed to login.', ['id' => $user->id]);
写入指定频道
有时候你可能希望将日志信息记录到某个频道而不是应用的默认频道。要实现这个目的,你可以使用 Log 门面上的 channel 方法来获取配置文件定义的频道并将日志写入进去:

Log::channel('slack')->info('Something happened!');
如果你想要创建一个由多个频道组成的按需日志堆栈,可以使用 stack 方法:

Log::stack(['single', 'slack'])->info('Something happened!');
发布了264 篇原创文章 · 获赞 46 · 访问量 37万+

猜你喜欢

转载自blog.csdn.net/qq_27229113/article/details/103022554