Skip to content

Commit

Permalink
Pass log_level config parameter to logging module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Koerber committed Mar 15, 2016
1 parent 5ce3611 commit eadf48f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions graphios.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ log_file = /usr/local/nagios/var/graphios.log
# max log size in megabytes (it will rotate the files)
log_max_size = 24

# available log levels:
# DEBUG, INFO, WARNING, ERROR, CRITICAL
# see https://docs.python.org/2/library/logging.html#logging-levels for details
# DEBUG is quite verbose
#log_level = logging.DEBUG
log_level = logging.INFO
Expand Down
18 changes: 16 additions & 2 deletions graphios.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
# backend global
be = ""

# available loglevels for graphios.cfg
loglevels = {
'logging.DEBUG': logging.DEBUG,
'logging.INFO': logging.INFO,
'logging.WARNING': logging.WARNING,
'logging.ERROR': logging.ERROR,
'logging.CRITICAL': logging.CRITICAL
}

# options parsing
parser = OptionParser("""usage: %prog [options]
sends nagios performance data to carbon.
Expand Down Expand Up @@ -233,6 +242,11 @@ def verify_config(config_dict):
for value in missing_values:
print "%s\n" % value
sys.exit(1)
if not config_dict['log_level'] in loglevels.keys():
print "Unknown loglevel: " + config_dict['log_level'] + '\n'
print "Available loglevels:"
print '\n'.join(sorted(loglevels.keys()))
sys.exit(1)
if "spool_directory" in config_dict:
spool_directory = config_dict['spool_directory']

Expand Down Expand Up @@ -326,13 +340,13 @@ def configure():
log_handler.setFormatter(formatter)
log.addHandler(log_handler)

if "debug" in cfg and cfg["debug"] is True:
if cfg.get("debug") is True or cfg['log_level'] == 'logging.DEBUG':
log.debug("adding streamhandler")
log.setLevel(logging.DEBUG)
log.addHandler(logging.StreamHandler())
debug = True
else:
log.setLevel(logging.INFO)
log.setLevel(loglevels[cfg['log_level']])
debug = False


Expand Down

0 comments on commit eadf48f

Please sign in to comment.