Francesco Romani has uploaded a new change for review.
Change subject: API: streamline and make setLogLevel correct ......................................................................
API: streamline and make setLogLevel correct
According to the schema, setLogLevel should accept a log level string ('DEBUG', 'INFO',...). But the code actually blindly casted the given value to int(), and this suggests the code actually expected an integer value.
To make things a bit user friendlier and comformant to schema, change the argument to actually be a log level in string format.
Along the way, this patch streamlines the implementation of setLogLevel and makes it simpler.
Change-Id: Iaddbb12d13bdbaa7a02255ab209da11e42d2ea97 Signed-off-by: Francesco Romani fromani@redhat.com --- M vdsm/API.py 1 file changed, 21 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/25/38425/1
diff --git a/vdsm/API.py b/vdsm/API.py index 5cbda50..85478b1 100644 --- a/vdsm/API.py +++ b/vdsm/API.py @@ -1369,13 +1369,22 @@
Doesn't survive a restart """ - logging.info('Setting loglevel to %s', level) - handlers = logging.getLogger().handlers - [fileHandler] = [h for h in handlers if - isinstance(h, logging.FileHandler)] - fileHandler.setLevel(int(level)) + LEVELS = { + 'DEBUG': logging.DEBUG, + 'INFO': logging.INFO, + 'WARNING': logging.WARNING, + 'ERROR': logging.ERROR, + 'CRITICAL': logging.CRITICAL + }
- return {'status': doneCode} + try: + log_level = LEVELS[level] + except KeyError: + return errCode['unavail'] + else: + logging.info('Setting loglevel to %s (%d)', level, log_level) + _set_log_level(logging.getLogger(), log_level) + return {'status': doneCode}
# VM-related functions def getVMList(self, fullStatus=False, vmList=()): @@ -1772,3 +1781,9 @@ logging.warn("options %s is deprecated. Use %s instead" % (k, _translationMap[k])) options[_translationMap[k]] = options.pop(k) + + +def _set_log_level(logger, log_level): + for handler in logger.handlers: + if isinstance(handler, logging.FileHandler): + handler.setLevel(log_level)