SLF4J

  • Simple Logging Facade for Java
  • It is a facade library which provides abstraction for logging libraries like:
    • log4j
    • logback
    • java.util.logger

Spring Boot Logging:

  • Default log pattern:
    • Date and Time: Millisecond precision and easily sortable.
    • Log Level: ERRORWARNINFODEBUG, or TRACE.
    • Process ID.
    • --- separator to distinguish the start of actual log messages.
    • Thread name: Enclosed in square brackets (may be truncated for console output).
    • Logger name: This is usually the source class name (often abbreviated).
    • The log message.
2014-03-05 10:57:51.253  INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
 
2014-03-05 10:57:51.253  INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1358 ms
  • Spring Boot Actuator:
    • Metrics library
    • Exposes metrics via http endpoint
  • Spring Boot Admin:
    • Web Application to manage and monitor
    • Uses actuator and shows up in centralized way
  • Spring Cloud Sleuth:
    • Adds TraceID to track single request, job or action
    • logs of different services will share the same trace ID for a single request

Log Levels

  • Change log levels via application.properties:
    • package level: logging.level.com.my.package=TRACE
      • seems like if set at package level then all the classes/packages will inherit it
    • application level: logging.level.root=TRACE
  • Change logging level at runtime without restarting application:
    • with spring boot actuator endpoint: /actuator/loggers
    • using logback autoscan functionality
    • with spring cloud config library
    • with spring boot admin telemetry_log_levels|500

Logging library

  • spring-boot-starter-web > spring-boot-starter-logging
  • Default for starter library is logback
  • co.elastic.logging:logback-ecs-encoder
    • ECS: Elastic Common Schema
    • Transforms Java application logs into JSON format following the ECS

Elastic APM