1
0
Fork 0
ynh-apps_tools/appslib/logging_sender.py

37 lines
913 B
Python
Raw Normal View History

#!/usr/bin/env python3
import subprocess
from shutil import which
import logging
import logging.handlers
2024-02-08 22:18:59 +01:00
class LogSenderHandler(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
self.is_logging = False
def emit(self, record):
if which("sendxmpppy") is None:
2024-02-08 22:18:59 +01:00
logging.warning("Could not send error via xmpp.")
return
msg = f"[Applist builder error] {record.msg}"
subprocess.call(["sendxmpppy", msg], stdout=subprocess.DEVNULL)
@classmethod
def add(cls, level=logging.ERROR):
if not logging.getLogger().handlers:
logging.basicConfig()
# create handler
handler = cls()
handler.setLevel(level)
# add the handler
logging.getLogger().handlers.append(handler)
def enable():
2024-02-08 22:18:59 +01:00
"""Enables the LogSenderHandler"""
LogSenderHandler.add(logging.ERROR)