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.
155
+
156
+
### Key naming rules
157
+
158
+
- `snake_case`, not dotted; `tmux_` prefix
159
+
- Prefer stable scalars; avoid ad-hoc objects
160
+
- Heavy keys (`tmux_stdout`, `tmux_stderr`) are DEBUG-only; consider companion `tmux_stdout_len` fields or hard truncation (e.g. `stdout[:100]`)
161
+
162
+
### Lazy formatting
163
+
164
+
`logger.debug("msg %s", val)` not f-strings. Two rationales:
165
+
- Deferred string interpolation: skipped entirely when level is filtered
166
+
- Aggregator message template grouping: `"Running %s"`is one signature grouped ×10,000; f-strings make each line unique
167
+
168
+
When computing `val` itself is expensive, guard with `if logger.isEnabledFor(logging.DEBUG)`.
169
+
170
+
### stacklevel for wrappers
171
+
172
+
Increment for each wrapper layer so `%(filename)s:%(lineno)d` and OTel `code.filepath` point to the real caller. Verify whenever call depth changes.
173
+
174
+
### LoggerAdapter for persistent context
175
+
176
+
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, config validation error |
186
+
187
+
Config discovery noise belongs in `DEBUG`; only surprising/user-actionable config issues → `WARNING`.
188
+
189
+
### Message style
190
+
191
+
- Lowercase, past tense for events: `"session created"`, `"tmux command failed"`
192
+
- No trailing punctuation
193
+
- Keep messages short; put details in `extra`, not the message string
194
+
195
+
### Exception logging
196
+
197
+
- Use `logger.exception()` only inside `except` blocks when you are **not** re-raising
198
+
- Use `logger.error(..., exc_info=True)` when you need the traceback outside an `except` block
199
+
- 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
200
+
201
+
### Testing logs
202
+
203
+
Assert on `caplog.records` attributes, not string matching on `caplog.text`:
0 commit comments