From 314a931b84d5b94df818226a8343453e1d34b9c2 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sat, 12 Aug 2017 21:40:23 +0200 Subject: [PATCH 1/2] Respect cdist log level in emulator. --- cdist/core/manifest.py | 4 ++-- cdist/emulator.py | 7 ++++--- cdist/test/manifest/__init__.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cdist/core/manifest.py b/cdist/core/manifest.py index 6f941550..0a26601a 100644 --- a/cdist/core/manifest.py +++ b/cdist/core/manifest.py @@ -113,8 +113,8 @@ class Manifest(object): '__target_host_tags': self.local.target_host_tags, } - if self.log.getEffectiveLevel() == logging.DEBUG: - self.env.update({'__cdist_debug': "yes"}) + self.env.update( + {'__cdist_loglevel': str(self.log.getEffectiveLevel())}) def _open_logger(self): self.log = logging.getLogger(self.target_host[0]) diff --git a/cdist/emulator.py b/cdist/emulator.py index 7c9dfcca..66736643 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -104,10 +104,11 @@ class Emulator(object): def __init_log(self): """Setup logging facility""" - if '__cdist_debug' in self.env: - logging.root.setLevel(logging.DEBUG) + if '__cdist_loglevel' in self.env: + level = int(self.env['__cdist_loglevel']) else: - logging.root.setLevel(logging.INFO) + level = logging.OFF + logging.root.setLevel(level) self.log = logging.getLogger(self.target_host[0]) diff --git a/cdist/test/manifest/__init__.py b/cdist/test/manifest/__init__.py index e0da2d9f..95bf2768 100644 --- a/cdist/test/manifest/__init__.py +++ b/cdist/test/manifest/__init__.py @@ -136,7 +136,7 @@ class ManifestTestCase(test.CdistTestCase): current_level = self.log.getEffectiveLevel() self.log.setLevel(logging.DEBUG) manifest = cdist.core.manifest.Manifest(self.target_host, self.local) - self.assertTrue("__cdist_debug" in manifest.env) + self.assertTrue("__cdist_loglevel" in manifest.env) self.log.setLevel(current_level) From 87fe52ea61ce693ccb6d894b22b37cff0fd0f7eb Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sat, 12 Aug 2017 23:02:31 +0200 Subject: [PATCH 2/2] Default logging level is WARNING. --- cdist/emulator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 66736643..eff2f221 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -105,9 +105,12 @@ class Emulator(object): """Setup logging facility""" if '__cdist_loglevel' in self.env: - level = int(self.env['__cdist_loglevel']) + try: + level = int(self.env['__cdist_loglevel']) + except: + level = logging.WARNING else: - level = logging.OFF + level = logging.WARNING logging.root.setLevel(level) self.log = logging.getLogger(self.target_host[0])