diff --git a/library/Icinga/Application/Logger.php b/library/Icinga/Application/Logger.php index 26241b3d5..aa03b49fc 100644 --- a/library/Icinga/Application/Logger.php +++ b/library/Icinga/Application/Logger.php @@ -8,6 +8,7 @@ use Icinga\Data\ConfigObject; use Icinga\Application\Logger\Writer\FileWriter; use Icinga\Application\Logger\Writer\SyslogWriter; use Icinga\Exception\ConfigurationError; +use Icinga\Exception\IcingaException; /** * Logger @@ -226,13 +227,7 @@ class Logger $messages = array(); $error = $message; do { - $messages[] = sprintf( - '%s in %s:%d with message: %s', - get_class($error), - $error->getFile(), - $error->getLine(), - $error->getMessage() - ); + $messages[] = IcingaException::describe($error); } while ($error = $error->getPrevious()); $message = implode(' <- ', $messages); } diff --git a/library/Icinga/Cli/Loader.php b/library/Icinga/Cli/Loader.php index 316a8062e..debf52be9 100644 --- a/library/Icinga/Cli/Loader.php +++ b/library/Icinga/Cli/Loader.php @@ -4,6 +4,7 @@ namespace Icinga\Cli; use Icinga\Application\ApplicationBootstrap as App; +use Icinga\Exception\IcingaException; use Icinga\Exception\ProgrammingError; use Icinga\Cli\Params; use Icinga\Cli\Screen; @@ -266,13 +267,7 @@ class Loader echo $this->formatTrace($e->getTrace()); } - $this->fail(sprintf( - '%s in %s:%d with message: %s', - get_class($e), - $e->getFile(), - $e->getLine(), - $e->getMessage() - )); + $this->fail(IcingaException::describe($e)); } } diff --git a/library/Icinga/Exception/IcingaException.php b/library/Icinga/Exception/IcingaException.php index ab6591b01..bdc6833a3 100644 --- a/library/Icinga/Exception/IcingaException.php +++ b/library/Icinga/Exception/IcingaException.php @@ -25,4 +25,24 @@ class IcingaException extends Exception } parent::__construct(vsprintf($message, $args), 0, $exc); } + + /** + * Return the given exception formatted as one-liner + * + * The format used is: %class% in %path%:%line% with message: %message% + * + * @param Exception $exception + * + * @return string + */ + public static function describe(Exception $exception) + { + return sprintf( + '%s in %s:%d with message: %s', + get_class($exception), + $exception->getFile(), + $exception->getLine(), + $exception->getMessage() + ); + } }