示例#1
0
 protected function logRequest($requestInfo)
 {
     // Get profiling info.
     $profiling = $requestInfo['profiling'];
     $receiveTime = $processTime = $sendTime = 0;
     if (isset($profiling['receive.start']) and isset($profiling['receive.end'])) {
         $receiveTime = ($profiling['receive.end'] - $profiling['receive.start']) * 1000.0;
     }
     if (isset($profiling['process.start']) and isset($profiling['process.end'])) {
         $processTime = ($profiling['process.end'] - $profiling['process.start']) * 1000.0;
     }
     if (isset($profiling['send.start']) and isset($profiling['send.end'])) {
         $sendTime = ($profiling['send.end'] - $profiling['send.start']) * 1000.0;
     }
     $totalTime = ceil($receiveTime + $processTime + $sendTime);
     // Do the logging.
     $request = $requestInfo['request'];
     $response = $requestInfo['response'];
     if ($request and $response) {
         $clientInfo = $this->handler->getClientInfo($requestInfo['socket']);
         $statusName = StupidHttp_WebServer::getHttpStatusHeader($response->getStatus());
         $replacements = array('%date%' => date(self::REQUEST_DATE_FORMAT), '%client_ip%' => $clientInfo['address'], '%client_port%' => $clientInfo['port'], '%method%' => $request->getMethod(), '%uri%' => $request->getUri(), '%path%' => $request->getUriPath(), '%status%' => $response->getStatus(), '%status_name%' => $statusName, '%time%' => $totalTime);
         $this->log->info(str_replace(array_keys($replacements), array_values($replacements), self::REQUEST_LOG_FORMAT));
     }
 }
示例#2
0
 /**
  * Creates a new instance of StupidHttp_PearLog wrapped around the given PEAR logger.
  */
 public function __construct(Log $log)
 {
     parent::__construct();
     $this->log = $log;
     $this->isBuffering = false;
     $this->bufferedMessages = array();
 }
示例#3
0
 /**
  * Implementation of the StupidHttp_Log::log() function.
  */
 public function log($message, $type = StupidHttp_Log::TYPE_INFO)
 {
     if ($type <= $this->level) {
         $prefix = '';
         if ($this->prefixAllMessages or $type != StupidHttp_Log::TYPE_INFO) {
             $prefix = '[' . StupidHttp_Log::messageTypeToString($type) . '] ';
         }
         $formattedMessage = $prefix . $message . PHP_EOL;
         if ($this->isBuffering) {
             $this->buffer .= $formattedMessage;
         } else {
             echo $formattedMessage;
         }
     }
 }
示例#4
0
 /**
  * Creates a new instance of StupidHttp_MultiLog.
  */
 public function __construct(array $logs)
 {
     parent::__construct();
     $this->logs = $logs;
 }