Почему ваши логи бесполезны и как это починить за полчаса

Когда продакшен падает в три часа ночи, строка ERROR Something went wrong не помогает никому. В статье разбираем, почему привычные текстовые логи быстро превращаются в шум при реальной нагрузке, как перейти на structured logging, зачем каждому запросу нужен request_id и как настроить нормальные JSON‑логи в Python и Go без лишней инфраструктуры.

https://habr.com/ru/companies/otus/articles/1034388/

#structured_logging #структурированные_логи #JSONлоги #логирование #request_id #observability #OpenTelemetry #structlog #slog #диагностика_ошибок

Почему ваши логи бесполезны и как это починить за полчаса

Три часа ночи, алерт, сервис отдаёт 500. Открываете логи и видите: 2026-05-12 03:14:22 ERROR Something went wrong 2026-05-12 03:14:22 ERROR Failed to process request 2026-05-12 03:14:23 ERROR...

Хабр

During my work hours, and with company resources, I made a simple but useful library to get logging very easily set up for FastAPI projects, using structlog and with integration with svcs.

I think that would be quite useful for many folks, so I'm going to try to Open Source it. I expect resistance and a lot of red tape, but still I want to give it a try. Wish me luck!

#FastAPI #structlog #svcs #OpenSource

Python logging: basic, better and best

Technical articles and ephemera

@judy2k Your “Stupid Things I’ve Done With Pytho” talk (https://www.youtube.com/watch?v=_MDksZlA9Bo) just saved my day and helped me solve a Python testing problem I always struggeled with: Variable data (with a known format) in test results (e.g. API responses or #structlog log records).

In this case it’s been UUID trace IDs that are unique for each request but the same for all log events of that request. I create a "SomeTraceID" class that checks if "other" is a hex-form UUID and if it's the same as before. :)

Mark Smith: Stupid Things I've Done With Python

YouTube

@hynek I know you have some snippets about using #structlog with #Flask on the docs, bu do you know of a sample repo with something like "this is a sample Flask app with everything set up to show basic request information on stdout and/or a log file using structlog"? Extra points if it has configuration for #gunicorn.

#logging #Python

@xahteiwi I think old style logging formatting is preferred as an optimisation. If you use f-string then the string is evaluated before the call but depending on the log config it might not be used (i.e. debug logging disabled). Whereas if you use the old style then it is never evaluated if it is thrown away

… but better still, use #structlog 😀

As promised, #structlog 22.3.0 is out with two bug fixes relating native loggers and string interpolation:
https://github.com/hynek/structlog/releases/tag/22.3.0 #python #logging
Release 22.3.0 · hynek/structlog

Highlights This is bug-fix release due to overly-zealous string interpolation in the native bound logger. You can now pass anything as event again (but it really should be a string) and log % signs...

GitHub

#structlog provides structured logging for #Python.

structlog implements standard timestamped, leveled message logging, but adds support for including key-value pairs within log messages. structlog sends all log messages through a set of processors, which can be used for timestamping and printing annotated tracebacks. structlog supports many output formats, including colour-coded plaintext, JSON, etc.

Website 🔗️: https://www.structlog.org/

#free #opensource #foss #fossmendations #programming

structlog documentation

structlog makes logging in Python faster, less painful, and more powerful by adding structure to your log entries.

Those who wanted to know if and how #Python #structlog supports async: yes, it will, starting with the next release. @[email protected] just merged my PR. Check out the current master and take it for a spin. http://www.structlog.org/en/latest/contextvars.html
contextvars — structlog documentation

someone with a idea how i can use something like "filter_by_level" with the ConsoleRenderer in #structlog? #python