Logging
Log Aggregation
Grafana Loki
Loki - HTTP API Reference
Loki HTTP API (opens in a new tab)
Loki - Health check
GET :3100/ready# e.g.
❯ http :3100/ready
HTTP/1.1 200 OK
Content-Length: 6
Content-Type: text/plain; charset=utf-8
Date: Fri, 03 Oct 2025 15:03:01 GMT
X-Content-Type-Options: nosniff
readyLoki - Send log data to Loki
Send log data to Loki (opens in a new tab)
Tooling - LogQL simulator
Spring Boot - integration
Pusing logs directly over HTTP to Loki using a Logback Appender loki-logback-appender.
- Add dependencies (Gradle Kotlin DSL)
implementation("com.github.loki4j:loki-logback-appender:2.0.0")- Configure Logback
<!-- logback-spring.xml -->
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<contextName>playground.spring-data</contextName>
<springProperty name="logging.loki.url" source="logging.loki.url"/>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>${logging.loki.url}</url>
</http>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="LOKI"/>
</root>
</configuration>- Configure Spring Boot application properties
logging.loki.url=http://${LOKI_HOST:localhost}:${LOKI_PORT:3100}/loki/api/v1/pushVictoriaLogs
VictoriaLogs datasource for Grafana
- Grafana Plugin - VictoriaLogs datasource (opens in a new tab)
- VictoriaMetrics Playground - k8s Logs Demo (opens in a new tab)
Log Format
logfmt
JSON Lines
Logging API
SLF4J
SLF4J - Multiple bindings were found on the class path (opens in a new tab)
SLF4J - Modules
jul-to-slf4j
slf4j-jdk-platform-logging
Logback
Logback - Turn on debug flag
# System Property
-Dlogback.debug=true
# This will print out internal status messages of logbackLogback - MDC
- Store contextual information on a per-thread basis, such as a transaction ID.
Logback - Config
-
By default,
additivity="true"which sends logging output to any appender attached higher in the hierarchy.Try setting
additivity="false"if duplicate logging output happens. -
Logback - Chapter 3 Configuration - Overriding the default cumulative behaviour (opens in a new tab)
Logback - Appenders
-
immediateFlushBy default, each log event is immediately flushed to the underlying output stream. This default approach is safer in the sense that logging events are not lost in case your application exits without properly closing appenders.
Try using
immediateFlush = trueif logging events are lost in logs.
Logback - RollingFileAppender
-
RollingPolicy
- How to roll over log files
-
TriggeringPolicy
- When to roll over log files
Logback - PatternLayout
-
Colored output
Jansilibrary is required forANSIcolor code interpretation on Windows.POSIXsystems supportANSIcolor code interpretation natively.
-
Logback - Chapter 6 Layouts - PatternLayout (opens in a new tab)
Reference for conversion patterns
Logback - Spring Boot - integration
-
Spring Boot by default uses programmatic configuration to improve startup time, with Spring config for customizations.
Logback default config class:
org.springframework.boot.logging.logback.DefaultLogbackConfiguration
Logback - Spring Boot - default config
org.springframework.boot.logging.logback