Skip to content
Snippets Groups Projects
Commit b03c7b74 authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

add: node instance id in logs

parent 645e3abf
No related branches found
No related tags found
No related merge requests found
......@@ -46,13 +46,9 @@ def authentication(node, suicide, login, password):
timeout = MAX_AUTH_TIMEOUT
sleep(exp(timeout))
def run_node(options):
def setup_logging(options, instance_id=None):
'''
'''
# instance life signal
suicide_event = threading.Event()
# setup logging facility:
level = logging.ERROR
verb = int(options['verbosity'])
if verb:
......@@ -70,23 +66,41 @@ def run_node(options):
facility = logging.handlers.SysLogHandler.LOG_DAEMON
handler = logging.handlers.SysLogHandler(address='/dev/log',
facility=facility)
fmt = 'cc-node: %(levelname)s '
if options['verbosity'] == 0:
fmt = 'cc-node: %(levelname)s %(message)s'
fmt += '%(message)s'
else:
if isinstance(instance_id, int):
fmt += 'id=%i ' % instance_id
if options['stdout']:
fmt = ("cc-node: %(levelname)s \x1B[30;47m%(process)d\x1B[0m:"
"\x1B[30;42m%(threadName)s\x1B[0m:\x1B[30;43m%(funcName)s"
"\x1B[0m:\x1B[30;44m%(lineno)d\x1B[0m@\x1B[30;45m%(msecs)d"
"\x1B[0m\t\t %(message)s")
fmt += ("\x1B[30;47m%(process)d\x1B[0m:"
"\x1B[30;42m%(threadName)s\x1B[0m:"
"\x1B[30;43m%(funcName)s\x1B[0m:"
"\x1B[30;44m%(lineno)d\x1B[0m@"
"\x1B[30;45m%(msecs)d"
"\x1B[0m\t\t "
"%(message)s")
else:
fmt = ("cc-node: %(levelname)s %(process)d:%(threadName)s:"
"%(funcName)s:%(lineno)d@%(msecs)d %(message)s")
fmt += ("%(process)d:"
"%(threadName)s:"
"%(funcName)s:"
"%(lineno)d@"
"%(msecs)d "
"%(message)s")
handler.setFormatter(logging.Formatter(fmt))
logger.handlers = []
logger.addHandler(handler)
def run_node(options):
'''
'''
# instance death event
suicide_event = threading.Event()
# start node
try:
# setup logging infrastructure
setup_logging(options)
# create client
logging.debug('Initializing client')
try:
......@@ -98,6 +112,10 @@ def run_node(options):
logging.error('Client initialization failure: `%s`:`%s`',
repr(err), err)
raise err
# reconfigure logging with instance ID
setup_logging(options, instance_id=id(node))
# auth thread
logging.debug('Starting authentication thread')
auth_thread = threading.Thread(target=authentication, name='Auth',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment