XML Config - epam/gflog GitHub Wiki

XML Config

This page describes xml config.

Structure

The top element is config. It contains three types of optional elements:

  1. appender - describes how/where to write/stream/filter messages.
  2. logger - describes a level filter and what appenders to use.
  3. service - describes how to route messages from loggers to appenders.
<config>
    <appender name="console" factory="com.epam.deltix.gflog.core.appender.ConsoleAppenderFactory"/>
   
    <logger>
        <appender-ref ref="console"/>
    </logger>

    <service/>
</config>

Appender

Attribute Default Required Description
name Y Appender name.
factory Y Factory class to create an instance.
level TRACE N Level filter. Values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.

Usually contains the specific attributes and elements depending on the type. For instance:

<appender name="file" factory="com.epam.deltix.gflog.core.appender.FileAppenderFactory" file="log.txt">
    <layout template="%d %p '%c' [%t] %m%n"/>
</appender>

Logger

Attribute Default Description
name "" Log name.
level INFO Level filter. Values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.

Contains appender-ref element to select which appenders to use:

<logger level="DEBUG" name="my-logger">
    <appender-ref ref="console"/>
    <appender-ref ref="file"/>
</logger>

Service

Attribute Default Description
factory com.epam.deltix.gflog.core.service.AsyncLogServiceFactory Factory class to create an instance.

Contains the specific attributes and elements depending on the type. For instance:

<service entryEncoding="UTF-8">
    <idle-strategy maxSpins="5"/>
</service>

Appenders

Console

Writes messages to the console.

Attribute Default Required Description
name Y Appender name.
factory Y com.epam.deltix.gflog.core.appender.ConsoleAppenderFactory
level TRACE N Level filter. Values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.
bufferCapacity 2M N Buffer capacity. Supports suffixes: k/kb/K/KB/m/mb/M/MB.
flushCapacity bufferCapacity* N Max size to flush at once. Window's default is 16K. Supports suffixes: k/kb/K/KB/m/mb/M/MB.
wrap false N Uses a wrapper over the system stream. Otherwise tries to use the underlying FileChannel directly.
stderr false N Uses the standard error stream instead of the standard output stream.

Contains an optional layout element:

<appender name="console" factory="com.epam.deltix.gflog.core.appender.ConsoleAppenderFactory" bufferCapacity="1M" stderr="true">
    <layout template="%d (${user.name}) %p '%c' [%t]: %m%n"/>
</appender>

File

Writes messages to a file.

Attribute Default Required Description
name Y Appender name.
factory Y com.epam.deltix.gflog.core.appender.FileAppenderFactory
file Y File path to write to.
level TRACE N Level filter. Values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.
append true N Appends to the existing file or truncates it.
bufferCapacity 2M N Buffer capacity. Supports suffixes: k/kb/K/KB/m/mb/M/MB.
flushCapacity bufferCapacity N Max size to flush at once. Supports suffixes: k/kb/K/KB/m/mb/M/MB.

Contains an optional layout element:

<appender name="console" factory="com.epam.deltix.gflog.core.appender.FileAppenderFactory" file="my-log.log">
    <layout template="%d (${user.name}) %p '%c' [%t]: %m%n"/>
</appender>

Daily Rolling File

Writes messages to files. Starts a new file on daily basis or if the current file exceeds the configured size. Deletes old files if configured.

The file name pattern: ${directory}/${name}${suffix}${index}${extension}.

For file "my-dir/my-file.log" and fileSuffixTemplate "-yyyy-MM-dd" it would be: "my-dir/my-file-2021-02-15.0.log".

Attribute Default Required Description
name Y Appender name.
factory Y com.epam.deltix.gflog.core.appender.DailyRollingFileAppenderFactory
file Y File path to write to. Pattern: ${directory}/${name}${suffix}${index}${extension}.
fileSuffixTemplate -yyyy-MM-dd N File suffix template. Pattern: ${directory}/${name}${suffix}${index}${extension}.
level TRACE N Level filter. Values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.
append true N Appends to the existing file or truncates it.
maxFiles 0 N Preserves only N last files and removes old ones. Enabled if positive.
maxFileSize 0 N Triggers file rolling if the current file exceeds the specified size. Enabled if positive. Supports suffixes: k/kb/K/KB/m/mb/M/MB.
zoneId system N Which time zone to use when rolling files.
bufferCapacity 2M N Buffer capacity. Supports suffixes: k/kb/K/KB/m/mb/M/MB.
flushCapacity bufferCapacity N Max size to flush at once. Supports suffixes: k/kb/K/KB/m/mb/M/MB.

Contains an optional layout element:

<appender name="file" factory="com.epam.deltix.gflog.core.appender.DailyRollingFileAppenderFactory"
              file="gflog-sample/build/tmp/file.log" fileSuffixTemplate="_yyyy-MM-dd-HH-mm-ss"
              maxFiles="2" maxFileSize="1KB"/>

Tcp

Sends messages through a TCP connection to a remote side.

Attribute Default Required Description
name Y Appender name.
factory Y com.epam.deltix.gflog.core.appender.TcpAppenderFactory
host Y Remote host.
port Y Remote port.
level TRACE N Level filter. Values: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.
bufferCapacity 2M N Buffer capacity. Supports suffixes: k/kb/K/KB/m/mb/M/MB.
flushCapacity bufferCapacity N Max size to flush at once. Supports suffixes: k/kb/K/KB/m/mb/M/MB.
connectTimeout 5s N Connect timeout on startup. Application threads can be blocked.
reconnectInitialPeriod 5s N Reconnect period is reset to this value on a successful connection attempt.
reconnectMaxPeriod 10m N Reconnect period is doubled gradually up to this value on each consequent failed connection attempt.
sendTimeout 5s N Disconnects after this period if a message can't be sent to socket because of backpressure.
socketSendBufferCapacity 2M N Socket send buffer capacity. 0 is OS's default.
socketReceiveBufferCapacity 0 N Socket receive buffer capacity. 0 is OS's default.
socketTcpNoDelay false N Socket tcp no delay. true is to enable Nagle's algorithm.

Contains an optional layout element:

<appender name="gelf" factory="com.epam.deltix.gflog.core.appender.TcpAppenderFactory"
          host="localhost" port="5555" connectTimeout="1s" reconnectInitialPeriod="1ms" sendTimeout="1s">

    <layout factory="com.epam.deltix.gflog.core.layout.GelfLayoutFactory">
        <additional-fields>
            <entry key="container" value="${container.name}"/>
        </additional-fields>
    </layout>
</appender>

Layouts

Template

  • %p - log level.
  • %c - log name.
  • %t - thread name.
  • %m - message.
  • %n - line break.
  • %d - date time. By default uses yyyy-MM-dd HH:mm:ss.SSS format. Custom format can be specified using {} suffix: or use custom format. For example, ISO 8601 format can be specified as %d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}.
<!-- 2021-03-05 17:14:38.154 INFO [main] Hello there! -->
<layout/>

<!-- 2021-03-05 17:15:40.879 INFO 'com.epam.deltix.gflog.sample.ConfigSample' [main]: Hello there! -->
<layout template="%d %p '%c' [%t]: %m%n"/>

<!-- 2021-03-05 17:09:04.612 (my-user) INFO 'ConfigSample' [main]: Hello there! -->
<layout template="%d (${user.name}) %p '%c{1}' [%t]: %m%n"/>

<!-- 5 Mar 2021 17:26:42.990 INFO @ Hello there! -->
<layout template="%d{d MMM yyyy HH:mm:ss.SSS} %p \0x40 %m%n"/>

<!-- 2021-03-05T17:26:42.990Z INFO @ Hello there! --> 
<layout template="%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'} %p    [%t]: %m%n" zoneId="UTC"/>

Gelf

You can stream log messages to Gray Log by using com.epam.deltix.gflog.core.layout.GelfLayout and com.epam.deltix.gflog.core.appender.TcpAppender.

You can use the following config sample to configure GF Log:

<config>
    <appender name="gelf" factory="com.epam.deltix.gflog.core.appender.TcpAppenderFactory" host="10.10.87.126" port="11111">
        <layout factory="com.epam.deltix.gflog.core.layout.GelfLayoutFactory">
            <additional-fields>
                <entry key="key" value="value"/>
            </additional-fields>
        </layout>
    </appender>

    <logger>
        <appender-ref ref="gelf"/>
    </logger>

</config>

A message sample from the config above will be:

{  
   "version":"1.1",
   "level":4,
   "host":"localhost",
   "_key":"value",
   "short_message":"Hey there!",
   "_logger":"java.util.Object",
   "_thread":"main",
   "timestamp":1345.234567890
}\0x00

Services

Async

Attribute Default Description
factory default com.epam.deltix.gflog.core.service.AsyncLogServiceFactory
entryEncoding ASCII Which encoding to use. Values: ASCII, UTF-8.
entryInitialCapacity 4K Initial entry size per thread.
entryMaxCapacity 64K Max entry size per thread.
entryTruncationSuffix >> Truncation suffix to append when exceeding the max entry size.
bufferCapacity 8M Ring buffer capacity in bytes. The ring buffer is used to pass messages to the background thread.
overflowStrategy WAIT What to do if the ring buffer is full. Values: WAIT, DISCARD.

Contains an optional idleStrategy element to specify how to idle when no messages to process:

<service entryEncoding="UTF-8" entryInitialCapacity="16K" entryMaxCapacity="128K" entryTruncationSuffix="TRNCTD>>" 
    bufferCapacity="16M" overflowStrategy="DISCARD">
   
    <idle-strategy maxSpins="0" maxYields="10" minParkPeriod="1000" maxParkPeriod="100000"/>
</service>

Sync

Good for testing to not mess up messages from different tests.

Attribute Default Description
factory change to com.epam.deltix.gflog.core.service.SyncLogServiceFactory
entryEncoding ASCII Which encoding to use. Values: ASCII, UTF-8.
entryInitialCapacity 4K Initial entry size per thread.
entryMaxCapacity 64K Max entry size per thread.
entryTruncationSuffix >> Truncation suffix to append when exceeding the max entry size.
⚠️ **GitHub.com Fallback** ⚠️