diff options
author | Soren Hansen <soren@linux2go.dk> | 2011-02-16 19:09:40 +0100 |
---|---|---|
committer | Soren Hansen <soren@linux2go.dk> | 2011-02-16 19:09:40 +0100 |
commit | 775fc13f8ea85bb74f8f55dedc02f44cb5aac2b9 (patch) | |
tree | 66b6289cb1e5a418384b7ed1d973cf6c5a4f984f /nova/log.py | |
parent | ef7e1003a2f7f0743808236e7e10d2a2b4369de6 (diff) | |
parent | 17abf5c23f90f15b557131f71657e70e7b5cdef8 (diff) | |
download | nova-775fc13f8ea85bb74f8f55dedc02f44cb5aac2b9.tar.gz nova-775fc13f8ea85bb74f8f55dedc02f44cb5aac2b9.tar.xz nova-775fc13f8ea85bb74f8f55dedc02f44cb5aac2b9.zip |
Merge trunk
Diffstat (limited to 'nova/log.py')
-rw-r--r-- | nova/log.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/nova/log.py b/nova/log.py index 32b6d4629..87a6dd51b 100644 --- a/nova/log.py +++ b/nova/log.py @@ -28,9 +28,11 @@ It also allows setting of formatting information through flags. import cStringIO +import inspect import json import logging import logging.handlers +import os import sys import traceback @@ -111,6 +113,18 @@ def _dictify_context(context): return context +def _get_binary_name(): + return os.path.basename(inspect.stack()[-1][1]) + + +def get_log_file_path(binary=None): + if FLAGS.logfile: + return FLAGS.logfile + if FLAGS.logdir: + binary = binary or _get_binary_name() + return '%s.log' % (os.path.join(FLAGS.logdir, binary),) + + def basicConfig(): logging.basicConfig() for handler in logging.root.handlers: @@ -123,8 +137,9 @@ def basicConfig(): syslog = SysLogHandler(address='/dev/log') syslog.setFormatter(_formatter) logging.root.addHandler(syslog) - if FLAGS.logfile: - logfile = RotatingFileHandler(FLAGS.logfile) + logpath = get_log_file_path() + if logpath: + logfile = RotatingFileHandler(logpath) logfile.setFormatter(_formatter) logging.root.addHandler(logfile) |