Improve logging.
Allow pipeline workers to log to different logfiles (the python logging system is not entirely multiprocess safe) Allow users to set a logging name for each worker process to differentiate logs. Change-Id: Ic93e88270d58495cda918dab503f65d9f550e2b6
This commit is contained in:
parent
4cb16327c7
commit
0a2bf4471e
@ -1,7 +1,7 @@
|
||||
[metadata]
|
||||
description-file = README.md
|
||||
name = winchester
|
||||
version = 0.51
|
||||
version = 0.52
|
||||
author = Monsyne Dragon
|
||||
author_email = mdragon@rackspace.com
|
||||
summary = An OpenStack notification event processing library.
|
||||
|
@ -124,8 +124,12 @@ class PipelineManager(object):
|
||||
return configs
|
||||
|
||||
def __init__(self, config, db=None, pipeline_handlers=None,
|
||||
pipeline_config=None, trigger_defs=None, time_sync=None):
|
||||
logger.debug("PipelineManager: Using config: %s" % str(config))
|
||||
pipeline_config=None, trigger_defs=None, time_sync=None,
|
||||
proc_name='pipeline_worker'):
|
||||
#name used to distinguish worker processes in logs
|
||||
self.proc_name = proc_name
|
||||
|
||||
logger.debug("PipelineManager(%s): Using config: %s" % (self.proc_name, str(config)))
|
||||
config = ConfigManager.wrap(config, self.config_description())
|
||||
self.config = config
|
||||
config.check_config()
|
||||
|
@ -16,20 +16,37 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="Winchester pipeline worker")
|
||||
parser.add_argument('--config', '-c', default='winchester.yaml',
|
||||
help='The name of the winchester config file')
|
||||
parser.add_argument('--name', '-n', default='pipeline_worker',
|
||||
help='The name of this process for logging purposes')
|
||||
parser.add_argument('--daemon', '-d', help='Run in daemon mode.')
|
||||
args = parser.parse_args()
|
||||
|
||||
conf = ConfigManager.load_config_file(args.config)
|
||||
proc_name = args.name
|
||||
|
||||
if 'log_level' in conf:
|
||||
level = conf['log_level']
|
||||
level = getattr(logging, level.upper())
|
||||
else:
|
||||
level = logging.INFO
|
||||
|
||||
if 'log_file' in conf:
|
||||
log_file = conf['log_file'] % dict(proc_name=proc_name)
|
||||
else:
|
||||
log_file = '%(proc_name)s.log' % dict(proc_name=proc_name)
|
||||
|
||||
# This is a hack, but it's needed to pass the logfile name & default
|
||||
# loglevel into log handlers configured with a config file. (mdragon)
|
||||
logging.LOCAL_LOG_FILE = config_file
|
||||
logging.LOCAL_DEFAULT_LEVEL = default_log_level
|
||||
|
||||
if 'logging_config' in conf:
|
||||
fileConfig(conf['logging_config'])
|
||||
else:
|
||||
logging.basicConfig()
|
||||
if 'log_level' in conf:
|
||||
level = conf['log_level']
|
||||
level = getattr(logging, level.upper())
|
||||
logging.getLogger('winchester').setLevel(level)
|
||||
logging.getLogger('winchester').setLevel(level)
|
||||
timesync = time_sync.TimeSync(conf)
|
||||
pipe = PipelineManager(conf, time_sync=timesync)
|
||||
pipe = PipelineManager(conf, time_sync=timesync, proc_name=proc_name)
|
||||
if args.daemon:
|
||||
print "Backgrounding for daemon mode."
|
||||
with daemon.DaemonContext():
|
||||
|
Loading…
x
Reference in New Issue
Block a user