Files
messageLogger/src/diag.py
T
lyuksovannyyandClaude Opus 5.5 9b2f26a845
Publish plugin / publish (push) Successful in 4s
Message Logger: show logged edits and deletions from telegram-panel [no bump]
Keeps deleted messages (75% opacity, red icon-pack trash icon), restores
logged messages deleted while away, reports deletions, and shows edit
history as a mock chat (Edit history in the message menu, Open topic).
Message links and history open as any signed-in account with access.
Per-master API tokens; chat state synced per checked range with an hour's
validity, cached in SQLite with a configurable lifetime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 23:55:23 +02:00

55 lines
1.4 KiB
Python

"""Diagnostics mirrored to a file, since this device's logcat surfaces neither
Chaquopy stdout nor android_utils.log output.
The file lives under `get_files_dir()` (app external storage), so it is
readable over adb:
adb shell cat "/sdcard/Android/data/com.exteragram.messenger/files/exteraGram/exteraGram Files/message_logger/diag.log"
"""
import os
import time
import traceback
_MAX_BYTES = 256 * 1024
_path = None
def _file():
global _path
if _path is None:
try:
from file_utils import get_files_dir
directory = os.path.join(get_files_dir(), "message_logger")
os.makedirs(directory, exist_ok=True)
_path = os.path.join(directory, "diag.log")
except Exception:
_path = ""
return _path
def log(message):
line = time.strftime("%H:%M:%S ") + str(message)
try:
from android_utils import log as android_log
android_log("[message_logger] " + line)
except Exception:
pass
path = _file()
if not path:
return
try:
mode = "a"
if os.path.exists(path) and os.path.getsize(path) > _MAX_BYTES:
mode = "w"
with open(path, mode, encoding="utf-8") as handle:
handle.write(line + "\n")
except Exception:
pass
def error(where, exc=None):
detail = traceback.format_exc() if exc is not None else ""
log(f"ERROR {where}: {exc!r}\n{detail}")