Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get GELFJ appender work in log4j?

I need to get my Java application writing logging to a Graylog2 server. The application uses a log4j configuration. Several things I have tried to get the logging writing to the Graylog2 server, the things I got working was sending a test message directly to the server, as shown here (first example).

Yet, when I write an appender and attach it to the root logger, I always get this error message the first time a log event is to be fired:

log4j:ERROR Could not send GELF message

Nothing then happens on the Graylog2 server side.

The appender I try to get working:

<appender name="graylog2" class="org.graylog2.log.GelfAppender">
    <param name="graylogHost" value="127.0.0.1"/>
    <param name="originHost" value="my.machine.example.com"/>
    <param name="extractStacktrace" value="true"/>
    <param name="addExtendedInformation" value="true"/>
    <param name="facility" value="gelf-java"/>
    <param name="Threshold" value="INFO"/>
    <param name="additionalFields" value="{'environment': 'DEV', 'application': 'MyAPP'}"/>
</appender>

Does anyone have an idea how to get this running?
Any help is highly appreciated!

like image 938
Jochen Avatar asked Nov 10 '14 15:11

Jochen


People also ask

What is Appender in log4j?

Appenders. Apache log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as consoles, files, sockets, NT event logs, etc. Each Appender object has different properties associated with it, and these properties indicate the behavior of that object.

How do I use console Appenders in log4j2?

Log4j2 ConsoleAppender ConfigurationThe target poperty specifies the target of the logging messages i.e. SYSTEM_OUT or SYSTEM_ERR . The follow attribute tells whether the appender should honor the reassignments of System. out or System. err made after the logging configuration has been initialized.

Where can I find log4j properties file?

During Content Engine installation, two log4j sample files are placed on the system in the ContentEngine\config\samples\ folder: log4j. properties. client: A Java format file that contains client configuration settings.


1 Answers

This work work me:

add this dependency in your maven pom file

       <dependency>
            <groupId>org.graylog2</groupId>
            <artifactId>gelfj</artifactId>
            <version>1.1.13</version>
        </dependency>

and these lines in your log4j.properties

# Define the graylog2 destination
log4j.appender.graylog2=org.graylog2.log.GelfAppender
log4j.appender.graylog2.graylogHost=192.168.243.23 
log4j.appender.graylog2.port=12201
log4j.appender.graylog2.originHost=loggenerator-server-ip
log4j.appender.graylog2.layout=org.apache.log4j.PatternLayout
log4j.appender.graylog2.additionalFields={'environment': 'DEV', 'application': 'MyAPP'}
log4j.appender.graylog2.extractStacktrace=true
log4j.appender.graylog2.addExtendedInformation=true
log4j.appender.graylog2.facility=gelfappender-test
like image 102
adramazany Avatar answered Sep 30 '22 11:09

adramazany