summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Wells <iawells@cisco.com>2018-06-06 14:12:27 +0100
committerChris Luke <chris_luke@comcast.com>2018-06-06 19:10:54 +0000
commitd0e812f2d49cf241f80ac020b6e697cd408f216b (patch)
tree12732648e0e84619e5cb5511d5f8b2112fdf8160
parent9f781d84b0943b03af2a9fd0b7c4cef721d1d4c6 (diff)
Alter logging semantics for VPP PAPI object
Logging previously used a string name for the log level and changed the system-wide log level based on this string name. It now uses a logging-module provided constant for the log level and changes its own logger's level based on the name, and only if the level is provided. This allows the logging to be more compatible with Pythonic usage, where an external source may be used to dictate logging levels across the system on a per module basis and should not be overridden. Change-Id: Icf6896ff61a29b12c11d04374767322cdb330323 Signed-off-by: Ian Wells <iawells@cisco.com>
-rw-r--r--src/vpp-api/python/vpp_papi.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/vpp-api/python/vpp_papi.py b/src/vpp-api/python/vpp_papi.py
index 7305ef38763..ece0e4ee52d 100644
--- a/src/vpp-api/python/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi.py
@@ -116,7 +116,7 @@ class VPP():
these messages in a background thread.
"""
def __init__(self, apifiles=None, testmode=False, async_thread=True,
- logger=logging.getLogger('vpp_papi'), loglevel='debug',
+ logger=None, loglevel=None,
read_timeout=0):
"""Create a VPP API object.
@@ -125,11 +125,20 @@ class VPP():
dynamically created reflecting these APIs. If not
provided this will load the API files from VPP's
default install location.
+
+ logger, if supplied, is the logging logger object to log to.
+ loglevel, if supplied, is the log level this logger is set
+ to report at (from the loglevels in the logging module).
"""
global vpp_object
vpp_object = self
+
+ if logger is None:
+ logger = logging.getLogger(__name__)
+ if loglevel is not None:
+ logger.setLevel(loglevel)
+
self.logger = logger
- logging.basicConfig(level=getattr(logging, loglevel.upper()))
self.messages = {}
self.id_names = []