Configuring logging of the Scai web server

The Scai logging framework is logback. A standard configuration can be found:

DeploymentFile
on-premiselogback-prod.xml, by default in /opt/scai/conf
AWS/opt/scai/data/logback.xml

Such a file can look like this:

<configuration>  <appender name="FILE" class="ch.qos.logback.core.FileAppender">    <file>/opt/scai/logs/application.log</file>    <encoder>      <pattern>%-5level|%d|%c{0}| - %msg%n</pattern>    </encoder>  </appender>    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">        <encoder>            <pattern>%-5level|%d|%c{0}| - %msg%n</pattern>        </encoder>    </appender>  <appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">    <appender-ref ref="FILE" />  </appender>  <appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">    <appender-ref ref="STDOUT" />  </appender>  <root level="DEBUG">    <appender-ref ref="ASYNCFILE" />    <appender-ref ref="ASYNCSTDOUT" />  </root>  <logger name="play" level="INFO"/>  <logger name="play.application" level="DEBUG"/>  <logger name="com.google.inject" level="ERROR"/>  <logger name="com.scai.notebook.helpers.ExceptionLogger" level="TRACE"/> <!-- Will log all exceptions received -->  <logger name="com.scai.process.controllers" level="TRACE"/>  <logger name="com.scai.process.models.ProcessModel" level="TRACE"/>  <logger name="Auth" level="ERROR"/>  <logger name="org.jdbcdslog.ConnectionLogger" level="OFF"  /> <!-- Won' log connections -->  <logger name="org.jdbcdslog.StatementLogger"  level="INFO" /> <!-- Will log all statements -->  <logger name="org.jdbcdslog.ResultSetLogger"  level="OFF"  /> <!-- Won' log result sets --></configuration>

This logging configuration specifies that the Scai web server should log its messages in two different places:

  • on the standard output
  • in a file application.log located at /opt/scai/logs

Only the log messages that respect the restrictions in this file will be logged to both locations. Each line in the logs is generated bya class and classes are organized in a tree-like structure, with the root being the root of the class hierarchy.

The lines starting with <logger define fine grained restrictions. For example, <logger name="play" level="INFO"> defines that all classes thatbelong to the play package will log only messages with the INFO level or above. If, in addition, <logger name="play.application" level="DEBUG">is specified, then all classes in the play package will log only INFO level messages and above except classes that are in the play.applicationpackage. These ones will log at DEBUG level and above.

The logging framework contains different levels of logging, from least verbose to most verbose in order:

  • OFF: disables all logging
  • ERROR: error messages
  • WARN: warning messages
  • INFO: informational messages
  • DEBUG: messages suitable to debugging a specific problem
  • TRACE: messages tracking each step the Scai web server is taking. Logging with this level might fill the log files rather quickly.

These levels can be specified at a global level by modifying the <root level="LEVEL"> tag, or per particular class/collection of classes. The more specificlevel definitions will have the higher priority.

Example

Example: suppose some lines in the logs will be generated like the following:

DEBUG|2018-02-28 10:54:03,590|AnormHelpers| - #PROF Q: select * from [scai].[metadata_temp_tables] = 0.000771s

Here, we can see that this line was generated at the DEBUG level, at 2018-02-28 10:54:03,590 by the class with the name AnormHelpers and what remainsis a custom message. This line was generated following the pattern defined in the configuration file: %-5level|%d|%c{0}| - %msg%n.

Suppose we would like to not have this message appear in the logs anymore. We could:

  1. set <root level="INFO">, but this has the disadvantage that it will remove any message from the logs that has the DEBUG level. This is not what we may want.
  2. set a more restrictive tag

In order to set a more restrictive tag, we need to know which package the AnormHelpers class belongs to. For this, we need to change the logging pattern so thatit includes the whole name of the class. We change the pattern from %-5level|%d|%c{0}| - %msg%n to %-5level|%d|%c| - %msg%n. After restarting the server,we can now see that the full name is com.scai.notebook.models.AnormHelpers. Now we can set either:

  • <logger name="com.scai.notebook.models.AnormHelpers" level="INFO"/>, or
  • <logger name="com.scai.notebook.models" level="INFO"/>, or just
  • <logger name="com.scai" level="INFO"/>

in order to achieve our goal.

List of most common logging classes

  • org.jdbcdslog.StatementLogger: INFO level and below will enable logging of every SQL statement executed by Scai
  • com.scai.notebook.helpers.ExceptionLogger: TRACE level will enable logging of exceptions occurred during execution of SQL statements
  • com.scai.notebook.models.AnormHelpers: messages related to executing SQL server and profiling of SQL execution times