Philipp Hörist pushed to branch master at gajim / gajim


Commits:
96bddaee by Philipp Hörist at 2023-05-20T21:57:25+02:00
new: Store logging records in memory

- - - - -


2 changed files:

- gajim/common/app.py
- gajim/common/logging_helpers.py


Changes:

=====================================
gajim/common/app.py
=====================================
@@ -77,6 +77,7 @@
 app = None  # type: GajimApplication
 window = None  # type: MainWindow
 commands = None  # type: ChatCommands
+logging_records: list[logging.LogRecord] = []
 
 ged = ged_module.GlobalEventsDispatcher()  # Global Events Dispatcher
 plugin_manager = cast(types.PluginManagerT, None)  # Plugins Manager


=====================================
gajim/common/logging_helpers.py
=====================================
@@ -106,6 +106,16 @@ def colorize(text: str, color: str) -> str:
     return color + text + Colors.NONE
 
 
+class CustomStreamHandler(logging.StreamHandler):  # pyright: ignore
+    def __init__(self) -> None:
+        super().__init__()  # pyright: ignore
+
+    def emit(self, record: logging.LogRecord) -> None:
+        if record.levelno >= logging.WARNING:
+            app.logging_records.append(record)
+        super().emit(record)
+
+
 class FancyFormatter(logging.Formatter):
     '''
     An eye-candy formatter with Colors
@@ -152,7 +162,7 @@ def init() -> None:
     if os.name != 'nt':
         use_color = sys.stderr.isatty()
 
-    consoleloghandler = logging.StreamHandler()
+    consoleloghandler = CustomStreamHandler()
     consoleloghandler.setFormatter(
         FancyFormatter(
             '%(asctime)s %(levelname)s %(name)-35s %(message)s',



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/96bddaeed06bc090519b2ceadb9905f2e25d0c49

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/96bddaeed06bc090519b2ceadb9905f2e25d0c49
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to