Dependency

  • Lombok

Log Format

Default output from Spring Boot:

2019-03-05 10:57:51.112  INFO 45469 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.52
2019-03-05 10:57:51.253  INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-03-05 10:57:51.253  INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1358 ms
2019-03-05 10:57:51.698  INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2019-03-05 10:57:51.702  INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

Notes:

  1. Date and Time: Millisecond precision and easily sortable.
  2. Log Level: ERROR, WARN, INFO, DEBUG, or TRACE.
  3. Process ID.
  4. A --- separator to distinguish the start of actual log messages.
  5. Thread name: Enclosed in square brackets (may be truncated for console output).
  6. Logger name: This is usually the source class name (often abbreviated).
  7. The log message.

Logging Properties

Example Logging properties for change Logging level (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, atau OFF):

logging.level.root=info

# spesific in some package (only Warn level will show from the package)
logging.level.nama.package.nya=warn 

# e.g. loging.level.com.helmigandi=warn

File Output

logging.file.name=application.log // save in project directory

# or

logging.file.name=/var/log/application.log

# or

# automatic save in /tmp/spring.log
logging.file.path=/tmp/ 

File Rolling

  • logging.logback.rollingpolicy.max-file-size: Maximum size log file (default 10 MB).
  • logging.logback.rollingpolicy.max-history: Maximum number of files created after reaching max files.
# about 10 files and the total size is 100 KB

logging.logback.rollingpolicy.max-file-size=10KB
logging.logback.rollingpolicy.max-history=10

Log Group

  • Configure the same logging level only for multiple packages.
# logging.group.nama=package1,package2, and so forth
logging.group.warn-log=com.helmigandi.service,com.helmigandi.controller

# only warning levels will be displayed in packages `com.helmigandi.service`, and `com.helmigandi.controller`
logging.level.warn-log=warn

Bibliography