Implement custom logging #37

Open
opened 2026-02-14 18:42:22 +00:00 by aniram · 1 comment
Owner

Instead of printing everything to the console, use custom logging.
Make it environment dependent. Locally print to stdout, in production to a file.

Instead of printing everything to the console, use custom [logging](https://codeberg.org/marinacompsci/go-errs). Make it environment dependent. Locally print to stdout, in production to a file.
aniram added this to the 2026.1 milestone 2026-02-14 18:42:22 +00:00
aniram self-assigned this 2026-02-14 18:42:22 +00:00
Author
Owner

Use slog for structured logging.
slog.Error("failed to get authors", "proposition_id", id, "err", err)

  • Make sure each layer logs contextual information so that the error is easily traceable.
  • If formatting is necessary use %w and Errorf instead of fmt.Printf.
  • Do not use punctuation at the end, capitalized sentences or newlines.
  • Errors are supposed to be easy to wrap like this:
    query authors: failed to scan row: sql: no rows
  • Do not use the word "error" which is redundant.
  • Do not use short-lived information like filename or package name.
  • Separate context with a colon like this:
    failed to open file: %v"
  • On production log to a file with timestamps.
Use slog for structured logging. `slog.Error("failed to get authors", "proposition_id", id, "err", err)` - Make sure each layer logs contextual information so that the error is easily traceable. - If formatting is necessary use **%w** and **Errorf** instead of **fmt.Printf**. - Do not use punctuation at the end, capitalized sentences or newlines. - Errors are supposed to be easy to wrap like this: `query authors: failed to scan row: sql: no rows` - Do not use the word "error" which is redundant. - Do not use short-lived information like filename or package name. - Separate context with a colon like this: `failed to open file: %v"` - On production log to a file with timestamps.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
overdrives/chambersbr#37
No description provided.