36-Logging in SpringBoot
36-Logging in SpringBoot
Logging
###########
-> Log messages will help us to understand the problems occuring in the application
execution
-> If any problem occurs in project execution we need to check log file of that
project to find out the root cause
###################
Logging Architecture
####################
2) Layout : It represents log msg format (what info shud present in log msg)
############
Log Levels
###########
TRACE => DEBUG => INFO => WARN => ERROR => FATAL
-> Log messages we will generate using Log Levels
-> Based On Log Level Configured, the log msgs will be printed
-> From the configured level to higher level logs will be printed
##########################################
Logging Properties in application.properties file
###########################################
logging.file.name=app.log
logging.pattern.rolling-file-name=app-%d{yyyy-MM-dd}.%i.log
logging.file.max-size=1MB
logging.file.max-history=30
logging.file.total-size-cap=10MB
##################
logback.xml
##################
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>MyApp.log</file>
<encoder>
<pattern>%d [%thread] %-5level %-50logger{40} - %msg%n</pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>MyApp-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>1MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>10MB</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="Console" />
<appender-ref ref="RollingFile" />
</root>
</configuration>
##############
Assignment
###############