4 months ago
Hello,
I have a python runtime application running with Loguru for handling logs and all my INFO logs are being marked as ERROR in the deploy logs. What can I change so they get identified as INFO logs instead?
Code example:
from loguru import logger
if name == "__main__":
logger.add("logs/app.log", rotation="10 MB", retention="10 days")
logger.info("Hello world")
My dockerfile
FROM python:3.13-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
COPY requirements.txt .
RUN pip install --upgrade pip && pip install -r requirements.txt
COPY . .
CMD ["python", "run.py"]
Pinned Solution
4 months ago
You should add this to your code:
logger.add(sys.stdout, filter=lambda record: record["level"].no < 40, level="INFO")
This configuration ensures that only log messages below level 40 (i.e., below ERROR) are sent to stdout.
Levels 40 and above (ERROR, CRITICAL) will be excluded from this handler.
It's useful when deploying on platforms where separating output streams helps keep logs clean and avoids mixing error logs with standard logs.
Source: https://github.com/Delgan/loguru/issues/422#issuecomment-813519575
2 Replies
4 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
4 months ago
You should add this to your code:
logger.add(sys.stdout, filter=lambda record: record["level"].no < 40, level="INFO")
This configuration ensures that only log messages below level 40 (i.e., below ERROR) are sent to stdout.
Levels 40 and above (ERROR, CRITICAL) will be excluded from this handler.
It's useful when deploying on platforms where separating output streams helps keep logs clean and avoids mixing error logs with standard logs.
Source: https://github.com/Delgan/loguru/issues/422#issuecomment-813519575
Status changed to Solved brody • 4 months ago