Here is an incremental. I added some additional tests as well.
---
python/ovs/vlog.py | 38 +++++++++++-----------
tests/test-vlog.py | 11 ++++++
tests/vlog.at | 89 +++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 112 insertions(+), 26 deletions(-)
diff --git a/python/ovs/vlog.py b/python/ovs/vlog.py
index 46b2693..ad53781 100644
--- a/python/ovs/vlog.py
+++ b/python/ovs/vlog.py
@@ -22,7 +22,7 @@ import sys
import ovs.dirs
import ovs.util
-FACILITIES = {"console": "off", "file": "info", "syslog": "info"}
+FACILITIES = {"console": "info", "file": "info", "syslog": "info"}
LEVELS = {
"dbg": logging.DEBUG,
"info": logging.INFO,
@@ -40,7 +40,7 @@ def get_level(level_str):
class Vlog:
__inited = False
__msg_num = 0
- __mfl = {} # Module -> facilitiy -> level
+ __mfl = {} # Module -> facility -> level
def __init__(self, name):
"""Creates a new Vlog object representing a module called 'name'. The
@@ -52,7 +52,7 @@ class Vlog:
if name not in Vlog.__mfl:
Vlog.__mfl[self.name] = FACILITIES.copy()
- def __log(self, level, message, exc_info=False):
+ def __log(self, level, message, **kwargs):
if not Vlog.__inited:
return
@@ -62,30 +62,30 @@ class Vlog:
level = LEVELS.get(level.lower(), logging.DEBUG)
Vlog.__msg_num += 1
- for f in FACILITIES:
- f_level = LEVELS.get(Vlog.__mfl[self.name][f], logging.CRITICAL)
+
+ for f, f_level in Vlog.__mfl[self.name].iteritems():
+ f_level = LEVELS.get(f_level, logging.CRITICAL)
if level >= f_level:
- logging.getLogger(f).log(level, message, exc_info=exc_info)
+ logging.getLogger(f).log(level, message, **kwargs)
- def emer(self, message):
- self.__log("EMER", message)
+ def emer(self, message, **kwargs):
+ self.__log("EMER", message, **kwargs)
- def err(self, message, exc_info=False):
- """Logs 'message' at ERR log level. Set 'exc_info' to include a
- backtrace."""
- self.__log("ERR", message, exc_info)
+ def err(self, message, **kwargs):
+ self.__log("ERR", message, **kwargs)
- def warn(self, message):
- self.__log("WARN", message)
+ def warn(self, message, **kwargs):
+ self.__log("WARN", message, **kwargs)
- def info(self, message):
- self.__log("INFO", message)
+ def info(self, message, **kwargs):
+ self.__log("INFO", message, **kwargs)
- def dbg(self, message):
- self.__log("DBG", message)
+ def dbg(self, message, **kwargs):
+ self.__log("DBG", message, **kwargs)
def exception(self, message):
- """Logs 'message' at ERR log level. Includes a backtrace."""
+ """Logs 'message' at ERR log level. Includes a backtrace when in
+ exception context."""
self.err(message, exc_info=True)
@staticmethod
diff --git a/tests/test-vlog.py b/tests/test-vlog.py
index 99aec16..1c6a2df 100644
--- a/tests/test-vlog.py
+++ b/tests/test-vlog.py
@@ -32,6 +32,17 @@ def main():
m.info("information")
m.dbg("debug")
+ try:
+ fail = False # Silence pychecker warning.
+ assert fail
+ except AssertionError:
+ m.emer("emergency exception", exc_info=True)
+ m.err("error exception", exc_info=True)
+ m.warn("warn exception", exc_info=True)
+ m.info("information exception", exc_info=True)
+ m.dbg("debug exception", exc_info=True)
+ m.exception("exception")
+
if __name__ == '__main__':
main()
diff --git a/tests/vlog.at b/tests/vlog.at
index bd69ea7..dd9c50d 100644
--- a/tests/vlog.at
+++ b/tests/vlog.at
@@ -16,13 +16,88 @@ AT_CHECK([sed -e 's/.* .* ..:..:..|//' stderr_log], [0],
[dnl
2|module_0|WARN|warning
3|module_0|INFO|information
4|module_0|DBG|debug
-5|module_1|EMER|emergency
-6|module_1|ERR|error
-7|module_1|WARN|warning
-8|module_1|INFO|information
-10|module_2|EMER|emergency
-11|module_2|ERR|error
-12|module_2|WARN|warning
+5|module_0|EMER|emergency exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+6|module_0|ERR|error exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+7|module_0|WARN|warn exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+8|module_0|INFO|information exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+9|module_0|DBG|debug exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+10|module_0|ERR|exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+11|module_1|EMER|emergency
+12|module_1|ERR|error
+13|module_1|WARN|warning
+14|module_1|INFO|information
+16|module_1|EMER|emergency exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+17|module_1|ERR|error exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+18|module_1|WARN|warn exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+19|module_1|INFO|information exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+21|module_1|ERR|exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+22|module_2|EMER|emergency
+23|module_2|ERR|error
+24|module_2|WARN|warning
+27|module_2|EMER|emergency exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+28|module_2|ERR|error exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+29|module_2|WARN|warn exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
+32|module_2|ERR|exception
+Traceback (most recent call last):
+ File "../.././test-vlog.py", line 37, in main
+ assert fail
+AssertionError
])
AT_CLEANUP
--
1.7.6.1
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev