chiark / gitweb /
before reorg debug opts again
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 01:57:20 +0000 (02:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 01:57:20 +0000 (02:57 +0100)
hippotat/__init__.py

index 0b827c9..c31bdb7 100644 (file)
@@ -55,7 +55,8 @@ org_stderr = sys.stderr
 
 log = twisted.logger.Logger()
 
-debug_set = set([x for x in DBG.iterconstants() if x <= DBG.HTTP])
+debug_set = set()
+debug_def_detail = DBG.HTTP
 
 def log_debug(dflag, msg, idof=None, d=None):
   if dflag not in debug_set: return
@@ -73,6 +74,7 @@ class LogNotBoringTwisted:
   def __call__(self, event):
     yes = twisted.logger.PredicateResult.yes
     no  = twisted.logger.PredicateResult.no
+    return yes
     try:
       if event.get('log_level') != LogLevel.info:
         return yes
@@ -397,6 +399,43 @@ def process_cfg_clients(constructor):
 #---------- startup ----------
 
 def common_startup():
+  optparser.add_option('-c', '--config', dest='configfile',
+                       default='/etc/hippotat/config')
+
+  def ds_by_detail(od,os,detail_level,op):
+    global debug_set
+    debug_set = set([df for df in DBG.iterconstants() if df <= detail_level])
+
+  def ds_one(mutator,df, od,os,value,op):
+    mutator(df)
+
+  optparser.add_option('-D', '--debug',
+                       default=debug_def_detail.name,
+                       type='choice',
+                       choices=[dl.name for dl in DBG.iterconstants()],
+                       action='callback',
+                       callback= ds_by_detail)
+
+  optparser.add_option('--no-debug',
+                       nargs=0,
+                       action='callback',
+                       callback= partial(ds_by_detail,DBG.INIT))
+
+  for df in DBG.iterconstants():
+    optparser.add_option('--debug-'+df.name,
+                         action='callback',
+                         callback= partial(ds_one, debug_set.add, df))
+    optparser.add_option('--no-debug-'+df.name,
+                         action='callback',
+                         callback= partial(ds_one, debug_set.discard, df))
+
+  (opts, args) = optparser.parse_args()
+  if len(args): optparser.error('no non-option arguments please')
+
+  re = regexp.compile('#.*')
+  cfg.read_string(re.sub('', defcfg))
+  cfg.read(opts.configfile)
+
   log_formatter = twisted.logger.formatEventAsClassicLogText
   stdout_obs = twisted.logger.FileLogObserver(sys.stdout, log_formatter)
   stderr_obs = twisted.logger.FileLogObserver(sys.stderr, log_formatter)
@@ -412,15 +451,6 @@ def common_startup():
     [ log_observer, crash_on_critical ]
     )
 
-  optparser.add_option('-c', '--config', dest='configfile',
-                       default='/etc/hippotat/config')
-  (opts, args) = optparser.parse_args()
-  if len(args): optparser.error('no non-option arguments please')
-
-  re = regexp.compile('#.*')
-  cfg.read_string(re.sub('', defcfg))
-  cfg.read(opts.configfile)
-
 def common_run():
   log_debug(DBG.INIT, 'entering reactor')
   if not _crashing: reactor.run()