When I use logback to output a log to a file ... I wondered if I could put the date in the active log file, and I found out that I could do it normally!
Simply omit the file property of the RollingFileAppender and include the date format of the unit you want to rotate in the fileNamePattern property of the TimeBasedRollingPolicy.
<appender name="APPLICATION_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--<file>${app.log.dir:-log}/application.log</file>--> <!--Omit this! !!-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${app.log.dir:-log}/application-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern><![CDATA[date:%d{yyyy-MM-dd HH:mm:ss}\tthread:%thread\tX-Track:%X{X-Track}\tlevel:%-5level\tlogger:%-48logger{48}\tmessage:%msg%n]]></pattern>
</encoder>
</appender>
"TimeBasedRollingPolicy fileNamePattern property ”Was described exactly in the explanation column!
There is nothing to summarize, but ... It's a hassle to look at the document, but if it's written properly, you can use it with confidence! !! Especially ... Documentation is important so that many people can use it as OSS. It is also good that logback has a Japanese translation !! (Thanks to the translator)
Recommended Posts