MCPcopy Create free account
hub / github.com/chatmail/core / FFIEventLogger

Class FFIEventLogger

python/src/deltachat/events.py:42–82  ·  view source on GitHub ↗

If you register an instance of this logger with an Account you'll get all ffi-events printed.

Source from the content-addressed store, hash-verified

40
41
42class FFIEventLogger:
43 """If you register an instance of this logger with an Account
44 you'll get all ffi-events printed.
45 """
46
47 # to prevent garbled logging
48 _loglock = threading.RLock()
49
50 def __init__(self, account, logid=None, init_time=None) -> None:
51 self.account = account
52 self.logid = logid or self.account.get_config("displayname")
53 if init_time is None:
54 init_time = time.time()
55 self.init_time = init_time
56
57 @account_hookimpl
58 def ac_process_ffi_event(self, ffi_event: FFIEvent) -> None:
59 self.account.log(str(ffi_event))
60
61 @account_hookimpl
62 def ac_log_line(self, message):
63 t = threading.current_thread()
64 tname = getattr(t, "name", t)
65 if tname == "MainThread":
66 tname = "MAIN"
67 elapsed = time.time() - self.init_time
68 locname = tname
69 if self.logid:
70 locname += "-" + self.logid
71 s = f"{elapsed:2.2f} [{locname}] {message}"
72
73 if os.name == "posix":
74 WARN = "\033[93m"
75 ERROR = "\033[91m"
76 ENDC = "\033[0m"
77 if message.startswith("DC_EVENT_WARNING"):
78 s = WARN + s + ENDC
79 if message.startswith("DC_EVENT_ERROR"):
80 s = ERROR + s + ENDC
81 with self._loglock:
82 print(s, flush=True)
83
84
85class FFIEventTracker:

Callers 2

init_loggingMethod · 0.85
run_accountMethod · 0.85

Calls

no outgoing calls

Tested by 1

init_loggingMethod · 0.68