chiark / gitweb /
logevent_is_boringtwisted: break out as a function from LogNotBoringTwisted (nfc)
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 Apr 2017 00:45:34 +0000 (01:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 Apr 2017 00:45:34 +0000 (01:45 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
hippotatlib/__init__.py

index 4c7dd90..ab404fa 100644 (file)
@@ -100,22 +100,27 @@ def log_debug(dflag, msg, idof=None, d=None):
     msg += ' ' + d + trunc
   log.info('{dflag} {msgcore}', dflag=dflag, msgcore=msg)
 
+def logevent_is_boringtwisted(event):
+  try:
+    if event.get('log_level') != LogLevel.info:
+      return False
+    dflag = event.get('dflag')
+    if dflag is False                            : return False
+    if dflag                         in debug_set: return False
+    if dflag is None and DBG.TWISTED in debug_set: return False
+    return True
+  except Exception:
+    print(traceback.format_exc(), file=org_stderr)
+    return False
+
 @implementer(twisted.logger.ILogFilterPredicate)
 class LogNotBoringTwisted:
   def __call__(self, event):
-    yes = twisted.logger.PredicateResult.yes
-    no  = twisted.logger.PredicateResult.no
-    try:
-      if event.get('log_level') != LogLevel.info:
-        return yes
-      dflag = event.get('dflag')
-      if dflag is False                            : return yes
-      if dflag                         in debug_set: return yes
-      if dflag is None and DBG.TWISTED in debug_set: return yes
-      return no
-    except Exception:
-      print(traceback.format_exc(), file=org_stderr)
-      return yes
+    return (
+      twisted.logger.PredicateResult.no
+      if logevent_is_boringtwisted(event) else
+      twisted.logger.PredicateResult.yes
+    )
 
 #---------- default config ----------