chiark / gitweb /
init debug
[hippotat.git] / hippotat / __init__.py
index 1e8a23f11e7b717f0a17534835b65f1debe4eb33..b6a84d9546903868edf9d6830f4b8df2de92b08c 100644 (file)
@@ -32,23 +32,27 @@ import re as regexp
 import hippotat.slip as slip
 
 class DBG(twisted.python.constants.Names):
+  INIT = NamedConstant()
   ROUTE = NamedConstant()
   DROP = NamedConstant()
   FLOW = NamedConstant()
   HTTP = NamedConstant()
-  HTTP_CTRL = NamedConstant()
-  INIT = NamedConstant()
+  TWISTED = NamedConstant()
   QUEUE = NamedConstant()
+  HTTP_CTRL = NamedConstant()
   QUEUE_CTRL = NamedConstant()
   HTTP_FULL = NamedConstant()
-  SLIP_FULL = NamedConstant()
   CTRL_DUMP = NamedConstant()
+  SLIP_FULL = NamedConstant()
 
 _hex_codec = codecs.getencoder('hex_codec')
 
 log = twisted.logger.Logger()
 
+debug_set = set([x for x in DBG.iterconstants() if x <= DBG.HTTP])
+
 def log_debug(dflag, msg, idof=None, d=None):
+  if dflag not in debug_set: return
   #print('---------------->',repr((dflag, msg, idof, d)), file=sys.stderr)
   if idof is not None:
     msg = '[%#x] %s' % (id(idof), msg)
@@ -369,7 +373,12 @@ def process_cfg_clients(constructor):
 
 def common_startup():
   log_formatter = twisted.logger.formatEventAsClassicLogText
-  log_observer = twisted.logger.FileLogObserver(sys.stderr, log_formatter)
+  stdout_obs = twisted.logger.FileLogObserver(sys.stdout, log_formatter)
+  stderr_obs = twisted.logger.FileLogObserver(sys.stderr, log_formatter)
+  pred = twisted.logger.LogLevelFilterPredicate(LogLevel.error)
+  log_observer = twisted.logger.FilteringLogObserver(
+    stderr_obs, [pred], stdout_obs
+  )
   twisted.logger.globalLogBeginner.beginLoggingTo(
     [ log_observer, crash_on_critical ]
     )