The post has been translated automatically. Original language: Russian
Production is down, you open the logs and see thousands of "Something went wrong" lines with no context. Logs aren't written for beauty — they're written for the worst moment, when something broke and you need to find out why, fast.
Log in a structured way. JSON with level, message, user_id and request_id fields is easy to filter, while free text forces you to grep with regexes. A single request_id passed through all services lets you reconstruct one request's story in seconds.Use levels properly. ERROR means someone must react, WARN is odd but not critical, INFO is key events, DEBUG is for debugging only. If everything goes to ERROR, people stop reading alerts very quickly.Never log personal data, passwords or tokens. Mask them at the logger level instead of relying on every developer to be careful. And watch the volume: storing logs in the cloud costs money.A good test: can a new team member understand what happened to a specific request from the logs alone, without reading the code? If yes, your logs are fine. What logging rules does your team follow?
Прод упал, вы открываете логи и видите тысячи строк «Something went wrong» без контекста. Логи пишутся не для красоты, а для самого неприятного момента, когда что-то сломалось и нужно быстро понять почему.
Пишите структурно. JSON с полями level, message, user_id, request_id легко фильтровать, а свободный текст приходится грепать регулярками. Один сквозной request_id через все сервисы позволяет собрать историю одного запроса за секунды.Разделяйте уровни. ERROR — то, на что нужно реагировать, WARN — странное, но не критичное, INFO — ключевые события, DEBUG — только для отладки. Если всё пишется в ERROR, алерты быстро перестают читать.Не логируйте персональные данные, пароли и токены. Маскируйте их на уровне логгера, а не надейтесь на аккуратность каждого разработчика. И следите за объёмом: хранение логов в облаке стоит денег.Хороший тест: может ли новый человек в команде по логам понять, что произошло с конкретным запросом, не читая код? Если да — логи в порядке. Какие правила логирования приняты у вас?
Comments 0
Newest Popular