3 final class DarkConsoleErrorLogPluginAPI
extends Phobject
{
5 private static $errors = array();
7 private static $discardMode = false;
9 public static function registerErrorHandler() {
10 // NOTE: This forces PhutilReadableSerializer to load, so that we are
11 // able to handle errors which fire from inside autoloaders (PHP will not
12 // reenter autoloaders).
13 PhutilReadableSerializer
::printableValue(null);
14 PhutilErrorHandler
::setErrorListener(
15 array(__CLASS__
, 'handleErrors'));
18 public static function enableDiscardMode() {
19 self
::$discardMode = true;
22 public static function disableDiscardMode() {
23 self
::$discardMode = false;
26 public static function getErrors() {
30 public static function handleErrors($event, $value, $metadata) {
31 if (self
::$discardMode) {
36 case PhutilErrorHandler
::EXCEPTION
:
37 // $value is of type Exception
38 self
::$errors[] = array(
39 'details' => $value->getMessage(),
41 'file' => $value->getFile(),
42 'line' => $value->getLine(),
43 'str' => $value->getMessage(),
44 'trace' => $metadata['trace'],
47 case PhutilErrorHandler
::ERROR
:
48 // $value is a simple string
49 self
::$errors[] = array(
52 'file' => $metadata['file'],
53 'line' => $metadata['line'],
55 'trace' => $metadata['trace'],
58 case PhutilErrorHandler
::PHLOG
:
59 // $value can be anything
60 self
::$errors[] = array(
61 'details' => PhutilReadableSerializer
::printShallow($value, 3),
63 'file' => $metadata['file'],
64 'line' => $metadata['line'],
65 'str' => PhutilReadableSerializer
::printShort($value),
66 'trace' => $metadata['trace'],
70 error_log(pht('Unknown event: %s', $event));