Robert Bastian
08/13/2025, 6:57 PMMarvin
08/13/2025, 6:57 PMMarvin
08/13/2025, 7:02 PMlogging.basicConfig(force=True)
, logging.getLogger().handlers.clear()
, or a library that fiddles with global logging can remove Prefect’s handlers mid-run.
- Fix: remove/guard your logging reconfig, or let Prefect own logging. If you must customize, do it once at process start and avoid force=True
.
- disable_run_logger()
used (directly or via a helper): this disables the run logger for the current context.
- Fix: remove it and use from prefect.logging import get_run_logger
within tasks.
- Child processes/threads: logs from a subprocess won’t have Prefect’s run context and may not show up unless you explicitly route them (capture stdout/stderr, or use the run logger in the child process).
- “Prints stopped being logged” vs “logs stopped”: if only prints are missing, confirm your print-to-log configuration in Prefect 3.x (see logging settings).
Quick diagnostics you can drop into the suspect task
import logging
from prefect.logging import get_run_logger
import prefect
def inspect_logging_state():
rlog = get_run_logger()
<http://rlog.info|rlog.info>(f"Prefect {prefect.__version__} - inspecting logging state")
<http://rlog.info|rlog.info>(f"Root handlers: {logging.getLogger().handlers}")
<http://rlog.info|rlog.info>(f\"Prefect logger handlers: {logging.getLogger('prefect').handlers}\")
- If handlers are empty at this point, something is reconfiguring or shutting down logging in your code or a dependency.
Helpful docs
- Prefect 3 logging customization and settings: Logging customization (Prefect 3)
To help pinpoint your case, can you share:
- How you’re running (worker type: Kubernetes/Docker/Process; Prefect Cloud/Server; versions of Prefect and any integrations like prefect-kubernetes)
- Whether you see the “Error occurred while streaming logs” message in worker logs around the time logging stops
- Whether the “quiet” task spawns a subprocess or runs a long external command
- Any logging configuration you apply in your flow/tasks (basicConfig, loguru, etc.)
With that, I can suggest a precise fix instead of just waving a wrench at it.Robert Bastian
08/13/2025, 7:05 PMMarvin
08/13/2025, 7:11 PMMarvin
08/13/2025, 7:13 PMfrom prefect import task
from prefect.logging import get_run_logger
import time
@task
def long_task():
log = get_run_logger()
for _ in range(12): # ~12 minutes
time.sleep(60)
<http://log.info|log.info>("still working...")
# actual work...
- Subprocess output is not streamed: If the task runs a CLI, make sure you stream stdout line-by-line and log it:
import subprocess
from prefect import task
from prefect.logging import get_run_logger
@task
def run_cmd(cmd):
log = get_run_logger()
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1)
for line in p.stdout:
<http://log.info|log.info>(line.rstrip())
return p.wait()
- Logging reconfigured mid-run: Calls like logging.basicConfig(force=True)
, logging.getLogger().handlers.clear()
, or libraries that tamper with logging can drop Prefect’s handlers.
- Drop this into the suspect task to verify:
import logging
from prefect.logging import get_run_logger
@task
def inspect_logging():
log = get_run_logger()
<http://log.info|log.info>(f"root handlers: {logging.getLogger().handlers}")
<http://log.info|log.info>(f"prefect handlers: {logging.getLogger('prefect').handlers}")
If handlers vanish before/after the task, something is shutting them down.
- disable_run_logger()
was called (directly or indirectly). Remove it.
Helpful docs
- Logging customization (Prefect 3): Docs
If you can share:
- Exact versions: Prefect core and prefect-kubernetes
- Whether UI logs stop at the same moment as worker stdout
- A snippet of what that “quiet” task does (subprocess? long CPU-bound loop? any logging setup?)
- Any worker pod log lines around the time logging stops
…then I can point at the precise fix rather than mumbling about the void.