modified CliController to use ErrorStream conf var and separate logging by LOGGING/PROFILER settings

This commit is contained in:
Anton Grebnev
2012-10-05 19:39:23 +04:00
parent 8d60abe7d1
commit 5bc65513eb
2 changed files with 40 additions and 28 deletions

View File

@ -24,7 +24,7 @@ class CliController
protected function __construct()
{
ErrorHandler::init();
$this->error_stream = fopen('php://stderr', 'rw');
$this->error_stream = Config::get('ErrorStream');
}
/**
@ -51,11 +51,20 @@ class CliController
}
$cli_class->run();
if (Config::get('PROFILER')) {
echo PHP_EOL . Profiler::getInstance()->getCli();
$profile = Profiler::getInstance()->getCli();
if (Config::get('LOGGING')) {
Logger::getInstance()->log($profile);
} else {
echo $profile;
}
}
} catch (Exception $e) {
fwrite($this->error_stream, PHP_EOL . 'Error: ' . $e->getMessage() . PHP_EOL);
fwrite($this->error_stream, PHP_EOL . 'Stack trace: ' . PHP_EOL . $e->getTraceAsString() . PHP_EOL);
$code = $e->getCode();
if ($e instanceof ErrorException) {
$code = $e->getSeverity();
}
file_put_contents($this->error_stream, PHP_EOL . 'Error ' . '#' . $code . ': ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
file_put_contents($this->error_stream, PHP_EOL . 'Stack trace: ' . PHP_EOL . $e->getTraceAsString() . PHP_EOL, FILE_APPEND);
}
}
}