summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSoren Hansen <soren@linux2go.dk>2011-02-16 09:54:54 +0000
committerTarmac <>2011-02-16 09:54:54 +0000
commit17abf5c23f90f15b557131f71657e70e7b5cdef8 (patch)
treec73f7a6aa32ac3b5de4c185d6e50aa63a5afb7b6
parent6c9bb2b8102be4874c24b474649395e9fb2b7580 (diff)
parent9f1c46f5be0520afac21c3320e206ced98acd9ba (diff)
downloadnova-17abf5c23f90f15b557131f71657e70e7b5cdef8.tar.gz
nova-17abf5c23f90f15b557131f71657e70e7b5cdef8.tar.xz
nova-17abf5c23f90f15b557131f71657e70e7b5cdef8.zip
Add back --logdir=DIR option. If set, a logfile named after the binary (e.g. nova-api.log) will be kept in DIR.
-rw-r--r--nova/flags.py2
-rw-r--r--nova/log.py19
-rw-r--r--nova/tests/test_log.py21
-rw-r--r--nova/twistd.py2
4 files changed, 40 insertions, 4 deletions
diff --git a/nova/flags.py b/nova/flags.py
index 3ba3fe6fa..f64a62da9 100644
--- a/nova/flags.py
+++ b/nova/flags.py
@@ -282,6 +282,8 @@ DEFINE_integer('auth_token_ttl', 3600, 'Seconds for auth tokens to linger')
DEFINE_string('state_path', os.path.join(os.path.dirname(__file__), '../'),
"Top-level directory for maintaining nova's state")
+DEFINE_string('logdir', None, 'output to a per-service log file in named '
+ 'directory')
DEFINE_string('sql_connection',
'sqlite:///$state_path/nova.sqlite',
diff --git a/nova/log.py b/nova/log.py
index b541488bd..90c40cca7 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 = FileHandler(FLAGS.logfile)
+ logpath = get_log_file_path()
+ if logpath:
+ logfile = FileHandler(logpath)
logfile.setFormatter(_formatter)
logging.root.addHandler(logfile)
diff --git a/nova/tests/test_log.py b/nova/tests/test_log.py
index 868a5ead3..c2c9d7772 100644
--- a/nova/tests/test_log.py
+++ b/nova/tests/test_log.py
@@ -46,6 +46,27 @@ class RootLoggerTestCase(test.TestCase):
self.assert_(True) # didn't raise exception
+class LogHandlerTestCase(test.TestCase):
+ def test_log_path_logdir(self):
+ self.flags(logdir='/some/path')
+ self.assertEquals(log.get_log_file_path(binary='foo-bar'),
+ '/some/path/foo-bar.log')
+
+ def test_log_path_logfile(self):
+ self.flags(logfile='/some/path/foo-bar.log')
+ self.assertEquals(log.get_log_file_path(binary='foo-bar'),
+ '/some/path/foo-bar.log')
+
+ def test_log_path_none(self):
+ self.assertTrue(log.get_log_file_path(binary='foo-bar') is None)
+
+ def test_log_path_logfile_overrides_logdir(self):
+ self.flags(logdir='/some/other/path',
+ logfile='/some/path/foo-bar.log')
+ self.assertEquals(log.get_log_file_path(binary='foo-bar'),
+ '/some/path/foo-bar.log')
+
+
class NovaFormatterTestCase(test.TestCase):
def setUp(self):
super(NovaFormatterTestCase, self).setUp()
diff --git a/nova/twistd.py b/nova/twistd.py
index 6390a8144..60ff7879a 100644
--- a/nova/twistd.py
+++ b/nova/twistd.py
@@ -43,8 +43,6 @@ else:
FLAGS = flags.FLAGS
-flags.DEFINE_string('logdir', None, 'directory to keep log files in '
- '(will be prepended to $logfile)')
class TwistdServerOptions(ServerOptions):