[elbe-devel] [PATCH 10/12] log: save maximum loglevel in LoggingQueue.max_level and export accessor

Torben Hohn torben.hohn at linutronix.de
Thu Sep 26 15:33:30 CEST 2019


when an error is logged, this is not fatal to the elbe build.

Add a max_level field to the LoggingQueue and save the maximum there.
Add log.read_maxlevel() to read that value out.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/log.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/elbepack/log.py b/elbepack/log.py
index 9f3196031..156ca3923 100644
--- a/elbepack/log.py
+++ b/elbepack/log.py
@@ -24,6 +24,11 @@ logging_methods = []
 class LoggingQueue(collections.deque):
     def __init__(self):
         super(LoggingQueue, self).__init__(maxlen=1024)
+        self.max_level = logging.NOTSET
+
+    def note_level(self, level):
+        if level > self.max_level:
+            self.max_level = level
 
 
 class QHandler(logging.Handler):
@@ -38,6 +43,7 @@ class QHandler(logging.Handler):
 
     def emit(self, record):
         self.Q.append(self.format(record))
+        self.Q.note_level(record.levelno)
 
     @classmethod
     def pop(cls, target):
@@ -46,11 +52,22 @@ class QHandler(logging.Handler):
         except (IndexError, KeyError):
             return ''
 
+    @classmethod
+    def max_level(cls, target):
+        try:
+            return cls.queues[target].max_level
+        except (IndexError, KeyError):
+            return logging.NOTSET
+
 
 def read_loggingQ(proj):
     return QHandler.pop(proj)
 
 
+def read_maxlevel(proj):
+    return QHandler.max_level(proj)
+
+
 class ThreadFilter(logging.Filter):
 
     def __init__(self, allowed, *args, **kwargs):
-- 
2.20.1




More information about the elbe-devel mailing list