Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2023-05-21 23:14:47 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-05-21 23:14:47 +0300
commit894938be73fc2db8ef4f8679da8aeb1426e680ee (patch)
treedd36519c1ac7080d3446d972ce524ebf08cc60b1
parent0a922532f6f762e60cbd640ad74587ab08fec660 (diff)
new: Logging: Add callback for CustomStreamHandler
-rw-r--r--gajim/common/logging_helpers.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/gajim/common/logging_helpers.py b/gajim/common/logging_helpers.py
index b1a0821ea..68beefb56 100644
--- a/gajim/common/logging_helpers.py
+++ b/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 app
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):
'''