pushHandler(new StreamHandler($logFilePath), $level); $logger->pushProcessor(new WebProcessor()); switch($level) { case Logger::INFO: $logger->info($content, $extra); break; case Logger::ERROR: $logger->error($content, $extra); break; case Logger::DEBUG: $logger->debug($content, $extra); break; default: $logger->warning('日志类型传递有误,暂时存在三种类型:', ['info', 'error', 'debug']); } } catch (\Exception $e) { $exceptionLogPath = storage_path('logs/exception.log'); file_put_contents($exceptionLogPath, date('Y-m-d H:i:s') . " " . $e->getMessage() . "[". json_encode($extra, JSON_UNESCAPED_UNICODE) ."【".$name."】]". "\r\n", FILE_APPEND); } } /** * 信息日志 * @param $title * @param $content * @param string $file */ public static function info($content, $extra = [], $prefix = 'info') { self::_save($prefix, $content, $extra, Logger::INFO); } /** * 错误日志 * @param $title * @param $content * @param string $file */ public static function error($content, $extra = [], $prefix = 'error') { self::_save($prefix, $content, $extra, Logger::ERROR); if ($prefix != 'exception') { SysLogRecord::query()->insert([ 'level' => 'ERROR', 'content' => $content, 'file' => $prefix ]); } } /** * 调试日志 * @param $content * @param array $extra * @param string $prefix */ public static function debug($content, $extra = [], $prefix = 'debug') { self::_save($prefix, $content, $extra, Logger::DEBUG); } }