Logging in HCL OneDB Explore

This topic provides a brief tutorial on logging in HCL OneDB™ Explore.

The HCL OneDB Explore server and agent use the log4j2 library for logging. By default, the HCL OneDB Explore server and agent will log messages at INFO level to an onedb-explore-server.log file and an onedb-explore-agent.log file respectively.

You can customize the logging behavior by providing a server.log4j.xml file in the current directory or classpath when starting the OneDB Explore server or a agent.log4j.xml file in the current directory or classpath when starting the OneDB Explore agent. Use these log4j2 configuration files to change the logging level (ERROR, WARN, INFO, or DEBUG), change the log file location, or enable rolling window logging. For more information, see the log4j2 documentation.

Sample log4j2 configuration files are provided in example-server.log4j.xml and example-agent.log4j.xml.

ConsoleAppender

The ConsoleAppender writes its output to either System.out or System.err with System.out being the default target. A Layout must be provided to format the LogEvent.

RollingFile Appender

The RollingFileAppender is an OutputStreamAppender that writes to the file named in the fileName parameter and rolls the file over according to the TriggeringPolicy and the RolloverPolicy.

The CompositeTriggeringPolicy takes multiple triggering policies and returns true if any of the configured policies return true. The CompositeTriggeringPolicy is configured simply by combining other policies in a Policies element.

SizeBased Triggering Policy

Once the file reaches the specified size, the SizeBasedTriggeringPolicy causes a rollover. The size can be specified in bytes, with the suffix KB, MB or GB, for example 20MB. When combined with a time based triggering policy, the file pattern must contain a %i otherwise the target file will be overwritten on every rollover as the SizeBased Triggering Policy will not cause the timestamp value in the file name to change. When used without a time based triggering policy, the SizeBased Triggering Policy will cause the timestamp value to change.

TimeBased Triggering Policy

The TimeBasedTriggeringPolicy causes a rollover once the date/time pattern no longer applies to the active file. This policy accepts an interval attribute which indicates how frequently the rollover should occur based on the time pattern and a modulate boolean attribute.

Default Rollover Policy

The default rollover takes both date/time pattern and an integer specified in filePattern Attribute in RollingFileAppender. If the pattern contains an integer, it will be incremented on every rollover. If the date/time pattern is present, it will be replaced with current date and time values. If the file pattern ends with ".gz", ".zip", ".bz2", ".deflate", ".pack200", or ".xz", the resulting archive will be compressed using the compression scheme that matches the suffix.

This example shows a rollover strategy that will keep up to 20 files before removing them.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
   <Appenders>
      <RollingFile name="RollingFile" fileName="logs/app.log" filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
         <PatternLayout>
            <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
         </PatternLayout>
         <Policies>
            <TimeBasedTriggeringPolicy />
            <SizeBasedTriggeringPolicy size="250 MB" />
         </Policies>
         <DefaultRolloverStrategy max="20" />
      </RollingFile>
   </Appenders>
   <Loggers>
      <Root level="error">
         <AppenderRef ref="RollingFile" />
      </Root>
   </Loggers>
</Configuration>