From 17d1d208652d8341bdde672b79092b481250f7de Mon Sep 17 00:00:00 2001 From: disqualifier Date: Fri, 3 Jul 2026 16:31:51 -0400 Subject: [PATCH] fix: console handler writes to stdout, not stderr console=True now binds sys.stdout explicitly (was the stdlib StreamHandler stderr default), so a supervisor capturing stdout sees console log lines. console stays off by default (file is the primary sink). docs corrected to stdout. Signed-off-by: disqualifier --- README.md | 14 +++++++++----- pyproject.toml | 2 +- src/log_setup/__init__.py | 2 +- src/log_setup/setup.py | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0aaa001..0071b5c 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,12 @@ and emit; their records flow into the handlers `log_setup` wired. ## Install ``` -log_setup @ git+ssh://git@git.rethinkstudios.io/rethink-public/log_setup.git@v0.6.2 +log_setup @ git+ssh://git@git.rethinkstudios.io/rethink-public/log_setup.git@v0.6.3 ``` No dependencies — stdlib only. -Drop the `@v0.6.2` suffix from the line above to install the latest unpinned. +Drop the `@v0.6.3` suffix from the line above to install the latest unpinned. ## Quick start @@ -29,7 +29,7 @@ from log_setup import setup_logging setup_logging(name="run", level="INFO") # daily rotation, logs/ dir, gzip (file only) log = logging.getLogger(__name__) -log.info("started") # -> ./run.log (add console=True for stderr too) +log.info("started") # -> ./run.log (add console=True for stdout too) ``` Call it once, at the app's entry point — before the rest of the app runs. Every module @@ -57,7 +57,7 @@ emits; the records land in the configured root. - **Retention** = `backup_count` (default 14) for every mode — unless tiered retention is enabled (below). For `rotate="size"`, `backup_count=0` is "keep none" (not "disable rotation") — see the `size` bullet above and the note at the bottom of this section. -- **console=True** (off by default) also logs to stderr in the same format — opt in when +- **console=True** (off by default) also logs to stdout in the same format — opt in when you want live terminal output alongside the file. The `name` you pass is normalized so it produces exactly one `.log`: `name="latest"` and @@ -174,7 +174,7 @@ setup_logging( keep_compressed=None, # tiered: next M rolled logs kept GZIPPED (opt-in) max_bytes=10_000_000, # only for rotate="size" compress=True, # gzip rolled files - console=False, # also log to stderr (off by default; opt in) + console=False, # also log to stdout (off by default; opt in) queue=False, # route through a background QueueListener (async-friendly) output="text", # "text" (human, local time) | "json" (structured, UTC) fmt=None, # override the text format string (text mode only) @@ -248,6 +248,10 @@ setup_logging(name="run", queue=True) documented (keeps that many rolled files). This does not change `"daily"`/`"on_start"`, where `backup_count=0` still means "roll, but don't prune the rolled files" (unbounded `log_dir` growth) — that is a separate, pre-existing knob, not this fix's scope. +- **`console=True` writes to stdout (v0.6.3).** the console handler now binds `sys.stdout` + explicitly instead of the stdlib `StreamHandler` default of `sys.stderr`, so a supervisor + capturing stdout sees console log lines. `console` stays off by default — the file is the + primary sink. - **`"daily"` regression fixed (v0.6.2).** v0.5.1's `rotate="size"` fix above shared its rotator with `"daily"`, so a `rotate="daily", backup_count=0` roll was incorrectly deleted at every midnight rollover instead of just landing unpruned. The rotator is now diff --git a/pyproject.toml b/pyproject.toml index 1b7f8d0..2c0cf8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "log_setup" -version = "0.6.2" +version = "0.6.3" description = "stdlib app-entry-point logging setup: live run.log, rotation, gzip, retention, consistent format" requires-python = ">=3.10" dependencies = [] diff --git a/src/log_setup/__init__.py b/src/log_setup/__init__.py index 9d74e04..42b9560 100644 --- a/src/log_setup/__init__.py +++ b/src/log_setup/__init__.py @@ -13,4 +13,4 @@ from .setup import setup_logging __all__ = ["setup_logging"] -__version__ = "0.6.2" +__version__ = "0.6.3" diff --git a/src/log_setup/setup.py b/src/log_setup/setup.py index c30a1ab..356cb89 100644 --- a/src/log_setup/setup.py +++ b/src/log_setup/setup.py @@ -278,7 +278,7 @@ def setup_logging( file_ok = False if console or not file_ok: - sh = logging.StreamHandler() + sh = logging.StreamHandler(sys.stdout) sh.setFormatter(formatter) handlers.append(sh)