Commit 1e2f4210 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Improved logging.

parent 20561eff
......@@ -37,7 +37,10 @@ def shutdown():
global logger, children
logger.info('Stopping consumers')
logger.info('Hangup children')
[ os.kill(cpid, signal.SIGHUP) for cpid in children ]
logger.info('Wait for children')
[ os.waitpid(cpid, 0) for cpid in children]
logger.info('Shut down')
......@@ -50,6 +53,17 @@ def setup_signal_handler():
signal.signal(signal.SIGQUIT, _signal_handler)
signal.signal(signal.SIGINT, _signal_handler)
def setup_syslog_logging(logger_name):
logger = logging.getLogger(logger_name)
syslog_handler = logging.handlers.SysLogHandler(address='/dev/log',
facility='daemon')
syslog_handler.setLevel(deployit.utils.str_to_loglevel(deployit.config.agent['loglevel']))
formatter = logging.Formatter('%(name)s: %(message)s')
syslog_handler.setFormatter(formatter)
logger.addHandler(syslog_handler)
def main():
global logger, children
......@@ -71,13 +85,9 @@ def main():
with open(deployit.config.agent['pidfile'], 'w') as pidfile:
pidfile.write(str(os.getpid()))
syslog_handler = logging.handlers.SysLogHandler(address='/dev/log',
facility='daemon')
syslog_handler.setLevel(deployit.utils.str_to_loglevel(deployit.config.agent['loglevel']))
formatter = logging.Formatter('%(name)s: %(message)s')
syslog_handler.setFormatter(formatter)
logger.addHandler(syslog_handler)
setup_syslog_logging('deployitagent')
setup_syslog_logging('deployit')
setup_syslog_logging('managementagent')
logger.debug('Going to redirect stdin, stdout, stderr')
dev_null_fd = os.open('/dev/null', os.O_RDWR)
......@@ -86,6 +96,8 @@ def main():
os.dup2(dev_null_fd, sys.stderr.fileno())
os.close(dev_null_fd)
logger.info("Daemonized deployit agent")
else:
ch = logging.StreamHandler()
ch.setLevel(deployit.utils.str_to_loglevel(deployit.config.agent['loglevel']))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment