mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
IcingaException: Add utility method to format exceptions as one-liner
This commit is contained in:
parent
c1a3d205bc
commit
982e226db0
@ -8,6 +8,7 @@ use Icinga\Data\ConfigObject;
|
|||||||
use Icinga\Application\Logger\Writer\FileWriter;
|
use Icinga\Application\Logger\Writer\FileWriter;
|
||||||
use Icinga\Application\Logger\Writer\SyslogWriter;
|
use Icinga\Application\Logger\Writer\SyslogWriter;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
use Icinga\Exception\IcingaException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logger
|
* Logger
|
||||||
@ -226,13 +227,7 @@ class Logger
|
|||||||
$messages = array();
|
$messages = array();
|
||||||
$error = $message;
|
$error = $message;
|
||||||
do {
|
do {
|
||||||
$messages[] = sprintf(
|
$messages[] = IcingaException::describe($error);
|
||||||
'%s in %s:%d with message: %s',
|
|
||||||
get_class($error),
|
|
||||||
$error->getFile(),
|
|
||||||
$error->getLine(),
|
|
||||||
$error->getMessage()
|
|
||||||
);
|
|
||||||
} while ($error = $error->getPrevious());
|
} while ($error = $error->getPrevious());
|
||||||
$message = implode(' <- ', $messages);
|
$message = implode(' <- ', $messages);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
namespace Icinga\Cli;
|
namespace Icinga\Cli;
|
||||||
|
|
||||||
use Icinga\Application\ApplicationBootstrap as App;
|
use Icinga\Application\ApplicationBootstrap as App;
|
||||||
|
use Icinga\Exception\IcingaException;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Cli\Params;
|
use Icinga\Cli\Params;
|
||||||
use Icinga\Cli\Screen;
|
use Icinga\Cli\Screen;
|
||||||
@ -266,13 +267,7 @@ class Loader
|
|||||||
echo $this->formatTrace($e->getTrace());
|
echo $this->formatTrace($e->getTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->fail(sprintf(
|
$this->fail(IcingaException::describe($e));
|
||||||
'%s in %s:%d with message: %s',
|
|
||||||
get_class($e),
|
|
||||||
$e->getFile(),
|
|
||||||
$e->getLine(),
|
|
||||||
$e->getMessage()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,4 +25,24 @@ class IcingaException extends Exception
|
|||||||
}
|
}
|
||||||
parent::__construct(vsprintf($message, $args), 0, $exc);
|
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()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user