Skip to content

Instantly share code, notes, and snippets.

@jsumners
Last active March 19, 2018 18:32
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsumners/5921773 to your computer and use it in GitHub Desktop.
Save jsumners/5921773 to your computer and use it in GitHub Desktop.
A basic Logback configuration template for use in an IntelliJ IDEA file template. Very easily used as a generic template as well.
<configuration scan="true" scanPeriod="1 minute">
<variable
name="logPattern"
value="%-30(%d{MMM dd YYYY HH:mm:ss.SSS} [%thread]) %-5level %logger{5} [%file:%line] - %msg%n" />
<!--
The base name of the log file. For "example.log" this would
simply be "example". Or if it were "logs/example.log" then
"logs/example".
The default is set to write to Tomcat's logging directory in a file
named after the IntelliJ IDEA project.
-->
<variable
name="logname"
value="\${catalina.base}/logs/${PROJECT_NAME}" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>\${logPattern}</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--
See http://logback.qos.ch/manual/appenders.html for details.
-->
<file>\${logname}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>\${logname}-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxHistory>30</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>\${logPattern}</pattern>
</encoder>
</appender>
<root level="debug">
<!-- <appender-ref ref="STDOUT" /> -->
<appender-ref ref="FILE" />
</root>
</configuration>
@Romain-P
Copy link

${logname}.log
Where is configured logname ?

@indyaah
Copy link

indyaah commented Jul 12, 2014

see line #14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment