log4j Configuration

<< Click to Display Table of Contents >>

Navigation:  Integrating SQLstream Blaze with Other Systems > Appendix A: Legacy Adapters and Agents > Adapter for log4j >

log4j Configuration

Previous pageReturn to chapter overviewNext page

Note: This topic describes a legacy adapter. Unless you have used these in the past, we recommend using the Extensible Common Data Adapter and Agent instead of these legacy adapters and agents.

Configuring log4j for source streams

To use the SQLstream log4j Adapter, the application and the SQLstream log4j Adapter need to be configured with a matching appender and receiver.

For instance, the following XML configures the application log4j framework to log to a SocketAppender on the localhost:

Configuration example 1: logging to a SocketAppender on the localhost

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

   <appender name="SOCKET" class="org.apache.log4j.net.SocketAppender">

       <param name="RemoteHost" value="localhost"/>

       <param name="Port" value="4445"/>

       <param name="LocationInfo" value="true"/>

       <layout class="org.apache.log4j.PatternLayout">

       <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>

       </layout>

   </appender>

   <root>

       <level value="debug" />

       <appender-ref ref="SOCKET" />

   </root>

</log4j:configuration>

 

Configuration example 2: Receiving logs from a SocketReceiver

To receive logs from that application, the SQLstream s-Server should reside on the remotehost. The log4j configuration for the log4j Adapter configures a corresponding SocketReceiver.

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

   <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">

       <layout class="org.apache.log4j.PatternLayout">

       <param name="ConversionPattern" value="%-5p [%t] %C{2} (%F:%L) - %m%n"/>

   </layout>

   </appender>

       <appender name="SS" class="com.sqlstream.plugin.log4j.Log4JStreamAppender">

       <param name="Columns" value="LOGGER, LEVEL, MESSAGE" />

   </appender>

   <plugin name="SocketReceiver" class="org.apache.log4j.net.SocketReceiver">

       <param name="Port" value="4445" />

   </plugin>

   <logger name="errors">

       <level value="debug" />

       <appender-ref ref="STDOUT" />

   </logger>

   <root>

       <level value="debug" />

       <appender-ref ref="SS" />

   </root>

</log4j:configuration>

 

A Log4JStreamAppender can optionally be configured to control the columns to be exposed by the streams in the adapter's virtual schema.

The table below shows all possible configuration parameters for SQLstream's log4j Appender, with explanations:

Configuration parameters for SQLstream's log4j Appender

Purpose

Req'd

Default Value

XML Syntax

Properties Syntax

Tell the log4j Adapter to use a custom set of columns. Standard log4j configuration

yes

n/a

<appender name ="..."

class="... Log4JStreamAppender"/>

Log4j.appender.

<USER DEFINED NAME>

Define custom columns. Value is a comma-delimited list of log4j fields. See the section on log4j fields for a list of possible fields.

yes

n/a

<param name= "Columns"

value= "..." />

*.columns

Layout. Format to use for the column associated with the "LAYOUT" field. Standard log4j configuration

no

n/a

<layout class ="..." >

<param name= "..." value="...">

</layout>

*.layout

In the example above, the streams in the virtual schema will have "LOGGER", "LEVEL", and "MESSAGE" as columns.

By default (if the Log4JStreamAppender is not configured), the columns are: "TIMESTAMP" "LOGGER", "LEVEL", and "MESSAGE".

Configuring log4j for sink streams and errors

To send log4j messages from SQLstream, the log4j configuration for the log4j Adapter must have loggers with appropriate appenders configured. For instance, the following XML shows how to configure a logger to output to the console:

<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">

   <layout class="org.apache.log4j.PatternLayout">

       <param name="ConversionPattern" value="%-5p [%t] %C{2} (%F:%L) - %m%n"/>

   </layout>

</appender>

<logger name="mylogger">

   <level value="debug" />

   <appender-ref ref="STDOUT" />

</logger>

 

Note that while it is possible to use the JDBCAppender to insert log4j messages into a SQLstream system, inserting into the SAME SQLstream system is not supported and will result in deadlock. Inserting into a different SQLstream system is allowed.

log4j Adapter Configuration Parameters

This section shows the log4j adapter configuration parameters in tables for server options, stream options, stream column options and log4j fields.

The table below, Server options for log4j adapter, shows the server options specifiable for log4j.

Name

 

Type and Description

Req'd

Value

CONFIG

string

Location of the log4j XML or properties configuration file

yes

path to log4j configuration file

SCHEMA_NAME

string

Defaults to LOGS.

no

virtual schema name

THRESHOLD

string

Threshold of the logger repository. Defaults to ALL.

no

log4j log level

CREATE_LOGGER

boolean

Option to automatically create a new logger when using the virtual schema to select from a stream corresponding to an unknown logger. Defaults to false.

no

true or false

ERROR_LOGGER

string

log4j logger to use for errors.

no

logger name

Stream options for log4j adapter

The table below shows the server options specifiable for log4j.

Name

Description

Type

Req'd

Value

TYPE

'source' : data source stream from a log4j logger;

'sink' : data sink stream that outputs to a log4j logger

string

yes

'source' or 'sink'

LOGGER

Defaults to the root logger.

string

no

logger name

THRESHOLD

Logger level. Overrides XML configuration.

string

no

log4j log level

LEVEL

Default level to use when logging (if the log level was null). Applicable only for sink stream, defaults to DEBUG.

string

no

log4j log level

ROWTIME_SOURCE

Only for source streams. Where to get the rowtime of each row:

'event' means take timestamp embedded in the LoggingEvent object;

'system' means read the system clock.

string

no

'event' or 'system'

Stream column options for log4J adapter

The table below shows the stream column options specifiable for log4j

Name

Description

Type

Required

Value

FIELD

Binds this column to given log4j field. The column name is used as the log4j field if this option is not specified. The list of log4j fields and their types is given in the table below.

string

no

log4j field name

LAYOUT

LAYOUT.Option1

...

LAYOUT.OptionN

If the column is bound to a layout field, then these column options configure the layout by specifying the layout class and parameters.

string

no

log4j layout class name

log4j layout parameters

log4j fields

The columns of a log4j data source stream can be bound to any of the log4j fields. All columns must be bound to a field.

The columns of a log4j data sink stream have the following constraints:

Only the 'LOGGER', 'LEVEL', 'MESSAGE', and 'MDC' fields can be bound to a log4j data sink stream column.

The 'LOGGER', 'LEVEL', 'MESSAGE' fields cannot be bound to multiple columns.

One column must be bound to the 'MESSAGE' field.

Any unbound columns will be treated as a MDC.

An MDC column will use the column name as the MDC key.

Field parameters for columns in streams from the log4j adapter

The table below shows the field parameters for columns in streams specifiable for log4j

Name

Type

Description

LOGGER

string

Name of the logger

CLASSNAME

string

Name of the class making the log request

TIMESTAMP

timestamp, date, time, or string

Timestamp of the log request

RELTIME

long or string

Relative time in milliseconds since the start of the application

FILE

string

Name of the file in which the log request was made

LINE

string

Line number at which the log request was made

LOCATION

string

Full location information (with class, method, file, and line number)

METHOD

string

Method making the log request

MESSAGE

MSG

string

Log message

LEVEL

PRIORITY

string or integer

Level of the log statement

SEQUENCE

string or integer

Log sequence number

THREAD

string

Thread making the log request

NDC

string

NDC (Nested Diagnostic Context) of the log statement

MDC[:Key]

string

MDC (Mapped Diagnostic Context) of the log statement

THROWABLE

string

String representation of throwable associated with the log statement

LAYOUT

string

User defined format of the log event