Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
96bddaee
by Philipp Hörist at 2023-05-20T21:57:25+02:00
2 changed files:
Changes:
| ... | ... | @@ -77,6 +77,7 @@ |
| 77 | 77 | app = None # type: GajimApplication
|
| 78 | 78 | window = None # type: MainWindow
|
| 79 | 79 | commands = None # type: ChatCommands
|
| 80 | +logging_records: list[logging.LogRecord] = []
|
|
| 80 | 81 | |
| 81 | 82 | ged = ged_module.GlobalEventsDispatcher() # Global Events Dispatcher
|
| 82 | 83 | plugin_manager = cast(types.PluginManagerT, None) # Plugins Manager
|
| ... | ... | @@ -106,6 +106,16 @@ def colorize(text: str, color: str) -> str: |
| 106 | 106 | return color + text + Colors.NONE
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | +class CustomStreamHandler(logging.StreamHandler): # pyright: ignore
|
|
| 110 | + def __init__(self) -> None:
|
|
| 111 | + super().__init__() # pyright: ignore
|
|
| 112 | + |
|
| 113 | + def emit(self, record: logging.LogRecord) -> None:
|
|
| 114 | + if record.levelno >= logging.WARNING:
|
|
| 115 | + app.logging_records.append(record)
|
|
| 116 | + super().emit(record)
|
|
| 117 | + |
|
| 118 | + |
|
| 109 | 119 | class FancyFormatter(logging.Formatter):
|
| 110 | 120 | '''
|
| 111 | 121 | An eye-candy formatter with Colors
|
| ... | ... | @@ -152,7 +162,7 @@ def init() -> None: |
| 152 | 162 | if os.name != 'nt':
|
| 153 | 163 | use_color = sys.stderr.isatty()
|
| 154 | 164 | |
| 155 | - consoleloghandler = logging.StreamHandler()
|
|
| 165 | + consoleloghandler = CustomStreamHandler()
|
|
| 156 | 166 | consoleloghandler.setFormatter(
|
| 157 | 167 | FancyFormatter(
|
| 158 | 168 | '%(asctime)s %(levelname)s %(name)-35s %(message)s',
|