Browse Source

[963] do --verbose through log (re)init

Jelte Jansen 13 years ago
parent
commit
5e70d900e4
2 changed files with 12 additions and 11 deletions
  1. 1 1
      src/bin/dbutil/Makefile.am
  2. 11 10
      src/bin/dbutil/dbutil.py.in

+ 1 - 1
src/bin/dbutil/Makefile.am

@@ -6,7 +6,7 @@ man_MANS = b10-dbutil.8
 nodist_pylogmessage_PYTHON = $(PYTHON_LOGMSGPKG_DIR)/work/dbutil_messages.py
 pylogmessagedir = $(pyexecdir)/isc/log_messages/
 
-EXTRA_DIST = $(man_MANS) b10-dbutil.xml
+EXTRA_DIST = $(man_MANS) b10-dbutil.xml dbutil_messages.mes
 
 noinst_SCRIPTS = run_dbutil.sh
 

+ 11 - 10
src/bin/dbutil/dbutil.py.in

@@ -45,6 +45,8 @@ isc.log.init("b10-dbutil")
 logger = isc.log.Logger("dbutil")
 isc.util.process.rename()
 
+TRACE_BASIC = logger.DBGLVL_TRACE_BASIC
+
 # @brief Version String
 # This is the version displayed to the user.  It comprises the module name,
 # the module version number, and the overall BIND 10 version number (set in
@@ -200,19 +202,16 @@ class Database:
     Encapsulates the SQL database, both the connection and the cursor.  The
     methods will cause a program exit on any error.
     """
-    def __init__(self, db_file, verbose = False):
+    def __init__(self, db_file):
         """
         @brief Constructor
 
         @param db_file Name of the database file
-        @param verbose If True, print all SQL statements to stdout before
-               executing them.
         """
         self.connection = None
         self.cursor = None
         self.db_file = db_file
         self.backup_file = None
-        self.verbose = verbose
 
     def open(self):
         """
@@ -244,14 +243,11 @@ class Database:
         """
         @brief Execute Statement
 
-        Executes the given statement, exiting the program on error.  If
-        verbose mode is set, the statement is printed to stdout before
-        execution.
+        Executes the given statement, exiting the program on error.
 
         @param statement SQL statement to execute
         """
-        if self.verbose:
-            logger.debug(40, DBUTIL_EXECUTE, statement)
+        logger.debug(TRACE_BASIC, DBUTIL_EXECUTE, statement)
 
         try:
             self.cursor.execute(statement)
@@ -543,7 +539,12 @@ def parse_command():
 
 if __name__ == "__main__":
     (options, args) = parse_command()
-    db = Database(args[0], options.verbose)
+
+    if options.verbose:
+        isc.log.init("b10-dbutil", "DEBUG", 99)
+        logger = isc.log.Logger("dbutil")
+
+    db = Database(args[0])
     exit_code = EXIT_SUCCESS
 
     logger.info(DBUTIL_FILE, args[0])