BIND 10 trac1074, updated. 2d84595398e0a29bd042b848e986e8aa7bc40f75 [1074] Set defined debug levels for the Python code
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Oct 17 13:24:47 UTC 2011
The branch, trac1074 has been updated
via 2d84595398e0a29bd042b848e986e8aa7bc40f75 (commit)
from 621c92d9a19379bb43e98c821183be1aa4d97c7b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2d84595398e0a29bd042b848e986e8aa7bc40f75
Author: Stephen Morris <stephen at isc.org>
Date: Mon Oct 17 14:22:41 2011 +0100
[1074] Set defined debug levels for the Python code
-----------------------------------------------------------------------
Summary of changes:
src/bin/bind10/bind10_src.py.in | 4 +-
src/bin/cmdctl/cmdctl.py.in | 11 ++------
src/bin/stats/stats.py.in | 5 +--
src/bin/stats/stats_httpd.py.in | 7 ++---
src/bin/xfrin/xfrin.py.in | 4 +-
src/bin/zonemgr/zonemgr.py.in | 8 +++---
src/lib/log/log_dbglevels.h | 7 +++++-
src/lib/python/isc/log/log.cc | 37 +++++++++++++++++++++++++++++-
src/lib/python/isc/log/tests/log_test.py | 10 ++++++++
9 files changed, 68 insertions(+), 25 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index 94747f2..166e895 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -74,8 +74,8 @@ logger = isc.log.Logger("boss")
# Pending system-wide debug level definitions, the ones we
# use here are hardcoded for now
-DBG_PROCESS = 10
-DBG_COMMANDS = 30
+DBG_PROCESS = logger.DBGLVL_TRACE_BASIC
+DBG_COMMANDS = logger.DBGLVL_TRACE_DETAIL
# Assign this process some longer name
isc.util.process.rename(sys.argv[0])
diff --git a/src/bin/cmdctl/cmdctl.py.in b/src/bin/cmdctl/cmdctl.py.in
index fcd69b8..a791aa3 100755
--- a/src/bin/cmdctl/cmdctl.py.in
+++ b/src/bin/cmdctl/cmdctl.py.in
@@ -49,17 +49,12 @@ from hashlib import sha1
from isc.util import socketserver_mixin
from isc.log_messages.cmdctl_messages import *
-# TODO: these debug-levels are hard-coded here; we are planning on
-# creating a general set of debug levels, see ticket #1074. When done,
-# we should remove these values and use the general ones in the
-# logger.debug calls
-
-# Debug level for communication with BIND10
-DBG_CMDCTL_MESSAGING = 30
-
isc.log.init("b10-cmdctl")
logger = isc.log.Logger("cmdctl")
+# Debug level for communication with BIND10
+DBG_CMDCTL_MESSAGING = logger.DBGLVL_COMMAND
+
try:
import threading
except ImportError:
diff --git a/src/bin/stats/stats.py.in b/src/bin/stats/stats.py.in
index da00818..3a7f47a 100755
--- a/src/bin/stats/stats.py.in
+++ b/src/bin/stats/stats.py.in
@@ -32,9 +32,8 @@ from isc.log_messages.stats_messages import *
isc.log.init("b10-stats")
logger = isc.log.Logger("stats")
-# Some constants for debug levels, these should be removed when we
-# have #1074
-DBG_STATS_MESSAGING = 30
+# Some constants for debug levels.
+DBG_STATS_MESSAGING = logger.DBGLVL_COMMAND
# This is for boot_time of Stats
_BASETIME = gmtime()
diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in
index 596870a..042630d 100644
--- a/src/bin/stats/stats_httpd.py.in
+++ b/src/bin/stats/stats_httpd.py.in
@@ -40,10 +40,9 @@ from isc.log_messages.stats_httpd_messages import *
isc.log.init("b10-stats-httpd")
logger = isc.log.Logger("stats-httpd")
-# Some constants for debug levels, these should be removed when we
-# have #1074
-DBG_STATHTTPD_INIT = 10
-DBG_STATHTTPD_MESSAGING = 30
+# Some constants for debug levels.
+DBG_STATHTTPD_INIT = logger.DBGLVL_START_SHUT
+DBG_STATHTTPD_MESSAGING = logger.DBGLVL_COMMAND
# If B10_FROM_SOURCE is set in the environment, we use data files
# from a directory relative to that, otherwise we use the ones
diff --git a/src/bin/xfrin/xfrin.py.in b/src/bin/xfrin/xfrin.py.in
index 1f5d9a1..91cd918 100755
--- a/src/bin/xfrin/xfrin.py.in
+++ b/src/bin/xfrin/xfrin.py.in
@@ -64,8 +64,8 @@ ZONE_MANAGER_MODULE_NAME = 'Zonemgr'
REFRESH_FROM_ZONEMGR = 'refresh_from_zonemgr'
ZONE_XFRIN_FAILED = 'zone_xfrin_failed'
-# Constants for debug levels, to be removed when we have #1074.
-DBG_XFRIN_TRACE = 3
+# Constants for debug levels.
+DBG_XFRIN_TRACE = logger.DBGLVL_TRACE_BASIC
# These two default are currently hard-coded. For config this isn't
# necessary, but we need these defaults for optional command arguments
diff --git a/src/bin/zonemgr/zonemgr.py.in b/src/bin/zonemgr/zonemgr.py.in
index 5c8d9b5..5bdb765 100755
--- a/src/bin/zonemgr/zonemgr.py.in
+++ b/src/bin/zonemgr/zonemgr.py.in
@@ -43,10 +43,10 @@ from isc.log_messages.zonemgr_messages import *
isc.log.init("b10-zonemgr")
logger = isc.log.Logger("zonemgr")
-# Constants for debug levels, to be removed when we have #1074.
-DBG_START_SHUT = 0
-DBG_ZONEMGR_COMMAND = 10
-DBG_ZONEMGR_BASIC = 40
+# Constants for debug levels.
+DBG_START_SHUT = logger.DBGLVL_START_SHUT
+DBG_ZONEMGR_COMMAND = logger.DBGLVL_COMMAND
+DBG_ZONEMGR_BASIC = logger.DBGLVL_TRACE_BASIC
isc.util.process.rename()
diff --git a/src/lib/log/log_dbglevels.h b/src/lib/log/log_dbglevels.h
index 27055d2..c366abb 100644
--- a/src/lib/log/log_dbglevels.h
+++ b/src/lib/log/log_dbglevels.h
@@ -45,6 +45,11 @@
/// In this way users can have some expection of what will be output when
/// enabling debugging. Symbols are prefixed DBGLVL so as not to clash with
/// DBG_ symbols in the various modules.
+///
+/// N.B. If the names of debug constants are changed, or if ones are added or
+/// removed, edit the file src/lib/python/isc/log/log.cc to update the log
+/// level definitions available to Python. The change does not need to be
+/// made if only the numeric values of constants are updated.
namespace {
@@ -68,7 +73,7 @@ const int DBGLVL_COMMAND = 10;
const int DBGLVL_COMMAND_DATA = 20;
// The following constants are suggested values for common operations.
-// Depending on the exact nature of the code, modules may or may not used these
+// Depending on the exact nature of the code, modules may or may not use these
// levels.
/// Trace basic operations.
diff --git a/src/lib/python/isc/log/log.cc b/src/lib/python/isc/log/log.cc
index 5bb6a94..c7112b3 100644
--- a/src/lib/python/isc/log/log.cc
+++ b/src/lib/python/isc/log/log.cc
@@ -28,7 +28,11 @@
#include <string>
#include <boost/bind.hpp>
+#include <util/python/pycppwrapper_util.h>
+#include <log/log_dbglevels.h>
+
using namespace isc::log;
+using namespace isc::util::python;
using std::string;
using boost::bind;
@@ -723,7 +727,38 @@ PyInit_log(void) {
&logger_type))) < 0) {
return (NULL);
}
- Py_INCREF(&logger_type);
+ // Add in the definitions of the standard debug levels. These can then
+ // be referred to in Python through the constants log.DBGLVL_XXX.
+ // N.B. These should be kept in sync with the constants defined in
+ // log_dbglevels.h.
+ try {
+ installClassVariable(logger_type, "DBGLVL_START_SHUT",
+ Py_BuildValue("I", DBGLVL_START_SHUT));
+ installClassVariable(logger_type, "DBGLVL_COMMAND",
+ Py_BuildValue("I", DBGLVL_COMMAND));
+ installClassVariable(logger_type, "DBGLVL_COMMAND_DATA",
+ Py_BuildValue("I", DBGLVL_COMMAND_DATA));
+ installClassVariable(logger_type, "DBGLVL_TRACE_BASIC",
+ Py_BuildValue("I", DBGLVL_TRACE_BASIC));
+ installClassVariable(logger_type, "DBGLVL_TRACE_BASIC_DATA",
+ Py_BuildValue("I", DBGLVL_TRACE_BASIC_DATA));
+ installClassVariable(logger_type, "DBGLVL_TRACE_DETAIL",
+ Py_BuildValue("I", DBGLVL_TRACE_DETAIL));
+ installClassVariable(logger_type, "DBGLVL_TRACE_DETAIL_DATA",
+ Py_BuildValue("I", DBGLVL_TRACE_DETAIL_DATA));
+ } catch (const std::exception& ex) {
+ const std::string ex_what =
+ "Unexpected failure in Log initialization: " +
+ std::string(ex.what());
+ PyErr_SetString(PyExc_SystemError, ex_what.c_str());
+ return (NULL);
+ } catch (...) {
+ PyErr_SetString(PyExc_SystemError,
+ "Unexpected failure in Log initialization");
+ return (NULL);
+ }
+
+ Py_INCREF(&logger_type);
return (mod);
}
diff --git a/src/lib/python/isc/log/tests/log_test.py b/src/lib/python/isc/log/tests/log_test.py
index 4292b6c..8deaeae 100644
--- a/src/lib/python/isc/log/tests/log_test.py
+++ b/src/lib/python/isc/log/tests/log_test.py
@@ -159,5 +159,15 @@ class Logger(unittest.TestCase):
# Bad type
self.assertRaises(TypeError, logger.debug, "42", "hello")
+ def test_dbglevel_constants(self):
+ """
+ Just check a constant to make sure it is defined and is the
+ correct value. (The constant chosen has a non-zero value to
+ ensure that the code has both define the constant and set its
+ value correctly.)
+ """
+ logger = isc.log.Logger("child")
+ self.assertEqual(logger.DBGLVL_COMMAND, 10)
+
if __name__ == '__main__':
unittest.main()
More information about the bind10-changes
mailing list