/** * Enables displaying or logging errors and exceptions. * @param mixed production, development mode, autodetection or IP address(es) whitelist. * @param string error log directory * @param string administrator email; enables email sending in production mode * @return void */ public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL) { self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(TRUE); error_reporting(E_ALL); if ($mode !== NULL || self::$productionMode === NULL) { self::$productionMode = is_bool($mode) ? $mode : !self::detectDebugMode($mode); } // logging configuration if ($email !== NULL) { self::$email = $email; } if ($logDirectory !== NULL) { self::$logDirectory = $logDirectory; } if (self::$logDirectory) { if (!is_dir(self::$logDirectory) || !preg_match('#([a-z]:)?[/\\\\]#Ai', self::$logDirectory)) { self::$logDirectory = NULL; self::exceptionHandler(new \RuntimeException('Logging directory not found or is not absolute path.')); } } // php configuration if (function_exists('ini_set')) { ini_set('display_errors', !self::$productionMode); // or 'stderr' ini_set('html_errors', FALSE); ini_set('log_errors', FALSE); } elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) { self::exceptionHandler(new \RuntimeException("Unable to set 'display_errors' because function ini_set() is disabled.")); } if (!self::$enabled) { register_shutdown_function([__CLASS__, 'shutdownHandler']); set_exception_handler([__CLASS__, 'exceptionHandler']); set_error_handler([__CLASS__, 'errorHandler']); array_map('class_exists', [Bar::class, BlueScreen::class, DefaultBarPanel::class, Dumper::class, FireLogger::class, Helpers::class, Logger::class]); self::$enabled = TRUE; } }
/** * Enables displaying or logging errors and exceptions. * @param mixed production, development mode, autodetection or IP address(es) whitelist. * @param string error log directory; enables logging in production mode, FALSE means that logging is disabled * @param string administrator email; enables email sending in production mode * @return void */ public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL) { self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(TRUE); if (isset($_SERVER['REQUEST_URI'])) { self::$source = (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://') . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $_SERVER['REQUEST_URI']; } else { self::$source = empty($_SERVER['argv']) ? 'CLI' : 'CLI: ' . implode(' ', $_SERVER['argv']); } error_reporting(E_ALL | E_STRICT); // production/development mode detection if (is_bool($mode)) { self::$productionMode = $mode; } elseif ($mode !== self::DETECT || self::$productionMode === NULL) { // IP addresses or computer names whitelist detection $list = is_string($mode) ? preg_split('#[,\\s]+#', $mode) : (array) $mode; if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $list[] = '127.0.0.1'; $list[] = '::1'; } self::$productionMode = !in_array(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : php_uname('n'), $list, TRUE); } // logging configuration if ($email !== NULL) { self::$email = $email; } if (is_string($logDirectory)) { self::$logDirectory = realpath($logDirectory); if (self::$logDirectory === FALSE) { self::_exceptionHandler(new \RuntimeException("Log directory is not found or is not directory.")); } } elseif ($logDirectory === FALSE) { self::$logDirectory = NULL; } if (self::$logDirectory) { ini_set('error_log', self::$logDirectory . '/php_error.log'); } // php configuration if (function_exists('ini_set')) { ini_set('display_errors', !self::$productionMode); // or 'stderr' ini_set('html_errors', FALSE); ini_set('log_errors', FALSE); } elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) { self::_exceptionHandler(new \RuntimeException("Unable to set 'display_errors' because function ini_set() is disabled.")); } if (!self::$enabled) { register_shutdown_function(array(__CLASS__, '_shutdownHandler')); set_exception_handler(array(__CLASS__, '_exceptionHandler')); set_error_handler(array(__CLASS__, '_errorHandler')); foreach (array('Tracy\\Bar', 'Tracy\\BlueScreen', 'Tracy\\DefaultBarPanel', 'Tracy\\Dumper', 'Tracy\\FireLogger', 'Tracy\\Helpers', 'Tracy\\Logger') as $class) { class_exists($class); } self::$enabled = TRUE; } }
/** * Enables displaying or logging errors and exceptions. * @param mixed production, development mode, autodetection or IP address(es) whitelist. * @param string error log directory * @param string administrator email; enables email sending in production mode * @return void */ public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL) { if ($mode !== NULL || self::$productionMode === NULL) { self::$productionMode = is_bool($mode) ? $mode : !self::detectDebugMode($mode); } self::$reserved = str_repeat('t', 300000.0); self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(TRUE); self::$obLevel = ob_get_level(); self::$cpuUsage = !self::$productionMode && function_exists('getrusage') ? getrusage() : NULL; // logging configuration if ($email !== NULL) { self::$email = $email; } if ($logDirectory !== NULL) { self::$logDirectory = $logDirectory; } if (self::$logDirectory) { if (!is_dir(self::$logDirectory) || !preg_match('#([a-z]+:)?[/\\\\]#Ai', self::$logDirectory)) { self::$logDirectory = NULL; self::exceptionHandler(new \RuntimeException('Logging directory not found or is not absolute path.')); } } // php configuration if (function_exists('ini_set')) { ini_set('display_errors', !self::$productionMode); // or 'stderr' ini_set('html_errors', FALSE); ini_set('log_errors', FALSE); } elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) { self::exceptionHandler(new \RuntimeException("Unable to set 'display_errors' because function ini_set() is disabled.")); } error_reporting(E_ALL | E_STRICT); if (!self::$enabled) { register_shutdown_function(array(__CLASS__, 'shutdownHandler')); set_exception_handler(array(__CLASS__, 'exceptionHandler')); set_error_handler(array(__CLASS__, 'errorHandler')); array_map('class_exists', array('Tracy\\Bar', 'Tracy\\BlueScreen', 'Tracy\\DefaultBarPanel', 'Tracy\\Dumper', 'Tracy\\FireLogger', 'Tracy\\Helpers', 'Tracy\\Logger')); self::$enabled = TRUE; } }
/** * Enables displaying or logging errors and exceptions. * @param mixed production, development mode, autodetection or IP address(es) whitelist. * @param string error log directory * @param string administrator email; enables email sending in production mode * @return void */ public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL) { if ($mode !== NULL || self::$productionMode === NULL) { self::$productionMode = is_bool($mode) ? $mode : !self::detectDebugMode($mode); } self::$maxLen =& self::$maxLength; self::$reserved = str_repeat('t', 300000.0); self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(TRUE); self::$obLevel = ob_get_level(); self::$cpuUsage = !self::$productionMode && function_exists('getrusage') ? getrusage() : NULL; // logging configuration if ($email !== NULL) { self::$email = $email; } if ($logDirectory !== NULL) { self::$logDirectory = $logDirectory; } if (self::$logDirectory) { if (!is_dir(self::$logDirectory) || !preg_match('#([a-z]+:)?[/\\\\]#Ai', self::$logDirectory)) { self::$logDirectory = NULL; self::exceptionHandler(new \RuntimeException('Logging directory not found or is not absolute path.')); } } // php configuration if (function_exists('ini_set')) { ini_set('display_errors', !self::$productionMode); // or 'stderr' ini_set('html_errors', FALSE); ini_set('log_errors', FALSE); } elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) { self::exceptionHandler(new \RuntimeException("Unable to set 'display_errors' because function ini_set() is disabled.")); } error_reporting(E_ALL); if (self::$enabled) { return; } self::$enabled = TRUE; register_shutdown_function([__CLASS__, 'shutdownHandler']); set_exception_handler([__CLASS__, 'exceptionHandler']); set_error_handler([__CLASS__, 'errorHandler']); array_map('class_exists', ['Tracy\\Bar', 'Tracy\\BlueScreen', 'Tracy\\DefaultBarPanel', 'Tracy\\Dumper', 'Tracy\\FireLogger', 'Tracy\\Helpers', 'Tracy\\Logger']); if (self::$productionMode) { } elseif (headers_sent($file, $line) || ob_get_length()) { throw new \LogicException(__METHOD__ . '() called after some output has been sent. ' . ($file ? "Output started at {$file}:{$line}." : 'Try Tracy\\OutputDebugger to find where output started.')); } elseif (self::getBar()->dispatchAssets()) { exit; } elseif (session_status() === PHP_SESSION_ACTIVE) { self::dispatch(); } }