X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=logger.py;h=8abd8fd10bb8150b77bd3f1dbcf1021a3c86e0e0;hb=refs%2Fheads%2Fplanetlab-4_0-branch;hp=eb99cafa9faf58b783c5d9221182f8813fc780d3;hpb=dfbec103d5234340d11f454c70c82891e5ac9344;p=nodemanager.git diff --git a/logger.py b/logger.py index eb99caf..8abd8fd 100644 --- a/logger.py +++ b/logger.py @@ -1,24 +1,27 @@ """A very simple logger that tries to be concurrency-safe.""" -import os +import os, sys import subprocess import time import traceback -LOG_FILE = '/var/log/pl_node_mgr.log' - +LOG_FILE = '/var/log/nm' def log(msg): """Write to the log file.""" - fd = os.open(LOG_FILE, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0600) - if not msg.endswith('\n'): msg += '\n' - os.write(fd, '%s: %s' % (time.asctime(time.gmtime()), msg)) - os.close(fd) + try: + fd = os.open(LOG_FILE, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0600) + if not msg.endswith('\n'): msg += '\n' + os.write(fd, '%s: %s' % (time.asctime(time.gmtime()), msg)) + os.close(fd) + except OSError: + sys.stderr.write(msg) + sys.stderr.flush() def log_call(*args): log('running command %s' % ' '.join(args)) - try: subprocess.call(args) + try: subprocess.call(args, close_fds=True) except: log_exc() def log_exc():