|
| static QByteArray | sanitize (const QByteArray &input) |
| | QetLogger::sanitize Escapes newlines, carriage returns and other control characters. Much of what QET logs is externally controlled (file paths, element names, font strings read out of a .qet file); left unescaped, a crafted string containing '
' can forge additional log lines. Operates on already-UTF-8-encoded bytes: this is safe because UTF-8 continuation bytes are always >= 0x80, so any byte < 0x20 found here is a genuine ASCII control character, never part of a multi-byte sequence.
|
| static QByteArray | truncateMessage (const QByteArray &input, int max_bytes) |
| | QetLogger::truncateMessage Caps a single message at max_bytes, appending a marker stating how many bytes were dropped, so one pathological caller (e.g. dumping an entire XML document to qDebug()) can't consume an unbounded amount of the ring's or file's byte budget.
|
| static QByteArray | formatLine (QtMsgType type, const QMessageLogContext &context, const QByteArray &sanitized_msg) |
The QetLogger class Rework of QET's diagnostic logging (discussion #644, steps 1-3):
- Step 1: one file handle held open for the session under a mutex instead of opening/closing per message; the log path (including the date-stamped filename) is resolved exactly once, at init(), instead of being recomputed on every message – a session that crosses midnight now stays in one file; retention now uses lastModified() instead of lastRead(); stderr and file output both use UTF-8 explicitly (previously stderr used the local 8-bit codec and the file's encoding silently differed between Qt5 and Qt6).
- Step 2: the previously-unbounded daily file is now size-capped and rotated (kMaxFileBytes per file, kRotationKeep old files kept beyond the current one); each message is truncated to kMaxMessageBytes and control characters are escaped before being written, so one pathological caller can't blow the size budget or forge log lines; the log file is refused if it already exists as a symlink and is created owner-read/write only.
- Step 3: every formatted line is also appended to an in-memory LogRing (see logring.h) – always on, fixed capacity, allocation- free on the hot path.
- Step 4: installCrashHandler() wires the ring up to CrashHandler (see crashhandler.h), so a SIGSEGV/SIGABRT/SIGBUS/SIGFPE/SIGILL (or, on Windows, an unhandled structured exception) flushes the ring to a fixed crash-dump file before the process dies.
- Step 5: hasPendingCrashDump()/pendingCrashDumpContents()/ clearPendingCrashDump() let startup code (see QETApp::checkBackupFiles()) notice and offer an unretrieved crash dump from the previous run; buildDiagnosticsReport() is the equivalent for a manual "save a
report right now" action on the current, still-running session. Both go through redact() before ever reaching the user, since both are destined for a public bug tracker.
Deliberately NOT included: log categories, a full session header beyond what the crash dump/report already carry, repeat collapsing, rate limiting. Those are listed in discussion #644 under "best
practices worth building in", not part of the numbered steps.
Escape hatch: if QET_LOG_DISABLE=1 is set in the environment at init() time, this class does nothing beyond a minimal, independent stderr passthrough – no ring, no file, no rotation – so a problem in this rework can be worked around without a rebuild.
| QByteArray QetLogger::redact |
( |
const QByteArray & | input | ) |
|
|
static |
QetLogger::redact Replaces the user's home directory with "~" wherever it appears. Applied before a crash dump or a diagnostics report is ever shown to the user: both are destined to be attached to a public bug tracker, and an absolute path under the home directory leaks the account name (discussion #644's privacy section: "/home/laurent/... leaks a
username"). This is the one redaction implemented here; the discussion's fancier "optionally redact project filenames too" is not attempted – reliably telling a project path apart from arbitrary log text is a much fuzzier problem than a literal prefix match against a known directory.
Replaces occurrences of the user's home directory with "~". Applied to both the crash dump and buildDiagnosticsReport() before they are ever shown to the user, since both are destined for a public bug tracker.
| QByteArray QetLogger::sanitize |
( |
const QByteArray & | input | ) |
|
|
staticprivate |
QetLogger::sanitize Escapes newlines, carriage returns and other control characters. Much of what QET logs is externally controlled (file paths, element names, font strings read out of a .qet file); left unescaped, a crafted string containing '
' can forge additional log lines. Operates on already-UTF-8-encoded bytes: this is safe because UTF-8 continuation bytes are always >= 0x80, so any byte < 0x20 found here is a genuine ASCII control character, never part of a multi-byte sequence.