-
Notifications
You must be signed in to change notification settings - Fork 4
Appender 2.x ‐ Log4j 2.x
Chavjoh edited this page Nov 3, 2024
·
4 revisions
In the configuration file, add a new appender ElasticsearchAppender
using package com.chavaillaz.appender.log4j
with the following properties:
-
ApplicationName
(defaultunknown
). It can also be specified as environment variable or system propertyAPPLICATION
. -
HostName
(default is the machine host name). It can also be specified as environment variable or system propertyHOST
. -
EnvironmentName
(defaultlocal
). It can be specified also as environment variable or system propertyENV
. -
ElasticConverter
(defaultcom.chavaillaz.appender.log4j.converter.DefaultEventConverter
) is the class used to convert a logging event into a key/value document to be stored in Elasticsearch. It can also be specified as environment variable or system propertyCONVERTER
. -
ElasticIndex
(defaultha
) andElasticIndexSuffix
(default-yyyy.MM.dd
) form together the index name where the messages are sent to. Note thatElasticIndexSuffix
must contain a format pattern suitable forDateTimeFormatter
. They can also both be specified with environment variables or system propertiesINDEX
andINDEX_SUFFIX
. -
ElasticUrl
is the address of the server (or its load balancer) in the format[scheme://][host]:[port]
. The scheme is optional and defaults tohttp
. -
ElasticApiKey
(encoded) orElasticUser
withElasticPassword
are the credentials for the server. -
ElasticParallelExecution
(defaulttrue
) specifies the way the messages are sent to the server (true
send them in a separate thread andfalse
send them sequentially). -
ElasticBatchSize
(default1
) is the number of messages threshold triggering the sending to the server. -
ElasticBatchInitialDelay
(default1000
) is the time in milliseconds before a first batch of messages is sent to the server (after appender startup, even if the batch of messages is incomplete, meaning not reaching the threshold). -
ElasticBatchDelay
(default1000
) is the time in milliseconds between two cleanups of incomplete batches. If after this time there are less thanelasticBatchSize
messages waiting to be sent, the batch is sent nonetheless. Note that onceElasticBatchSize
messages are waiting, the batch is sent immediately, without any delay.
Note that ElasticUrl
is the only mandatory configuration to give, except if you need to overwrite the default value of another ones.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" packages="com.chavaillaz.appender.log4j">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<ElasticsearchAppender name="Elasticsearch">
<PatternLayout pattern="%msg"/>
<ApplicationName>myApplication</ApplicationName>
<EnvironmentName>local</EnvironmentName>
<ElasticConverter>com.chavaillaz.appender.log4j.converter.DefaultEventConverter</ElasticConverter>
<ElasticUrl>http://localhost:9300</ElasticUrl>
<ElasticIndex>ha</ElasticIndex>
<ElasticIndexSuffix>-yyyy.MM.dd</ElasticIndexSuffix>
<ElasticUser>elastic</ElasticUser>
<ElasticPassword>changeme</ElasticPassword>
<ElasticParallelExecution>true</ElasticParallelExecution>
<ElasticBatchSize>10</ElasticBatchSize>
<ElasticBatchInitialDelay>1000</ElasticBatchInitialDelay>
<ElasticBatchDelay>1000</ElasticBatchDelay>
</ElasticsearchAppender>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="Elasticsearch" additivity="false"/>
</Root>
</Loggers>
</Configuration>