You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Treat established keys as compatibility-sensitive — downstream users may build dashboards and alerts on them. Change deliberately.
319
+
320
+
#### Key naming rules
321
+
322
+
-`snake_case`, not dotted; `tmux_` prefix
323
+
- Prefer stable scalars; avoid ad-hoc objects
324
+
- Heavy keys (`tmux_stdout`, `tmux_stderr`) are DEBUG-only; consider companion `tmux_stdout_len` fields or hard truncation (e.g. `stdout[:100]`)
325
+
326
+
#### Lazy formatting
327
+
328
+
`logger.debug("msg %s", val)` not f-strings. Two rationales:
329
+
- Deferred string interpolation: skipped entirely when level is filtered
330
+
- Aggregator message template grouping: `"Running %s"` is one signature grouped ×10,000; f-strings make each line unique
331
+
332
+
When computing `val` itself is expensive, guard with `if logger.isEnabledFor(logging.DEBUG)`.
333
+
334
+
#### stacklevel for wrappers
335
+
336
+
Increment for each wrapper layer so `%(filename)s:%(lineno)d` and OTel `code.filepath` point to the real caller. Verify whenever call depth changes.
337
+
338
+
#### LoggerAdapter for persistent context
339
+
340
+
For objects with stable identity (Session, Window, Pane), use `LoggerAdapter` to avoid repeating the same `extra` on every call. Lead with the portable pattern (override `process()` to merge); `merge_extra=True` simplifies this on Python 3.13+.
|`ERROR`| Failures that stop an operation | tmux command failed, invalid target |
350
+
351
+
#### Message style
352
+
353
+
- Lowercase, past tense for events: `"session created"`, `"tmux command failed"`
354
+
- No trailing punctuation
355
+
- Keep messages short; put details in `extra`, not the message string
356
+
357
+
#### Exception logging
358
+
359
+
- Use `logger.exception()` only inside `except` blocks when you are **not** re-raising
360
+
- Use `logger.error(..., exc_info=True)` when you need the traceback outside an `except` block
361
+
- Avoid `logger.exception()` followed by `raise` — this duplicates the traceback. Either add context via `extra` that would otherwise be lost, or let the exception propagate
362
+
363
+
#### Testing logs
364
+
365
+
Assert on `caplog.records` attributes, not string matching on `caplog.text`:
0 commit comments