Repository navigation
feat(logs): diagnostic log in a rotating file, readable by the admin - #25
Merged
Merged
Conversation
WATCHPILE_ART_CACHE_PATH defaulted to ./data/art, relative to the process cwd. In the Docker image that is /app/data/art, outside the /data volume, so cached artwork was silently lost on every container recreation; in packaged Electron it landed wherever the cwd was. The comment next to the variable claimed the opposite. The variable is now an optional override. Without it the cache lives in art/ next to WATCHPILE_DB_PATH, the one path both hosts declare, via besideDatabase() in lib/data-dir.ts, which the log file will reuse. READMEs: art cache is no longer "in the future", and the variable is listed in the configuration table.
The pino instance lived inside the HTTP middleware, so only route handlers could log; background work used console.* and nothing reached disk. lib/logger.ts is now the root logger, and the middleware is one of its consumers. - Two destinations: stdout (pino-pretty as an in-process stream in dev, never a transport, which breaks in packaged Electron) and logs/watchpile.log next to the database, rotated in-process at 5 MB x 3 files (WATCHPILE_LOG_PATH, _MAX_MB, _FILES overrides). - Secrets are redacted on every line at the emitter (streamWrite): by value for resolved provider credentials, OAuth tokens and the session secret, and by name for cookie/authorization/password keys and credential query params. - The per-request line no longer carries headers (the session cookie was logged on every request). Only 5xx (error), 4xx and responses over 1s (info) reach the file at the default level; the rest drops to debug. - The startup line goes through the logger instead of console.log.
Provider, art, import and update failures became typed states for the UI and left no trace, so a user reporting "search is broken" had nothing to send. Every such catch now emits through the root logger, never with the request URL (it can carry a key); the redaction in streamWrite scrubs whatever else slips through. - warn when a third party fails: provider search/detail/units refused, unreachable or not JSON; art image refused, not an image or out of range; token exchange; import sources going down (the cause used to be lost in ImportFailure); update feed and asset download; an unreadable *_FILE credential (path only). - error when the failure is ours: unexpected import, fill, refresh and enrich jobs; art warm; update download, check and install; corrupt JSON in notification params and import jobs. - debug for a job that did not start because one is already running, which is the expected path. - import logs "import finished", and a typed failure logs its kind (params stay out: they carry the username). - console.* is gone from the server outside env.ts, which runs before the logger exists. logger.spec.ts writes through the root logger and reads the file, so removing the redaction hook fails a test (checked by removing it).
GET /api/logs returns the newest lines of the file lib/logger.ts writes, and GET /api/logs/download returns every kept file as JSON Lines. Both sit behind adminMiddleware for the whole feature, like storage: the log is the instance's, not a user's. - The read walks files newest first, backwards, and stops at 1,000 lines, so a poll costs the slice and not the 15 MB. - level=all|warn|error is cumulative by severity. before= loads older lines, after= follows new ones. The cursor is the pino time, which survives rotation (line numbers do not); two lines in the same millisecond at a page boundary may repeat or skip. - Every line goes through redactLine again on the way out, so a secret registered after the line was written is still scrubbed. - The download is named by the server (watchpile-log-YYYY-MM-DD.jsonl) and never cached. - The download handler casts its response: @hono/zod-openapi types application/x-ndjson as a malformed JSON media type (never), and declaring another type would make openapi.json lie about the file. The e2e test checks status, headers and body instead.
New section "O log de diagnóstico" (root logger, rotation, redaction, the admin read/download feature and seven invariants), the lib files in the tree, and the container bullet now says stdout and file, following the brief 5.1 correction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contraparte: Digit4w/watchpile-client#36 — mergear este primeiro.
The diagnostic log was the item blocking the next pre-release: users who hit a problem had nothing to send. Most failures from providers, imports, art and updates were swallowed by catch blocks, background work logged through console.*, and nothing reached disk.
lib/logger.ts), writing to stdout and tologs/watchpile.lognext to the database, rotated in-process at 5 MB × 3 (no worker-thread transport, which breaks in packaged Electron).warnwhen a third party fails,errorwhen it is ours, never the request URL.GET /api/logsand/api/logs/download, admin only, read backwards and stop at 1,000 lines; the download is JSON Lines../data/artrelative to the cwd, outside the/datavolume in the container. It now derives from the database directory, like the log.No contract break: routes are new. Brief 5.1 was corrected by the owner (log goes to stdout and to a file in the volume).
🤖 Generated with Claude Code