enhance exception + fix

This commit is contained in:
Nicolas Le Goff
2012-01-12 18:50:57 +01:00
parent 9de91e25da
commit a538f1e454

View File

@@ -41,17 +41,34 @@ class Monolog extends ServiceAbstract implements ServiceInterface
{
parent::__construct($name, $options);
if (empty($options))
{
throw new \Exception(sprintf("'%s' service options can not be empty", $this->name));
}
//defaut to main handler
$handler = isset($options["handler"]) ? $options["handler"] : false;
if (!$handler)
{
throw new \Exception("You must specify at least one monolog handler");
throw new \Exception(sprintf(
"You must specify at least one handler for %s service"
, $this->name
)
);
}
if (!array_key_exists($handler, $this->handlers))
{
throw new \Exception(sprintf('Unknow monolog handler %s'), $handlerType);
throw new \Exception(sprintf(
"The handler type '%s' declared in %s %s service is not valid.
Available types are %s."
, $handler
, $this->name
, $this->getScope()
, implode(", ", $this->handler)
)
);
}
$handlerName = $this->handlers[$handler];
@@ -60,12 +77,20 @@ class Monolog extends ServiceAbstract implements ServiceInterface
if (!class_exists($handlerClassName))
{
throw new \Exception(sprintf('Unknow monolog handler class %s', $handlerClassName));
throw new \Exception(sprintf(
'Unable to log monolog handler ùs looked for class %s'
, $handlerName
, $handlerClassName)
);
}
if (!isset($options["filename"]))
{
throw new \Exception('you must specify a file to write "filename: my_filename"');
throw new \Exception(sprintf(
"Missing filename option in '%s' service"
, $this->name
)
);
}
$logPath = __DIR__ . '/../../../../logs';
@@ -74,7 +99,9 @@ class Monolog extends ServiceAbstract implements ServiceInterface
if ($handler == 'rotate')
{
$maxDay = isset($options["max_day"]) ? (int) $options["max_day"] : self::DEFAULT_MAX_DAY;
$maxDay = isset($options["max_day"]) ?
(int) $options["max_day"] :
self::DEFAULT_MAX_DAY;
$handlerInstance = new $handlerClassName($file, $maxDay);
}