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
2
votes
2 answers

setting up trees of renderers in structlog

How would I configure structlog such that all messages including above info would go to stdout using a KeyValueRenderer while all logging would also go to a file using a JSONRenderer? note: I only want to use structlog, no standard library stuff
Chris Withers
  • 10,837
  • 4
  • 33
  • 51
1
vote
1 answer

Structlog different ways to log: msg versus info and debug

I see different ways to use Structlog and I was wondering what the exact difference is. Let's say I want to log something using Structlog, you could for example use: logger.msg("My log message") But there are other ways to log, like info, debug (as…
Guido
  • 6,182
  • 1
  • 29
  • 50
1
vote
1 answer

Structlog use in modules and for console

Two related questions about using the production-ready configuration - https://www.structlog.org/en/stable/performance.html: i. How to use this configuration across different modules (files)? ii. How to ensure .info logger output is displayed on…
Henry Thornton
  • 4,381
  • 9
  • 36
  • 43
1
vote
1 answer

How to log stacktrace in json format python

Im using structlog for logging and want the exception/stacktrace to be printed in json format. Currently its not formatted and in string format which is not very readable { "message": "Error info with an exc", "timestamp":…
user17090811
  • 143
  • 2
  • 10
1
vote
1 answer

pytest does not find tests when structlog is configured

I have a python project where I use pytest for my unit testing. Normally if I run the following command from my test folder: pytest --collect-only I will get all my tests: ... 40 tests collected ... Now let's say I define a new class…
Greg7000
  • 297
  • 3
  • 15
1
vote
1 answer

changing log level filtering using structlog

im using structlog, and im configuring it to use the filter_by_level processor: structlog.configure( processors = [ structlog.stdlib.add_log_level, structlog.stdlib.add_log_level_number, …
1
vote
1 answer

Structlog: How to test what is emitted by which handler

I use structlog in my project and I would like to (unit) test which handler has emitted which message. Is there a canonical way to do this? I noticed pytest-structlog but could not find any such functionality there. Or is there maybe something I…
Haydnspass
  • 67
  • 6
1
vote
2 answers

Wrap "py.warnings" logger with structlog to add processors

I have a custom logger including processors, handlers etc. . I would like to wrap the "py.warnings" logger which I understand is used by the warnings so that my processors are 'injected'. However, running the following code does not change anything…
Haydnspass
  • 67
  • 6
1
vote
2 answers

Getting last log value with Structlog and passing it as a variable to a function

Currently I am trying to implement a function call that sends failed messages from a converter to a DLQ topic with Kafka. As part of the DLQ message I want to include the exception error that we also log. the code: except…
Harvey
  • 668
  • 2
  • 7
  • 15
1
vote
1 answer

Can't figure out how to turn off colored logging when written to disk with structlog

I'm just starting to learn how to use structlog and I'm having a difficult time trying to figure out how to turn off colored logging when it writes to files. Essentially what I did was take my old code that I had used with the standard logging…
Mike
  • 504
  • 7
  • 23
1
vote
1 answer

Use structlog to log changing object attributes

I recently discovered structlog and want to use it to log the object attributes of some objects. I'm unsure about two things: 1) What's the best practice for object-oriented logging? I want to bind some object attributes, eg, ID, that are always…
stefanbschneider
  • 5,460
  • 8
  • 50
  • 88
1
vote
2 answers

Logging in Python project using structlog and it logs third party libraries which needs to be removed

I am using structlog library to log for my Python project. I see some third party library logs which I do not want. How do I remove those logs?
RSY
  • 51
  • 5
1
vote
2 answers

Is there a way in Python structlog to change the key from 'logger' to ''namespace"?

I am using structlog - http://www.structlog.org/en/stable/ in my Python Project. I have one if the processors in the configuration to be stdlib.add_logger_name This adds the key in the event_dict to be logger. But, I want to change the key string…
RSY
  • 51
  • 5
1
vote
3 answers

Reduce boilerplate for logging

I read the docs of structlog: Configuration The goal is to reduce your per-file logging boilerplate to: from structlog import get_logger logger = get_logger() Is there a way to even reduce this to one import line (without ;)?
guettli
  • 25,042
  • 81
  • 346
  • 663
0
votes
0 answers

Is there a way of passing an argument directly to the wrapped logger (say, via kwargs)?

I'm using wrap_logger to wrap a logger which makes use of e.g. funcName. When using log = wrap_logger(logger), funcName shows up as _proxy_to_logger instead of whatever function is making the log—so I'd like to ensure that stacklevel=2 gets passed…
AmagicalFishy
  • 1,249
  • 1
  • 12
  • 36