Questions tagged [loguru]

For questions related to the logging library for Python. It can be combined with the tag [python].

Loguru is a Python logging library. It has a variety of useful features that solve the drawbacks of standard loggers.

Some Features

From https://loguru.readthedocs.io/en/stable/overview.html#features

  • Ready to use out of the box without boilerplate
  • No Handler, no Formatter, no Filter: one function to rule them all
  • Easier file logging with rotation / retention / compression
  • Exceptions catching within threads or main
  • Asynchronous, Thread-safe, Multiprocess-safe
  • Fully descriptive exceptions
  • Better datetime handling

Useful links

41 questions
13
votes
1 answer

How to use Loguru defaults + and extra information?

I'm still reaseaching about Loguru, but I can't find an easy way to do this. I want to use the default options from Loguru, I believe they are great, but I want to add information to it, I want to add the IP of a request that will be logged. If I…
Alex Turner
  • 698
  • 6
  • 16
6
votes
0 answers

How can I make Loguru log full backtrace to a file?

Please excuse if I'm doing something wrong, this is my first question here. this is my configuration: def logging_module(): """A customized Loguru logging module""" logger.add(sys.stderr, format="{time} {level} {message}",…
Kate
  • 61
  • 2
4
votes
1 answer

How to set a minimal logging level with loguru?

I would like to use a different logging level in development and production. To do so, I need early in my program to set the minimal level for logs to be triggered. The default is to output all severities: from loguru import logger as…
WoJ
  • 27,165
  • 48
  • 180
  • 345
4
votes
1 answer

How to hide logger output in Jupyter notebook but still continue the backend logging

Is there a way to hide the printed output inside Jupyter notebook (the red background section encircled in green) while still maintaining the info logging capabilities such as saving the logs into a .log file? I saw threads talking about changing…
Kenneth Leung
  • 300
  • 3
  • 8
3
votes
1 answer

Loguru: extra variable that's not always set

I would like to add an extra variable to my logs, but only if this variable exists / is set. Here's the solution I came up with: import sys from loguru import logger def formatter(record): if "remote_ip" in record.get("extra", []): …
rmweiss
  • 716
  • 1
  • 6
  • 16
2
votes
0 answers

Loguru log errors and tracebacks from uvicorn(FastAPI) to different files

I have a FastAPI app running over uvicorn. I would like to achieve the following goals: Catch uvicorn logs and process them with Loguru. (Done with InterceptHandler) Get request and response body and log in debug mode. (Done with APIRoute) Log into…
Ivan Mishalkin
  • 1,049
  • 9
  • 25
2
votes
1 answer

Loguru - how to change the logs 'filename'

With the python log library 'loguru', is there a way to change the log file name after declaring it? Thanks! from loguru import logger logger.add('dummy.log', format="{time:YYYY-MM-DD HH:mm:ss} {level} {message}") ..... # How to change log…
LeMoussel
  • 5,290
  • 12
  • 69
  • 122
2
votes
0 answers

Use loguru with alembic

I want to use Loguru as the Alembic logger handler. Do you know if and how I can do it? I only know there are some logging properties inside alembic.ini Right now I'm seeing the two loggers mixing things up in my console: 2021-10-25 23:12:59.484 |…
A.B.
  • 105
  • 1
  • 8
2
votes
1 answer

Loguru setup for use in bash script for use with several Python scripts

I have a program which runs a series of Python scripts through a Bash script. I am using loguru within the Python scripts, and I set up log files via a separate logger_setup.py. This works okay, but I need to implement the setup in each Python…
Brian
  • 115
  • 8
2
votes
1 answer

How to use loguru with standard loggers?

I would like to use Loguru to intercept loggers from other modules. Could anyone of you tell how to approach this topic, please? Example: import logging import requests from loguru import…
gbajson
  • 1,531
  • 13
  • 32
1
vote
1 answer

python loguru output to stderr and a file

I have the following line that configures my logger instance logger.add(sys.stderr, level=log_level, format="{time:YYYY-MM-DD HH:mm:ss.SSS zz} | {level: <8} | Line {line: >4} ({file}):
1
vote
0 answers

How can I get loguru's logger to work while running a Python program as a Windows service with NSSM?

I can use NSSM to run my Python program as a service just fine, and I can run my Python program just fine on its own and get loguru output to a log file as well as console window - but when I run the program as a service with NSSM only the stdout…
blownupp
  • 21
  • 2
1
vote
1 answer

Loguru error when using dask with a multiprocessing scheduler

I'm getting a RuntimeError when trying to log from a dask.delayed function using a logger handler with enqueue enabled. Here's a minimal reproducible example import sys, dask from loguru import logger logger.add(sys.stderr,…
David Hoffman
  • 2,205
  • 1
  • 16
  • 30
1
vote
2 answers

Python deactivate loguru.logger.catch() function when run in pytest

I am using loguru.logger.catch() function to log some outputs. Also, I want to deactivate this function when I test my class with pytest. I've tried to use monkey patch but didn't work. How can I handle this situation? Example Code: class…
1
vote
1 answer

How to format elapsed time (timedelta) in loguru?

Elapsed time in loguru is a datetime.timedelta object. (loguru docs) I want the time to be formatted as minutes and seconds. So, if elapsed.seconds = 123, it would become 2m3s. This would normally be attainable by…
callmeanythingyouwant
  • 1,789
  • 4
  • 15
  • 40
1
2 3