配置配置文件config/logging.phpLaravel默认使用stack通道记录日志信息,stack通道用于将多个日志通道聚合成一个通道。示例:单频道默认写入larave.log文件,每日频道默认写入larave-*.log文件。如果栈配置如下'stack'=>['driver'=>'stack','channels'=>['single','daily']],日志会写入到larave.log和larave-*.log文件同时。日志级别LOG_LEVEL=debug通道记录日志信息必须达到的最低“级别”emergency,alert,critical,error,warning,notice,infoanddebug假设LOG_LEVEL=error,那么Log::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('Userfailedtologin.',['id'=>123]);//local.INFO:Userfailedtologin.{"id":123}写入指定通道'test'=>['driver'=>'single','path'=>storage_path('logs/laravel.log'),],Log::channel('test')->info('出事了!');通道自定义'single'=>['driver'=>'single','tap'=>[App\Logging\CustomizeFormatter::class],'path'=>storage_path('logs/laravel.log'),'level'=>'debug',],注意:所有“tap”类都通过服务器服务容器解析,因此它们需要的所有构造函数依赖项都会自动注入getHandlers()as$handler){$handler->setFormatter(newLineFormatter('[%datetime%]%channel%.%level_name%:%message%%context%%extra%'));}}}
