Skip to main content
Version: Any 26

Logging (logback)

Any uses logback to manage the application logs.

Configuration file​

The logback.xml file is located in:

$TOMCAT_HOME/webapps/any/WEB-INF/classes/logback.xml

You can externalize it in any.configurationPath.

Location of the log files​

Parameter:

<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./../../logs/any.log</file>

The path can be relative or absolute.

Examples:

  • Relative: ./../../logs/any.log
  • Absolute: /var/log/tomcat/any.log

Archiving policy​

By default, a new file is created each day and the old ones are archived (zip) for 5 days.

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./../../logs/any-%d{yyyy-MM-dd}.log.zip</fileNamePattern>
<maxHistory>5</maxHistory>
</rollingPolicy>

Parameters:

  • fileNamePattern: format of the name with date
  • maxHistory: number of days to keep

Log levels​

By default: INFO

<root>
<level value="INFO"/>
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>

Available levels:

LevelContent
ERRORJava exceptions only
WARNWarnings + ERROR
INFOUser actions + WARN
DEBUGMethod calls + INFO
TRACEDetailed results + DEBUG

Pattern format​

By default:

%date %-5level %8.8(%X{threadIndex}) %-42.42(%X{requestURI}) %-10.10(%X{user}) %-32logger{0} - %message%n

Components:

  • %date: date/time
  • %-5level: level (ERROR, WARN, INFO, etc.)
  • %X{threadIndex}: ID of the thread
  • %X{requestURI}: URL of the called REST service
  • %X{user}: user who called
  • %logger{0}: Java class that logs
  • %message: log message

Additional appenders​

You can add appenders to send the logs by email, for instance:

<appender name="mail" class="ch.qos.logback.classic.net.SMTPAppender">
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.OnErrorEvaluator"/>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>

<smtpHost>smtp.server.com</smtpHost>
<smtpPort>587</smtpPort>
<SSL>true</SSL>
<username>account@mail.com</username>
<password>password</password>

<from>any-errors@company.com</from>
<to>support@company.com</to>
<subject>[ERROR] %logger{20} - %m</subject>

<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-5level %8.8(%X{threadIndex}) %-42.42(%X{requestURI}) %-10.10(%X{user}) %-32logger{0} - %message%n</pattern>
</layout>
</appender>

For more details: Logback documentation