Skip to content

Commit

Permalink
show the class dump only with --debug
Browse files Browse the repository at this point in the history
  • Loading branch information
lausser committed Feb 16, 2024
1 parent aaea250 commit b3762c2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion bin/coshsh-cook
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion bin/coshsh-create-template-tree
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 7 additions & 3 deletions coshsh/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion tests/common_coshsh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b3762c2

Please sign in to comment.