Philipp Hörist pushed to branch master at gajim / gajim
Commits: 894938be by Philipp Hörist at 2023-05-21T22:14:47+02:00 new: Logging: Add callback for CustomStreamHandler - - - - - 1 changed file: - gajim/common/logging_helpers.py Changes: ===================================== gajim/common/logging_helpers.py ===================================== @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see <http://www.gnu.org/licenses/>. +from typing import Callable from typing import Optional import logging @@ -26,6 +27,8 @@ from gajim.common import configpaths from gajim.common.i18n import _ +LogCallback = Callable[[logging.LogRecord], None] + def parseLogLevel(arg: str) -> int: ''' @@ -109,12 +112,21 @@ def colorize(text: str, color: str) -> str: class CustomStreamHandler(logging.StreamHandler): # pyright: ignore def __init__(self) -> None: super().__init__() # pyright: ignore + self._callback: LogCallback | None = None def emit(self, record: logging.LogRecord) -> None: if record.levelno >= logging.WARNING: app.logging_records.append(record) + if self._callback is not None: + self._callback(record) + super().emit(record) + def set_callback(self, + func: LogCallback | None + ) -> None: + self._callback = func + class FancyFormatter(logging.Formatter): ''' View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/894938be73fc2db8ef4f8679da8aeb1426e680ee -- View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/894938be73fc2db8ef4f8679da8aeb1426e680ee 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
