[tor-commits] [stem/master] Using log util runlevels for test runner
atagar at torproject.org
atagar at torproject.org
Sat Dec 31 21:58:55 UTC 2011
commit 94e009c8fcba1569b0e2439c626f0031d62a43b6
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Dec 31 13:51:18 2011 -0800
Using log util runlevels for test runner
Replacing hardcoded logging values with util abstraction.
---
run_tests.py | 16 +++++-----------
stem/util/log.py | 11 +++++++++++
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index 577ed2e..9bd0735 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -29,6 +29,7 @@ import test.integ.connection.connect
import test.integ.connection.protocolinfo
import stem.util.enum
+import stem.util.log as log
import stem.util.term as term
OPT = "uic:t:l:h"
@@ -115,7 +116,7 @@ if __name__ == '__main__':
run_integ_tests = False
config_path = None
test_config = stem.util.conf.get_config("test")
- logging_runlevel = logging.FATAL
+ logging_runlevel = None
# parses user input, noting any issues
try:
@@ -145,16 +146,9 @@ if __name__ == '__main__':
config_flag = TARGET_ATTR[target][0]
test_config.set(config_flag, "true")
elif opt in ("-l", "--log"):
- runlevel = arg.upper()
+ logging_runlevel = arg.upper()
- # TODO: logger has no notion of a TRACE or NOTICE runlevel
- if runlevel == "TRACE": logging_runlevel = logging.DEBUG - 5
- elif runlevel == "DEBUG": logging_runlevel = logging.DEBUG
- elif runlevel == "INFO": logging_runlevel = logging.INFO
- elif runlevel == "NOTICE": logging_runlevel = logging.INFO + 5
- elif runlevel == "WARN": logging_runlevel = logging.WARN
- elif runlevel == "ERROR": logging_runlevel = logging.ERROR
- else:
+ if not logging_runlevel in log.LOG_VALUES:
print "'%s' isn't a logging runlevel, use one of the following instead:" % arg
print " TRACE, DEBUG, INFO, NOTICE, WARN, ERROR"
sys.exit(1)
@@ -208,7 +202,7 @@ if __name__ == '__main__':
)
stem_logger = logging.getLogger("stem")
- logging_buffer = test.output.LogBuffer(logging_runlevel)
+ logging_buffer = test.output.LogBuffer(log.logging_level(logging_runlevel))
stem_logger.addHandler(logging_buffer)
stem_logger.setLevel(logging.DEBUG)
diff --git a/stem/util/log.py b/stem/util/log.py
index 7ab7895..76ebb2c 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -57,6 +57,17 @@ def get_logger():
return LOGGER
+def logging_level(runlevel):
+ """
+ Translates a runlevel into the value expected by the logging module.
+
+ Arguments:
+ runlevel (Runlevel) - runlevel to be returned, no logging if None
+ """
+
+ if runlevel: return LOG_VALUES[runlevel]
+ else: return logging.FATAL + 5
+
def log(runlevel, message):
"""
Logs a message at the given runlevel.
More information about the tor-commits
mailing list