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
1
vote
0 answers

How to intergrate loguru into pynput keylogger?

I am trying to add a logging feature to my keylogger using loguru but i cant seem to understand how to use loguru to update the keylogs onto the l0g.txt file that i want to create. any help would be much appriciated. from pynput.keyboard import…
lilloader
  • 11
  • 1
1
vote
2 answers

Logging UUID per API request in Python FastAPI

I have a pure python package(let's call it main) that has a few functions for managing infrastructure. Alongside, I have created a FastAPI service that can make calls to the main module to invoke functionality as per need. For logging, I'm using…
aafre
  • 23
  • 1
  • 7
1
vote
1 answer

Python - loguru disable traceback on exceptions

I'm not able to disable the traceback on exceptions even after setting LOGURU_BACKTRACE environment variable as False. I've also tried logger.configure() method like this. logger.configure(handlers=[ {"sink": sys.stderr, "backtrace":…
Dinesh Kumar
  • 483
  • 8
  • 24
1
vote
1 answer

Loguru - how to clear the logs

is there a way clear the log file before using it with the python log library 'loguru'? Thanks! from loguru import logger # clear the log before logging logger.add('output.log', format="{time:YYYY-MM-DD HH:mm:ss} {level}…
checkmate711
  • 3,301
  • 2
  • 35
  • 45
1
vote
0 answers

How to show full list of parameters bound to the query on SQLAlchemy error

right now I'm receiving an exception, while doing a bulk_save_objects, like the following one: (sqlite3.IntegrityError) UNIQUE constraint failed: foo.id [SQL: INSERT INTO foo (id, name, created_at) VALUES (?, ?, ?)] [parameters: ((1, 'A', 1111),…
A.B.
  • 105
  • 1
  • 8
1
vote
1 answer

How to write each level to a separate file so that it does not repeat in each file below the level?

logger.configure( handlers=[ dict(sink="TRACE.log", level='TRACE', enqueue=True, encoding='utf-8', diagnose=True), dict(sink="DEBUG.log", level='DEBUG', enqueue=True, encoding='utf-8', diagnose=True), …
1
vote
2 answers

Loguru: how to obfuscate data in logs

Using the python logger I can obfuscate data like this: import logging import re import sys class MySensitiveFormatter(logging.Formatter): """Formatter that removes sensitive information.""" @staticmethod def _filter(s): …
HeyMan
  • 1,529
  • 18
  • 32
1
vote
2 answers

How to access request_id defined in fastapi middleware in function

Hi i have my middleware written like this @app.middleware("http") async def request_middleware(request, call_next): end_point = request.url.path global request_id request_id = get_request_id() with…
Mahima Kulkarni
  • 127
  • 2
  • 9
0
votes
0 answers

How to suppress logging.warning from imported module (which uses loguru)

I am using a function from an imported module within an optimization loop. As a consequence the function gets called 10s or 100s of times. Since this is an optimization, sometimes the test parameters will cause a warning to be raised in the function…
Drphoton
  • 164
  • 9
0
votes
0 answers

Can I store logs into MySQL instead of log file using the loguru python library

I started using loguru to log errors and info in my FastAPI app. I want to store these logs in an existing MySQL database. I have created a middleware and managed to log the errors/info and store them in info.log file. However, I want to store these…
0
votes
1 answer

How to use loguru.catch in class

I have a template return logger like this class MyLog(object): def __init__(self, call_filename=None): self._caller_filename = call_filename def producer_log(self): …
0
votes
1 answer

Can I reset the "elapsed" reference in loguru

I am using loguru, and when I start a new test or rerun a test, I remove the old file-handler and add a new one to separate logs per-run and reflect the new start time. However, the logger's elapsed time in the stream-handler and the file-handler…
ryguycmt
  • 1
  • 2
0
votes
0 answers

Multiple handlers/levels logging in Loguru (Python module)

I am making use of loguru in a Python app. I have now come to the stage where I would like different handlers to write to stderr and file with different levels respectively. So for stderr I want it to only log "DEBUG" level logs (i.e.…
mp252
  • 453
  • 1
  • 6
  • 18
0
votes
0 answers

Log multiline errors from logs.txt to exceptions.txt

`I am currently trying to log the singleline and multiline errors only from logs.txt file to exceptions.txt file using python in VSCode. All three files, i.e., logs.txt, exceptions.txt and log_parser.py, on which I am writing the parser code are…
anything
  • 11
  • 3
0
votes
0 answers

Loguru for multiple python file

I'm new with loguru, so now have problem with logging multiple file. I have used the original python logging, and only need define the logger one time only, then it can catch the logging on multiple file, but the loguru does not. Specifically my…
ShanN
  • 831
  • 1
  • 9
  • 20