-def log(msg):
- """Write <msg> to the log file."""
- # the next three lines ought to be an atomic operation but aren't
- fd = os.open(LOG_FILE, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0600)
- flags = fcntl.fcntl(fd, fcntl.F_GETFD)
- fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
- if not msg.endswith('\n'): msg += '\n'
- os.write(fd, '%s: %s' % (time.asctime(time.gmtime()), msg))
- os.close(fd)
+def verbose(msg):
+ log(msg,LOG_VERBOSE)
+
+def log(msg,level=LOG_NODE):
+ """Write <msg> to the log file if level >= current log level (default LOG_NODE)."""
+ if (level > LOG_LEVEL):
+ return
+ 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()