How to Use Logging in Spring Boot

Опубликовано: 02 Сентябрь 2017
на канале: raksrahul
2,642
8

How to Use Logging in Spring Boot

1. Create a maven project in eclipse using maven dependencies.

Add some classes in it

Add logger in NewService file for logging a message

2. For custom logging configuration we need application.properties in classpath (say in resources folder)

3. Add below lines in application.properties

3.1 For Console logging :

for package org.springframework.web using ERROR level
logging.level.org.springframework.web=ERROR

for package com.raksrahul.logger using DEBUG level
logging.level.com.raksrahul.logger=DEBUG

pattern for console logging
logging.pattern.console= %d{dd-MM-yyyy HH:mm:ss} - %msg%n

Run project and check the pattern is changed accordingly

3.2 For file logging :

for package org.springframework.web using ERROR level
logging.level.org.springframework.web=ERROR

for package com.raksrahul.logger using DEBUG level
logging.level.com.raksrahul.logger=DEBUG

pattern for console logging
logging.file=%d{dd-MM-yyyy HH:mm:ss} - %msg%n

Run project and check

4. Finish

Follow us on :
Facebook :   / raksrahul-100219708647780  
Instagram :   / raksrahul_ig  

Thank You :)


#raksrahul #springboot #logging #java