Path: blob/master/src/applications/console/plugin/errorlog/DarkConsoleErrorLogPluginAPI.php
13409 views
<?php12final class DarkConsoleErrorLogPluginAPI extends Phobject {34private static $errors = array();56private static $discardMode = false;78public static function registerErrorHandler() {9// NOTE: This forces PhutilReadableSerializer to load, so that we are10// able to handle errors which fire from inside autoloaders (PHP will not11// reenter autoloaders).12PhutilReadableSerializer::printableValue(null);13PhutilErrorHandler::setErrorListener(14array(__CLASS__, 'handleErrors'));15}1617public static function enableDiscardMode() {18self::$discardMode = true;19}2021public static function disableDiscardMode() {22self::$discardMode = false;23}2425public static function getErrors() {26return self::$errors;27}2829public static function handleErrors($event, $value, $metadata) {30if (self::$discardMode) {31return;32}3334switch ($event) {35case PhutilErrorHandler::EXCEPTION:36// $value is of type Exception37self::$errors[] = array(38'details' => $value->getMessage(),39'event' => $event,40'file' => $value->getFile(),41'line' => $value->getLine(),42'str' => $value->getMessage(),43'trace' => $metadata['trace'],44);45break;46case PhutilErrorHandler::ERROR:47// $value is a simple string48self::$errors[] = array(49'details' => $value,50'event' => $event,51'file' => $metadata['file'],52'line' => $metadata['line'],53'str' => $value,54'trace' => $metadata['trace'],55);56break;57case PhutilErrorHandler::PHLOG:58// $value can be anything59self::$errors[] = array(60'details' => PhutilReadableSerializer::printShallow($value, 3),61'event' => $event,62'file' => $metadata['file'],63'line' => $metadata['line'],64'str' => PhutilReadableSerializer::printShort($value),65'trace' => $metadata['trace'],66);67break;68default:69error_log(pht('Unknown event: %s', $event));70break;71}72}7374}757677