6

just started to get into Graylog2 and wanted to log some Java-Applications via GELF Input. Therefore I used the library log4j2 and added the graylog2-gelfclient. All dependencies are satisfied and the programm is running. But the initialisation of my Logmanager is throwing the following error:

ERROR StatusLogger appenders contains an invalid element or attribute "GELF"

My code is just logging an error to the logger:

static final Logger logger = LogManager.getLogger(Application.class); 
    public static void main(String[] args) {
        logger.error("This is an error log entry");
    }
}

and my log4j2.xml file is configured to use GELF and the GelfAppender:

<configuration status="OFF">
    <appenders>
        <GELF name="gelfAppender" server="192.168.1.1" port="12201" hostName="myhost"/>
    </appenders>
    <loggers>
        <root level="info">
            <appender-ref ref="gelfAppender"/>
        </root>
    </loggers>
</configuration>

Is anyone familiar with this problem? Thanks for any help.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
Felix
  • 91
  • 1
  • 5

2 Answers2

4

It sounds like there is a problem with either the dependencies, or log4j has some other trouble loading or initializing the GELF appender plugin. It may be a good idea to mention your exact dependencies, both for log4j2 and log4j2-gelf. (Otherwise we have to guess...)

Furthermore, try setting status output to trace with

<configuration status="trace" ...

and take a look at the log4j internal log messages that are shown on the console. This should give you some insight into what is going wrong. Hopefully there is a clear ERROR-level message in that output that tells us what the problem is.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
3

Just managed to solve the problem :)

First of all I put the name of the package, that contains the GELF-appender, into the log4j2.xml file.

<configuration status="OFF" packages="org.graylog2.log4j2">
   <appenders>
      <GELF name="gelfAppender" server="192.168.1.1" port="12202" hostName="myhost"></GELF>
   </appenders>
   <loggers>
      <root level="info">
         <AppenderRef ref="gelfAppender"/>
      </root>
   </loggers>

Then I got this error: "This code should have never made it into slf4j-api.jar"

I didn't use Maven in the first place to get all the needed packages. So I used Maven and this gave me the hint, that the imported slf4j-api .java-files where not the expected ones. If you download the official SLF4J distribution be careful which files you import. In the first place, I imported the java files from the folder "slf4j-api" - but this folder holds the "impl" folder which caused the error I mentioned above. So I imported the sl4j-api-1.7.7.jar which is also in the official SLF4J distribution (this jar does not contain the "impl"-package) and now it works fine.

Note: I got this message when running the program:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Felix
  • 91
  • 1
  • 5