fix(logging): emit the log level in JSON logs - #15
Merged
Conversation
The JSON encoder was configured with a <level/> provider, but logstash-logback-encoder has no such provider — LoggingEventJsonProviders exposes addLogLevel and addLogLevelValue, not addLevel. Logback silently dropped the element and only hinted at it in its startup status output: |-WARN in ch.qos.logback.core.model.processor.ImplicitModelHandler - Ignoring unknown property [level] in [net.logstash.logback.composite.loggingevent.LoggingEventJsonProviders] So every log line went out without a level, while app/environment/instance survived because they come from the separate, valid <pattern> provider. That made the breakage easy to miss: nothing failed, the logs were still valid JSON, and only one field was quietly absent. Verified with ./gradlew bootRun on the dev profile. Before: 0 of 38 lines had a level field and the warning above was present. After: all 46 lines carry level, spanning DEBUG/INFO/WARN, and the warning is gone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема
В JSON-логах приложения нет уровня логирования. Замечено наставником при разборе проекта «Доска объявлений (Observability)» — там шаг про Promtail/Loki опирается на то, что логи уже в JSON и пригодны для фильтрации по уровню.
Симптом выглядел странно: поля
app,environmentиinstanceиз того же самого appender'а пишутся, аlevel— нет.Причина
В
logback-spring.xmlпровайдер назывался<level/>. Вlogstash-logback-encoderтакого провайдера нет:LoggingEventJsonProvidersпредоставляетaddLogLevelиaddLogLevelValue, но неaddLevel. Logback молча выбрасывал неизвестный элемент, оставив лишь строку в своём startup-статусе:app/environment/instanceвыживали потому, что приходят из отдельного, валидного провайдера<pattern>.Поэтому баг и было легко не заметить: сборка не падала, логи оставались валидным JSON, просто одного поля тихо не было.
Фикс
<level/>→<logLevel/>, одна строка.Проверка
./gradlew bootRun, профильdev(h2, без внешних зависимостей):levelПосле фикса в логах присутствуют уровни
DEBUG,INFOиWARN— то есть поле живое, а не константа. Пример строки:{"@timestamp":"2026-08-04T17:50:49.842989867Z","app":"bulletins","environment":"dev", "instance":"linux-mint","logger_name":"io.hexlet.project_devops_deploy.DemoApplication", "thread_name":"restartedMain","level":"INFO", "message":"Started DemoApplication in 11.896 seconds (process running for 12.731)"}Тикет: FEEDBACK-353.