From dab42173c099f2a4babe03d06cd9df989d4de70f Mon Sep 17 00:00:00 2001 From: Anton Arefiev Date: Fri, 4 Mar 2016 12:18:17 +0200 Subject: [PATCH] Allow specify log level for Error exception For now, all Error exceptions logged with error level, but some exceptions may be expected as correct flow and they shouldn't be logged as errors. NotFoundInCacheError, for example, is raised when there isn't info in cache about introspected node, this case may be handled by not_found_hook, so this wouldn't be error anymore. Change-Id: Ie537ccaef0035b2ef839c34fad0a5e6c9ba8f064 --- ironic_inspector/utils.py | 7 ++++--- .../log-info-not-found-cache-error-afbc87e80305ca5c.yaml | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/log-info-not-found-cache-error-afbc87e80305ca5c.yaml diff --git a/ironic_inspector/utils.py b/ironic_inspector/utils.py index e7b20064a..b8456e0cf 100644 --- a/ironic_inspector/utils.py +++ b/ironic_inspector/utils.py @@ -103,9 +103,9 @@ LOG = getProcessingLogger(__name__) class Error(Exception): """Inspector exception.""" - def __init__(self, msg, code=400, **kwargs): + def __init__(self, msg, code=400, log_level='error', **kwargs): super(Error, self).__init__(msg) - LOG.error(msg, **kwargs) + getattr(LOG, log_level)(msg, **kwargs) self.http_code = code @@ -113,7 +113,8 @@ class NotFoundInCacheError(Error): """Exception when node was not found in cache during processing.""" def __init__(self, msg, code=404): - super(NotFoundInCacheError, self).__init__(msg, code) + super(NotFoundInCacheError, self).__init__(msg, code, + log_level='info') def spawn_n(*args, **kwargs): diff --git a/releasenotes/notes/log-info-not-found-cache-error-afbc87e80305ca5c.yaml b/releasenotes/notes/log-info-not-found-cache-error-afbc87e80305ca5c.yaml new file mode 100644 index 000000000..70628dcc9 --- /dev/null +++ b/releasenotes/notes/log-info-not-found-cache-error-afbc87e80305ca5c.yaml @@ -0,0 +1,5 @@ +--- +other: + - Log level for error when node was not found in Inspector cache was + changed from error to info level. It was done because not_found_hook + may handle this case, so this wouldn't be error anymore.