Log4j2-gelf "ERRORS AppLogger contains invalid element or attribute" GELF "

just started getting into Graylog2 and wanted to register some Java applications through GELF Input. So I used the log4j2 library and added graylog2-gelfclient. All dependencies are fulfilled and the program works. But initializing my Logmanager causes the following error:

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

My code just logs an error in the log:

 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 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.

+5
source share
2 answers

It looks like there is a dependency problem, or log4j has some other problems with loading or initializing the GELF appender plugin. It might be a good idea to mention your exact dependencies for both log4j2 and log4j2-gelf. (Otherwise, we must guess ...)

Also, try setting up status output for tracing with

 <configuration status="trace" ... 

and take a look at the internal log4j log messages that appear on the console. This should give you some idea of ​​what is going wrong. Hopefully there is a clear ERROR message in this release that tells us what the problem is.

+2
source

Just managed to solve the problem :)

First of all, I put the name of the package containing 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 never have turned into slf4j-api.jar"

I did not use Maven in the first place to get all the necessary packages. So I used Maven, and this gave me a hint that the imported slf4j-api.java files where not expected. If you download the official SLF4J distribution, be careful what files you import. Firstly, I imported java files from the "slf4j-api" folder - but this folder contains the "impl" folder, which caused the error that I mentioned above. Therefore, I imported sl4j-api-1.7.7.jar, which is also in the official distribution of SLF4J (this bank does not contain an "impl" package), and now it works fine.

Note. I received this message when starting 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. 
+2
source

Source: https://habr.com/ru/post/1205193/


All Articles