protected function __construct() { set_error_handler('\\ManiaLive\\Application\\ErrorHandling::createExceptionFromError'); if (extension_loaded('pcntl')) { pcntl_signal(SIGTERM, array($this, 'kill')); pcntl_signal(SIGINT, array($this, 'kill')); declare (ticks=1); } try { $configFile = CommandLineInterpreter::preConfigLoad(); // load configuration file $loader = Loader::getInstance(); $loader->setINIConfigFilename(\ManiaLib\Utils\Path::getInstance()->getConfig(true) . $configFile); $loader->load(); // load configureation from the command line ... CommandLineInterpreter::postConfigLoad(); // add logfile prefix ... $manialiveConfig = \ManiaLive\Config\Config::getInstance(); $serverConfig = \ManiaLive\DedicatedApi\Config::getInstance(); if ($manialiveConfig->logsPrefix != null) { $manialiveConfig->logsPrefix = str_replace('%ip%', str_replace('.', '-', $serverConfig->host), $manialiveConfig->logsPrefix); $manialiveConfig->logsPrefix = str_replace('%port%', $serverConfig->port, $manialiveConfig->logsPrefix); } // disable logging? /*if(!$manialiveConfig->runtimeLog) \ManiaLive\Utilities\Logger::getLog('runtime')->disableLog();*/ } catch (\Exception $e) { // exception on startup ... ErrorHandling::processStartupException($e); } }
protected static function load() { if (!self::$loaded) { $config = \ManiaLive\Config\Config::getInstance(); $path = Path::getInstance()->getLog(true) . DIRECTORY_SEPARATOR; if (!is_dir($path) && !mkdir($path, '0777', true)) { throw new \ManiaLive\Application\FatalException(sprintf("The log repository (%s) does not exists and can't be created", Path::getInstance()->getLog(true))); } self::$loaded = true; self::$staticPath = $path; self::$staticPrefix = $config->logsPrefix ? $config->logsPrefix . '-' : ''; } return !empty(self::$staticPath); }
/** * Process an exception and decides what to do with it. * @param \Exception $e */ public static function processStartupException(\Exception $e) { $message = PHP_EOL . 'Critical startup error!' . PHP_EOL; foreach (self::computeMessage($e) as $line) { $message .= wordwrap($line, 73, PHP_EOL . ' ', true) . PHP_EOL; } $message .= PHP_EOL; // log and display error, then die! error_log($message, 3, Path::getInstance()->getLog(true) . 'ErrorLog_' . getmypid() . '.txt'); die($message); }