web123456

SpringBoot Integration Logging Framework

<configuration> <!--The main output logs in this article are console logs, system logs, sql logs, and exception logs.--> <!-- %mOutput information,%pLog level,%t thread name,%d Date,%Full name of class c,,,, --> <!--consoles--> <appender name="console" class=""> <encoder> <pattern>%d %p (%file:%line\)- %m%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <!--System info level log--> <!--<File> The log directory, which is not automatically created--> <!--<rollingPolicy>logging policy, resume one log file per day, or log file for the day with more than64MB time--> <!--encoder Log encoding and output format--> <appender name="fileLog" class=""> <File>log/file/fileLog.log</File> <rollingPolicy class=""> <fileNamePattern>log/file/fileLog.log.%d.%i</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class=""> <!-- or whenever the file size reaches 64 MB --> <maxFileSize>64 MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern> %d %p (%file:%line\)- %m%n </pattern> <charset>UTF-8</charset> <!-- Set the character set here--> </encoder> </appender> <!--sql log--> <appender name="sqlFile" class=""> <File>log/sql/sqlFile.log</File> <rollingPolicy class=""> <fileNamePattern>log/sql/sqlFile.log.%d.%i</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class=""> <!-- or whenever the file size reaches 64 MB --> <maxFileSize>64 MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!--Formats the logging events. Responsible for two things, converting log messages into byte arrays and writing the byte arrays to the output stream.--> <encoder> <!--Used to set the input format of the log--> <pattern> %d %p (%file:%line\)- %m%n </pattern> <charset>UTF-8</charset> <!-- Set the character set here--> </encoder> </appender> <!--Exception log--> <appender name="errorFile" class=""> <File>log/error/errorFile.log</File> <rollingPolicy class=""> <fileNamePattern>log/error/errorFile.%d.log.%i</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class=""> <!-- or whenever the file size reaches 64 MB --> <maxFileSize>64 MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!--Formats the logging events. Responsible for two things, converting log messages into byte arrays and writing the byte arrays to the output stream.--> <encoder> <!--Used to set the input format of the log--> <pattern> %d %p (%file:%line\)- %m%n </pattern> <charset>UTF-8</charset> <!-- Set the character set here--> </encoder> <!-- The logs are all here. Filter out errors. The logs are filtered for errors using thetry {}catch (Exception e){} If the exception cannot be written to the log, it can be written in thecatchUse the logger in the.error()method manually writes to the log --> <filter class=""> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- Log output level--> <!--All\DEBUG\INFO\WARN\ERROR\FATAL\OFF--> <!--Print info level logs in console, fileLog, errorFile output respectively. Exception log in the above by the filter to filter out the ERROR log printing --> <root level="INFO"> <appender-ref ref="fileLog" /> <appender-ref ref="console" /> <appender-ref ref="errorFile" /> </root> <!--Print sql to sqlFile file logs--> <logger name="" level="DEBUG" additivity="false"> <appender-ref ref="console" /> <appender-ref ref="sqlFile" /> </logger> </configuration>