Commits

jordilin committed 4807cf9

minor refactor

  • Participants
  • Parent commits a70c54c

Comments (0)

Files changed (2)

log4client/src/log4tailer/notifications.py

         self.counter = 0
         self.triggered = False
 
-    def notify(self, message, log):
-        msg_level = message.messageLevel.upper()
-        if not message.isATarget() and msg_level not in self.Pullers:
-            if self.triggered:
-                self.counter += 1
-                if self.counter > self.MAX_COUNT :
-                    self.tail_context.change_tail_method(
-                            strategy.TailMultiLineMethod())
-                    self.tail_context.throttle_time = 0
-                    self.counter = 0
-                    self.triggered = False
-            return
+    def restore_context(self):
+        if self.triggered:
+            self.counter += 1
+            if self.counter > self.MAX_COUNT :
+                self.tail_context.change_tail_method(
+                        strategy.TailMultiLineMethod())
+                self.tail_context.throttle_time = 0
+                self.counter = 0
+                self.triggered = False
+
+    def change_context(self):
         self.counter = 0
         self.triggered = True
         self.tail_context.change_tail_method(strategy.TailOneLineMethod())
         self.tail_context.throttle_time = self.THROTTLE_TIME
 
+    def notify(self, message, log):
+        msg_level = message.messageLevel.upper()
+        if message.isATarget() or msg_level in self.Pullers:
+            self.change_context()
+        else:
+            self.restore_context()
+
 
 class PrintShot(Print):
     """Prints log trace and takes

log4client/tests/test_printnotification.py

         slow_down.notify(WarningMessage(), DummyLog())
         self.assertTrue(isinstance(context.tail_method, TailOneLineMethod))
 
-    def test_notify_back_to_default_after_10_tails(self):
+    def test_notify_back_to_default_after_1_tails(self):
         throttle_time = 0
         context = TailContext(throttle_time)
         self.assertTrue(isinstance(context.tail_method, TailMultiLineMethod))
         slow_down.notify(NormalMessage(), DummyLog())
         slow_down.notify(NormalMessage(), DummyLog())
         self.assertTrue(isinstance(context.tail_method, TailMultiLineMethod))
+
+    def test_notify_no_change_context(self):
+        throttle_time = 0
+        context = TailContext(throttle_time)
+        self.assertTrue(isinstance(context.tail_method, TailMultiLineMethod))
+        slow_down = notifications.SlowDown(context)
+        slow_down.notify(NormalMessage(), DummyLog())
+        self.assertFalse(slow_down.triggered)