Beispiel #1
0
 /**
  * 记录起始请求日志
  * 记录成功返回true,失败或没记录日志返回false
  *
  * @return  bool
  */
 public static function request_start_log()
 {
     if (!BaseLog::isLog('debug')) {
         return false;
     }
     if (!Config::getEnv("app.request_start_log")) {
         return false;
     }
     $data = Request::nonPostParam();
     if (Config::getEnv("app.request_log_post")) {
         $data = Request::param();
     }
     $file_path = BaseLog::handle_log_file('framework', 'debug');
     $log_time = date("Y-m-d H:i:s", QP_RUN_START);
     $ip = Request::getIp();
     $router_url = \Qp\Kernel\Http\Router\QpRouter::getRouterStr();
     $prefix = "[{$log_time}] [{$ip}] [router : {$router_url}] ";
     $msg = "【请求日志】" . json_encode(['data' => $data]);
     $logger = new FileAdapter($file_path);
     $logger->setFormatter(new LineFormatter("%message%"));
     return (bool) $logger->log($prefix . $msg);
 }
Beispiel #2
0
 /**
  * 底层日志记录方法
  * 记录成功返回true,失败或没记录日志返回false
  *
  * @param   string  $log_level  日志等级
  * @param   string  $msg        日志消息(占位符使用{键名})
  * @param   array   $data       数据(支持key-value形式的数组,用来替换$msg中的占位字符)
  * @param   bool    $is_replace 是否替换占位字符
  * @param   string  $modular    应用模块名
  * @return  bool
  */
 protected static function log($log_level, $msg = '', $data = [], $is_replace = false, $modular = 'unknown_module')
 {
     if (!in_array($log_level, self::$log_level_allow)) {
         throw new \InvalidArgumentException("不支持的日志等级:" . $log_level);
     }
     if (!self::isLog($log_level)) {
         return false;
     }
     $file_path = self::handle_log_file($modular, $log_level);
     $log_time = date('Y-m-d H:i:s');
     $ip = \Qp\Kernel\Request::getIp();
     $router_url = \Qp\Kernel\Http\Router\QpRouter::getRouterStr();
     $prefix = "[{$log_time}] [{$ip}] [router : {$router_url}] ";
     if ($is_replace) {
         $msg = self::interpolate($msg, $data);
     } else {
         $msg = $msg . json_encode(['data' => $data]);
     }
     $logger = new FileAdapter($file_path);
     $logger->setFormatter(new LineFormatter("%message%"));
     return (bool) $logger->log($prefix . $msg);
 }