Auto-enable `tractor` logging when runtime active
Check for active `tractor` runtime via `.current_actor()` and use its `.loglevel` to auto-enable `tractor`'s internal console logging when `with_tractor_log` is not explicitly set. Deats, - add `tll` (tractor log level) var to capture level - check `with_tractor_log is not False` first - fallback to `maybe_actor.loglevel` if runtime exists - only call `tractor.log.get_console_log()` if `tll` set - add TODO comment about "log-spec" style config support (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codefix_tractor_logging
parent
2012543744
commit
f96d3c407e
19
piker/log.py
19
piker/log.py
|
|
@ -67,6 +67,9 @@ def get_console_log(
|
|||
name: str|None = None,
|
||||
pkg_name: str|None = None,
|
||||
with_tractor_log: bool = False,
|
||||
# ?TODO, support a "log-spec" style `str|dict[str, str]` which
|
||||
# dictates both the sublogger-key and a level?
|
||||
# -> see similar idea in `modden`'s usage.
|
||||
**tractor_log_kwargs,
|
||||
|
||||
) -> logging.Logger:
|
||||
|
|
@ -85,9 +88,21 @@ def get_console_log(
|
|||
pkg_name in name
|
||||
):
|
||||
name: str = name.lstrip(f'{_proj_name}.')
|
||||
if with_tractor_log:
|
||||
|
||||
tll: str|None = None
|
||||
if (
|
||||
with_tractor_log is not False
|
||||
):
|
||||
tll = level
|
||||
|
||||
elif maybe_actor := tractor.current_actor(
|
||||
err_on_no_runtime=False,
|
||||
):
|
||||
tll = maybe_actor.loglevel
|
||||
|
||||
if tll:
|
||||
t_log = tractor.log.get_console_log(
|
||||
level=level,
|
||||
level=tll,
|
||||
name='tractor', # <- XXX, force root tractor log!
|
||||
**tractor_log_kwargs,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue