From b3762c258cb9d4c92fe918e8ae46dd9485951db3 Mon Sep 17 00:00:00 2001 From: Gerhard Lausser Date: Fri, 16 Feb 2024 17:25:09 +0100 Subject: [PATCH] show the class dump only with --debug --- Changelog | 2 ++ bin/coshsh-cook | 3 ++- bin/coshsh-create-template-tree | 3 ++- coshsh/generator.py | 10 +++++++--- setup.py | 2 +- tests/common_coshsh_test.py | 3 ++- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Changelog b/Changelog index 258fa49..4c6609c 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +* 2024-02-16 10.2.1.3 + show the class dump only with --debug * 2024-02-16 10.2.1.2 make all datasources and recipients strict * 2024-02-16 10.2.1.1 diff --git a/bin/coshsh-cook b/bin/coshsh-cook index 430c631..6c72145 100755 --- a/bin/coshsh-cook +++ b/bin/coshsh-cook @@ -64,8 +64,9 @@ if __name__ == '__main__': opts, args = parser.parse_args() generator = Generator() + generator.set_default_log_level(opts.default_log_level) if opts.cookbook_files: - generator.read_cookbook(opts.cookbook_files, opts.default_recipe, opts.default_log_level, opts.force, opts.safe_output) + generator.read_cookbook(opts.cookbook_files, opts.default_recipe, opts.force, opts.safe_output) else: parser.error("Use option -c/--cookbook") if args: diff --git a/bin/coshsh-create-template-tree b/bin/coshsh-create-template-tree index 9fd7e35..18b5112 100755 --- a/bin/coshsh-create-template-tree +++ b/bin/coshsh-create-template-tree @@ -72,7 +72,8 @@ if __name__ == '__main__': opts, args = parser.parse_args() generator = Generator() if opts.cookbook_files: - generator.read_cookbook(opts.cookbook_files, opts.default_recipe, opts.default_log_level, opts.force, opts.safe_output) + generator.set_default_log_level(opts.default_log_level) + generator.read_cookbook(opts.cookbook_files, opts.default_recipe, opts.force, opts.safe_output) cookbook = generator.cookbook if not opts.template_name: parser.error("Which template hierarchy should i create? Use --template") diff --git a/coshsh/generator.py b/coshsh/generator.py index cb2a18f..ec02640 100644 --- a/coshsh/generator.py +++ b/coshsh/generator.py @@ -27,6 +27,10 @@ class Generator(object): def __init__(self): self.recipes = coshsh.util.odict() + self.default_log_level = "info" + + def set_default_log_level(self, default_log_level): + self.default_log_level = default_log_level def add_recipe(self, *args, **kwargs): try: @@ -124,11 +128,11 @@ def run(self): else: if recipe_completed: logger.info("recipe {} completed with {} problems".format(recipe.name, recipe.render_errors)) - if logger.level >= DEBUG: + if self.default_log_level == "debug": CoshshDatainterface.dump_classes_usage() coshsh.util.restore_logging() - def read_cookbook(self, cookbook_files, default_recipe, default_log_level, force, safe_output): + def read_cookbook(self, cookbook_files, default_recipe, force, safe_output): self.cookbook_files = '___'.join(map(lambda cf: os.path.basename(os.path.abspath(cf)), cookbook_files)) recipe_configs = {} datasource_configs = {} @@ -173,7 +177,7 @@ def read_cookbook(self, cookbook_files, default_recipe, default_log_level, force backup_count = int(dict(cookbook.items("defaults"))["backup_count"]) else: backup_count = 2 - if default_log_level and default_log_level.lower() == "debug" or "defaults" in cookbook.sections() and "log_level" in [c[0] for c in cookbook.items("defaults")] and cookbook.items("defaults")["log_level"].lower() == "debug": + if self.default_log_level and self.default_log_level.lower() == "debug" or "defaults" in cookbook.sections() and "log_level" in [c[0] for c in cookbook.items("defaults")] and cookbook.items("defaults")["log_level"].lower() == "debug": coshsh.util.setup_logging(logdir=log_dir, scrnloglevel=DEBUG, backup_count=backup_count) else: coshsh.util.setup_logging(logdir=log_dir, scrnloglevel=INFO, backup_count=backup_count) diff --git a/setup.py b/setup.py index 48ca70b..f442fd9 100755 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ def run(self): setup(name='coshsh', - version='10.2.1.2', + version='10.2.1.3', setup_requires=['wheel'], description='Coshsh - config generator for monitoring systems', long_description=open('README.md').read(), diff --git a/tests/common_coshsh_test.py b/tests/common_coshsh_test.py index 6e9609d..8d36a30 100644 --- a/tests/common_coshsh_test.py +++ b/tests/common_coshsh_test.py @@ -63,7 +63,8 @@ def setUp(self): def setUpConfig(self, configfile, default_recipe, default_log_level="info", force=False, safe_output=False): - self.generator.read_cookbook([configfile], default_recipe, default_log_level, force, safe_output) + self.generator.set_default_log_level(default_log_level) + self.generator.read_cookbook([configfile], default_recipe, force, safe_output) def setUpObjectsDir(self): if not isinstance(self._objectsdir, list):