private function checkLog($expect, $format, $data) { $tmp = new TempFile(); $log = new PhutilDeferredLog($tmp, $format); $log->setData($data); unset($log); $this->assertEqual($expect, Filesystem::readFile($tmp), $format); }
public static function getLog() { if (!self::$log) { $path = PhabricatorEnv::getEnvConfig('log.access.path'); $format = PhabricatorEnv::getEnvConfig('log.access.format'); $format = nonempty($format, "[%D]\t%p\t%h\t%r\t%u\t%C\t%m\t%U\t%R\t%c\t%T"); if (!$path) { return null; } $log = new PhutilDeferredLog($path, $format); $log->setData(array('D' => date('r'), 'h' => php_uname('n'), 'p' => getmypid(), 'e' => time())); self::$log = $log; } return self::$log; }
public static function saveProfilerSample(PhutilDeferredLog $access_log) { $file_phid = self::getProfileFilePHID(); if (!$file_phid) { return; } if (self::isProfilerRequested()) { $sample_rate = 0; } else { $sample_rate = PhabricatorEnv::getEnvConfig('debug.profile-rate'); } $profile_sample = id(new PhabricatorXHProfSample())->setFilePHID($file_phid)->setSampleRate($sample_rate)->setUsTotal($access_log->getData('T'))->setHostname($access_log->getData('h'))->setRequestPath($access_log->getData('U'))->setController($access_log->getData('C'))->setUserPHID($access_log->getData('P')); AphrontWriteGuard::allowDangerousUnguardedWrites(true); $caught = null; try { $profile_sample->save(); } catch (Exception $ex) { $caught = $ex; } AphrontWriteGuard::allowDangerousUnguardedWrites(false); if ($caught) { throw $caught; } }
public function processRequest(AphrontRequest $request, PhutilDeferredLog $access_log, AphrontHTTPSink $sink, MultimeterControl $multimeter) { $this->setRequest($request); list($controller, $uri_data) = $this->buildController(); $controller_class = get_class($controller); $access_log->setData(array('C' => $controller_class)); $multimeter->setEventContext('web.' . $controller_class); $request->setURIMap($uri_data); $controller->setRequest($request); // If execution throws an exception and then trying to render that // exception throws another exception, we want to show the original // exception, as it is likely the root cause of the rendering exception. $original_exception = null; try { $response = $controller->willBeginExecution(); if ($request->getUser() && $request->getUser()->getPHID()) { $access_log->setData(array('u' => $request->getUser()->getUserName(), 'P' => $request->getUser()->getPHID())); $multimeter->setEventViewer('user.' . $request->getUser()->getPHID()); } if (!$response) { $controller->willProcessRequest($uri_data); $response = $controller->handleRequest($request); } } catch (Exception $ex) { $original_exception = $ex; $response = $this->handleException($ex); } try { $response = $controller->didProcessRequest($response); $response = $this->willSendResponse($response, $controller); $response->setRequest($request); $unexpected_output = PhabricatorStartup::endOutputCapture(); if ($unexpected_output) { $unexpected_output = pht("Unexpected output:\n\n%s", $unexpected_output); phlog($unexpected_output); if ($response instanceof AphrontWebpageResponse) { echo phutil_tag('div', array('style' => 'background: #eeddff;' . 'white-space: pre-wrap;' . 'z-index: 200000;' . 'position: relative;' . 'padding: 8px;' . 'font-family: monospace'), $unexpected_output); } } $sink->writeResponse($response); } catch (Exception $ex) { if ($original_exception) { throw $original_exception; } throw $ex; } return $response; }
public function processRequest(AphrontRequest $request, PhutilDeferredLog $access_log, AphrontHTTPSink $sink, MultimeterControl $multimeter) { $this->setRequest($request); list($controller, $uri_data) = $this->buildController(); $controller_class = get_class($controller); $access_log->setData(array('C' => $controller_class)); $multimeter->setEventContext('web.' . $controller_class); $request->setController($controller); $request->setURIMap($uri_data); $controller->setRequest($request); // If execution throws an exception and then trying to render that // exception throws another exception, we want to show the original // exception, as it is likely the root cause of the rendering exception. $original_exception = null; try { $response = $controller->willBeginExecution(); if ($request->getUser() && $request->getUser()->getPHID()) { $access_log->setData(array('u' => $request->getUser()->getUserName(), 'P' => $request->getUser()->getPHID())); $multimeter->setEventViewer('user.' . $request->getUser()->getPHID()); } if (!$response) { $controller->willProcessRequest($uri_data); $response = $controller->handleRequest($request); $this->validateControllerResponse($controller, $response); } } catch (Exception $ex) { $original_exception = $ex; $response = $this->handleException($ex); } try { $response = $this->produceResponse($request, $response); $response = $controller->willSendResponse($response); $response->setRequest($request); self::writeResponse($sink, $response); } catch (Exception $ex) { if ($original_exception) { throw $original_exception; } throw $ex; } return $response; }