Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Log4j2, how do I associate an XML Schema with log4j2.xml?

Tags:

java

log4j

log4j2

I have been giving the new Log4j2 a go. It seems, from the documentation on migration, that the XML Schema/DTD specification has been done away with.

That seems like a step backwards. Surely it should be possible to associate either an XML Schema or a DTD with my log4j2.xml to assist writing it and for validation. I haven't been able to find anything useful in the documentation, and neither have I found the XML Schema or DTD itself.

So: In Log4j2, how should I associate an XML Schema with log4j2.xml?

like image 285
glts Avatar asked Dec 16 '12 18:12

glts


People also ask

What is log4j2 with XML configuration?

Log4j2 with XML configuration provides a simple way of setting up logging in your Java application. Apache Log4j2 is the new version of the log4j and is used for printing logs when used in a Java program. In this tutorial we will setup a Maven project and use log4j2 to print logs from a simple Java class.

How to find the classpath location of the log4j2 configuration file?

Log4j will scan all classpath locations to find out this file and then load it. We can find this file mostly placed in the ‘ src/main/resources ‘ folder. If we are using an external log4j2 configuration file, then we can provide the path of the configuration file using the application startup parameter or system property log4j.configurationFile.

How to use Apache log4j2 to print logs from a class?

Apache Log4j2 is the new version of the log4j and is used for printing logs when used in a Java program. In this tutorial we will setup a Maven project and use log4j2 to print logs from a simple Java class. If you are using Eclipse IDE, click on File > New > Project > Maven Project (You must have Maven Plugin installed in Eclipse for this)

What does%%-5 level mean in log4j2?

%-5level: Prints the level of the log message in a right-aligned fashion. But there exists many more variables and formatting in the PatternLayout. You can refer them to the Log4J 2 ‘s official documentation. Now we'll include the defined console appender into our main configuration:


1 Answers

Works for me with eclipse:

<Configuration strict="true"            xmlns="http://logging.apache.org/log4j/2.0/config"            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config             https://raw.githubusercontent.com/apache/logging-log4j2/master/log4j-core/src/main/resources/Log4j-config.xsd"> 

or against tagged version:

<Configuration strict="true"            xmlns="http://logging.apache.org/log4j/2.0/config"            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config             https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.8.2/log4j-core/src/main/resources/Log4j-config.xsd"> 
like image 200
x545 Avatar answered Sep 16 '22 16:09

x545