1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-13 10:22:42 +01:00
phorge-phorge/src/infrastructure/PhabricatorAccessLog.php
epriestley cde1416446 Guarantee the existence of the Phabricator access log
Summary:
We have a fair number of conditionals on the existence of the access log. Instead, always build it and just don't write it if the user doesn't want a version on disk.

Also, formalize logged-in user PHID (avoids object existence juggling) in the access log and move microseconds-since-startup to PhabricatorStartup (simplifies index.php).

Depends on D5532. Fixes T2860. Ref T2870.

Test Plan: Disabled access log, verified XHProf writes occurred correctly.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2860, T2870

Differential Revision: https://secure.phabricator.com/D5533
2013-04-02 09:53:56 -07:00

41 lines
991 B
PHP

<?php
final class PhabricatorAccessLog {
static $log;
public static function init() {
// NOTE: This currently has no effect, but some day we may reuse PHP
// interpreters to run multiple requests. If we do, it has the effect of
// throwing away the old log.
self::$log = null;
}
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");
// NOTE: Path may be null. We still create the log, it just won't write
// anywhere.
$path = 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;
}
}