<@ULVA73B9P> how can i disable prefect debug loggi...
# ask-marvin
f
@Marvin how can i disable prefect debug logging during tests? it's horrible i can't ready anything
m
thought for 128.2 seconds
Totally get it. Here are a few easy ways to quiet Prefect logs during tests (Prefect 3.x): Quick one-liner when running pytest
Copy code
PREFECT_LOGGING_LEVEL=WARNING PREFECT_LOGGING_INTERNAL_LEVEL=WARNING PREFECT_SERVER_LOGGING_LEVEL=WARNING PREFECT_LOGGING_TO_API_ENABLED=False PREFECT_LOG_PRINTS=False pytest -q
Recommended: make it automatic for all tests (conftest.py)
Copy code
# tests/conftest.py
import pytest
from prefect.settings import (
    temporary_settings,
    PREFECT_LOGGING_LEVEL,
    PREFECT_LOGGING_INTERNAL_LEVEL,
    PREFECT_SERVER_LOGGING_LEVEL,
    PREFECT_LOGGING_TO_API_ENABLED,
)

@pytest.fixture(scope="session", autouse=True)
def quiet_prefect_logs():
    with temporary_settings({
        PREFECT_LOGGING_LEVEL: "WARNING",            # or "ERROR"/"CRITICAL"
        PREFECT_LOGGING_INTERNAL_LEVEL: "WARNING",   # internal machinery
        PREFECT_SERVER_LOGGING_LEVEL: "WARNING",     # server components, if used
        PREFECT_LOGGING_TO_API_ENABLED: False,       # don’t ship logs to API in tests
    }):
        yield
If you prefer pytest.ini (requires pytest-env)
Copy code
[pytest]
env =
  PREFECT_LOGGING_LEVEL=WARNING
  PREFECT_LOGGING_INTERNAL_LEVEL=WARNING
  PREFECT_SERVER_LOGGING_LEVEL=WARNING
  PREFECT_LOGGING_TO_API_ENABLED=False
  PREFECT_LOG_PRINTS=False
Per-test “make it silent” fixture
Copy code
@pytest.fixture
def silent_prefect(monkeypatch):
    monkeypatch.setenv("PREFECT_LOGGING_LEVEL", "CRITICAL")
    monkeypatch.setenv("PREFECT_LOGGING_INTERNAL_LEVEL", "CRITICAL")
    yield
Want me to tailor this to your setup? Are you using pytest, and do you want to suppress all logs or just Prefect’s?