Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
894938be
by Philipp Hörist at 2023-05-21T22:14:47+02:00
1 changed file:
Changes:
| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 | # You should have received a copy of the GNU General Public License
|
| 15 | 15 | # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 16 | 16 | |
| 17 | +from typing import Callable
|
|
| 17 | 18 | from typing import Optional
|
| 18 | 19 | |
| 19 | 20 | import logging
|
| ... | ... | @@ -26,6 +27,8 @@ |
| 26 | 27 | from gajim.common import configpaths
|
| 27 | 28 | from gajim.common.i18n import _
|
| 28 | 29 | |
| 30 | +LogCallback = Callable[[logging.LogRecord], None]
|
|
| 31 | + |
|
| 29 | 32 | |
| 30 | 33 | def parseLogLevel(arg: str) -> int:
|
| 31 | 34 | '''
|
| ... | ... | @@ -109,12 +112,21 @@ def colorize(text: str, color: str) -> str: |
| 109 | 112 | class CustomStreamHandler(logging.StreamHandler): # pyright: ignore
|
| 110 | 113 | def __init__(self) -> None:
|
| 111 | 114 | super().__init__() # pyright: ignore
|
| 115 | + self._callback: LogCallback | None = None
|
|
| 112 | 116 | |
| 113 | 117 | def emit(self, record: logging.LogRecord) -> None:
|
| 114 | 118 | if record.levelno >= logging.WARNING:
|
| 115 | 119 | app.logging_records.append(record)
|
| 120 | + if self._callback is not None:
|
|
| 121 | + self._callback(record)
|
|
| 122 | + |
|
| 116 | 123 | super().emit(record)
|
| 117 | 124 | |
| 125 | + def set_callback(self,
|
|
| 126 | + func: LogCallback | None
|
|
| 127 | + ) -> None:
|
|
| 128 | + self._callback = func
|
|
| 129 | + |
|
| 118 | 130 | |
| 119 | 131 | class FancyFormatter(logging.Formatter):
|
| 120 | 132 | '''
|