structlog

structlog: display log level in Cloudwatch

structlog: display log level in Cloudwatch Question: 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, structlog.processors.TimeStamper(fmt="iso", key="ts"), structlog.processors.JSONRenderer(), ], wrapper_class=structlog.make_filtering_bound_logger(logging.INFO), ) logger = structlog.getLogger() return logger Events in Cloudwatch now look like this: 2023-04-05T10:44:52.920+01:00 {"event": "My logging message", "level": "info", "ts": …

Total answers: 1

How to get structlog log level?

How to get structlog log level? Question: 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 like isEnabledFor from the standard library logging module. Does such a thing exist? Update: …

Total answers: 1

Async structlog configuration

Async structlog configuration Question: 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, wrapper_class=structlog.make_filtering_bound_logger(logging.INFO), processors=[ structlog.threadlocal.merge_threadlocal, structlog.processors.add_log_level, structlog.processors.format_exc_info, structlog.processors.TimeStamper(fmt="iso", utc=True), structlog.processors.JSONRenderer(serializer=orjson.dumps), ], logger_factory=structlog.BytesLoggerFactory(), ) What is the equivalent async configuration? Asked By: Henry Thornton || Source Answers: EDIT: as of structlog 22.2.0, FilteringBoundLogger had a …

Total answers: 1

Python Structlog JSON

Python Structlog JSON Question: I am currently using the python structlog JSONRenderer and hoping to change my log configuration to render the event as the 1st JSON attribute for better readability. Current Configuration: structlog.configure(processors=[structlog.processors.JSONRenderer()]) log = structlog.get_logger() Current log call site: log.msg("Response: ", content_type=content_type, content_length=resp.headers.get(‘content-length’), status_code=resp.status_code ) Current Output: {"content_type": "application/json", "content_length": null, "status_code": 200, …

Total answers: 3

How to specify levels in python logging module?

How to specify levels in python logging module? Question: I need two handlers. One for file logging and another one for stream logging in the console. I need to specify levels for each handler. Notice that my levels are going to be something like the following ones. Stream Handler –> INFO File Handler –> WARNING, …

Total answers: 3