Questions tagged [structlog]

Use the structlog tag for the Python package structlog, which provides structured logging for Python applications.

Structured Logging for Python

54 questions
0
votes
0 answers

structlog - How to add additional entries to event_dict

How can I add additional fields to the event_dict? The documentation mentions a pre_chain, which only seems to be available for entries which do not originate from structlog?? import logging import structlog class Logging: @staticmethod def…
Omega
  • 750
  • 1
  • 8
  • 24
0
votes
1 answer

structlog: display log level in Cloudwatch

I have set up my logger like this: import logging import structlog class Logging: @staticmethod def my_logger() -> logging.Logger: structlog.configure( processors=[ structlog.processors.add_log_level, …
Omega
  • 750
  • 1
  • 8
  • 24
0
votes
1 answer

Structlog and logging module not logging with pytest

So I have a testing folder structure (that tests a module src not shown here) like this: ├── tests │ ├── __init__.py │ ├── conftest.py │ ├── test_main.py And have the __init__.py configure my logging as shown: import structlog, logging,…
aldo
  • 125
  • 1
  • 7
0
votes
1 answer

How to set log level with structlog when not using event parameter?

The idiomatic way (I think) to create a logger in structlog that only prints up to a certain log level is to use the following: wrapper_class=structlog.make_filtering_bound_logger(logging.INFO), This works fine, but it breaks with the…
Foobar
  • 7,458
  • 16
  • 81
  • 161
0
votes
0 answers

Race condition and interleaving when Struclog logger is used within Celery tasks

I use structlog and celery in my Django application and I'm having hard time when logging tasks with structlog in the console. Indeed, events are not properly aligned when printed in the console when a Celery task is being executed. How can I fix…
Florent
  • 1,791
  • 22
  • 40
0
votes
1 answer

How to get structlog log level?

Is there a way to get the effective log level of a structlog logger? I want to do something like the following: import structlog logger = structlog.get_logger() if logger.isEnabledFor(DEBUG): some_expensive_report() I'm looking for something…
itsadok
  • 28,822
  • 30
  • 126
  • 171
0
votes
2 answers

How to get multiple independent loggers using structlog

I am looking desperately for a solution for the following problem: For a project, I need multiple independent loggers let's say one for logging readable progress for the user to console (stderr) and one for collecting some stats into a json output…
Max
  • 335
  • 1
  • 3
  • 12
0
votes
1 answer

How to ignore structlog debug/info/etc generated during pytest on doctests?

I'm trying to figure out how to ignore logging output from structlog in my doctests. It seems that pytest is capable of ignoring logs from logging, but not from structlog (at least not natively). An example follows: import logging import…
Brad Beattie
  • 579
  • 3
  • 13
0
votes
1 answer

How can I make use of structlog in python rq

In my application I am using structlog as a log system. My application also uses PythonRQ. How can I make PythonRQ to use the log system I am already using in my application so that all my application logs follows the same pattern?
Bruno Casarotti
  • 623
  • 8
  • 23
0
votes
1 answer

Mixing add_logger_name with AsyncBoundLogger raises an error

When using AsyncBoundLogger with add_logger_name, I get: AttributeError: 'BoundLoggerFilteringAtNotset' object has no attribute 'name' My Code: import logging import structlog from structlog import get_logger import asyncio loop =…
Yuval Pruss
  • 8,716
  • 15
  • 42
  • 67
0
votes
1 answer

How to add a timestamp and loglevel to each log in Python's structlog?

How to configure structlog so it automatically adds loglevel and a timestamp (and maybe other fields) by default to each log message it logs? So I do not have to add it to every message explicitly. I am displaying my messages as JSON (for further…
jkulak
  • 768
  • 1
  • 6
  • 18
0
votes
1 answer

Async structlog configuration

In the structlog documentation https://www.structlog.org/en/stable/performance.html is an example for a sync structlog configuration: import logging import structlog structlog.configure( cache_logger_on_first_use=True, …
Henry Thornton
  • 4,381
  • 9
  • 36
  • 43
0
votes
1 answer

Structlog add processor to handler

I'm struggling to set different processors for different handlers in structlog. Here is a minimal example of what I'm trying to achieve: import logging import structlog import sys from logging.handlers import TimedRotatingFileHandler def…
Alex Bailey
  • 1,260
  • 12
  • 27
0
votes
0 answers

Is there a text editor in Windows that will render color coded python structlog output (or a way to do this in Notepad++)

I have output from a python program that is being logged for the most part by structlog. When viewed in the console it is color coded but Notepad++ doesn't seem to recognize the characters that are being used to do the color coding. Is there a text…
John
  • 3,458
  • 4
  • 33
  • 54
0
votes
0 answers

memory leak in logging with structlog

We observed a memory leak in a code making the following call with a structlog logger in python: logger.debug("RANGEB obs {}/{}".format(i + 1,obs_cnt), observation=observation) Details: observation is a dictionary. the program works in a…
Manuel Yguel
  • 198
  • 1
  • 9