Getting log4j2 to work with eclipse - java

I know there is allot of questions been asked on this but i have been trying to get this to work for few day's and i am not any more forward then when i started.
i have tried to use -Dlog4j.configuration=file:/path/to/log4j.properties and -Dlog4j.debug in eclipse vm arguments (under debug & run) and get no output
I have tried to use .properties and .xml but no joy
Tried to put the .xml and .properties files at the root, in the src and in an external folder which i added to my classpath ... still no joy
I think its using another .xml or .properties files in another lib/jar but because i cant get any debug to work i am finding very difficult to track what i am doing wrong here...
any help would be great! below is the code .. only the error message get's printed.
I have download (http://logging.apache.org/log4j/2.x/download.html) and imported into my app the
log4j-api-2.0-beta8.jar
log4j-core-2.0-beta8
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CucmServMonitor
{
private static final Logger logger = LogManager.getLogger(CucmServMonitor.class.getName())
public static void main(String[] args)
{
logger.error("testing ERROR level");
logger.trace("exiting application");
System.out.println(logger.getName());
}
}
the xml file i am using just now log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="WARN">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</appenders>
<loggers>
<root level="debug">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>

Manage to figure this one out. The hint was here.
http://pic.dhe.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-112.htm
I needed to add a "class folder" of where the log4j2.xml was located and then make sure it was at TOP of the list:
Right click on your project and go to properties
Then follow the step shown below. After adding the folder make sure its at the top and then click ok

Or... just create a resources directory like src/test/resources and add the log4j.xml file to that dir and then make that directory a source folder. Then eclipse will automatically copy the file to the the classes dir and there you have it.

1) Create the log4j.properties file inside the root folder
log4j.rootCategory=DEBUG, CONSOLE
# Appender writes to console
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
2) Modify the code like this
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class CucmServMonitor {
private static final Logger logger = Logger.getLogger(CucmServMonitor.class);
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
logger.error("testing ERROR level");
logger.trace("exiting application");
System.out.println(logger.getName());
}
}

according to Alexis comment, I setup it, but eclipse still can not find log4j2.xml. finally, I solved it by removing the other jars imported, only keep log4j-api and log4j-core. before I imported all the jars downloaded from the Apache website. hope this can help someone.

According to Alexis comment, I setup it, but eclipse still can not find log4j2.xml. finally, I solved it by removing the other jars imported, only keep log4j-api and log4j-core. before I imported all the jars downloaded from the Apache website.
I solved my project for log4j->log4j2 version upgrading.

Related

Specifying Log4j2 Configuration File When Using Executable JAR

I am having trouble specifying the Log4j2 config file location when using an executable JAR file. It works fine if I separate all the JARs, but when I try to combine them into one executable JAR file, for some reason the log4j2.xml file isn't picked up from the command line.
I've tried these two methods of specifying the location:
java -Djava.libary.path=..\bin -cp ..\config -jar MyApplication.jar
java -Djava.libary.path=..\bin -Dlog4j.configurationFile=..\config\log4j2.xml -jar MyApplication.jar
Neither of those are working. I've also tried adding the directory containing the config file to the classpath in the JAR's manifest file:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.2
Created-By: 1.7.0_21-b11 (Oracle Corporation)
Main-Class: com.abc.MyApplication
Class-Path: ../config/
I haven't had success with this method either. Any ideas what I might be doing wrong?
Thanks in advance for any help!
EDIT
Ah, I believe I mistook the problem. Originally, this was the error I was seeing in the command line output:
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
But at some point while I was changing things, the error message changed without my realizing it to this:
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
So what I figured out was that even though the executable JAR I was building was including the log4j-core-2.1.jar and log4j-api-2.1.jar JARs inside of it and in the MANIFEST file's classpath, there was a problem. The way I wrote my ant file to combine the libraries into the single JAR I was creating was successfully copying over the directories and class files, but was not copying over the other types for some reason, which are also obviously necessary (e.g. Log4j-config.xsd, Log4j-events.dtd, etc.).
To fix this, I changed the way I was merging the JARs in my Ant build file to this:
<jar destfile="${dist}/${jarName}" basedir="${classes}"
excludes=".svn">
<!-- Merge this JAR with all the JARs in the lib directory, so that
we are only creating one distribution JAR that includes all the
libraries that you need. -->
<fileset dir="${classes}" includes="**/*.class" />
<zipgroupfileset dir="${lib}" includes="**/*.jar" />
<!-- Specify the manifest file of the JAR -->
<manifest>
<attribute name="Main-Class" value="com.abc.MyApplication"/>
<attribute name="Class-Path" value=". ${manifest.classpath}"/>
</manifest>
</jar>
And that fixed the issue and copied over all files from the JARs into my newly created JAR.
Once this issue was resolved, the second of the commands I posted above worked for specifying the location of the configuration file. (As noted by #rewolf below, the first command won't work because the classpath specified in the MANIFEST of the JAR overrides any classpath specified on the command line.
Thanks for your responses, they definitely helped me get on the right path toward figuring out my mistakes.
Something that isn't explained very well/obviously in the Java documentation is that if you're using an executable Jar, it will only use the Class-Path as specified in the Manifest file. It will not listen to the -cp or --classpath arguments.
-Dlog4j.configurationFile=directory/file.xml
should definitely work though. I'm assuming you're running on Windows given your slash direction. Are you sure you are running it from the correct relative directory?
Update
I just tried it in Windows with no problems. I used the following manifest:
Manifest-Version: 1.0
Built-By: andrew.flower
Build-Jdk: 1.7.0_67
Class-Path: lib/log4j-api-2.1.jar lib/log4j-core-2.1.jar
Created-By: Apache Maven 3.2.3
Main-Class: com.andrew_flower.test.Log4jTest
Archiver-Version: Plexus Archiver
The Log4j2 jars are located in a lib/ directory and the log4j2.xml is in the conf/ directory. I executed the following command, and it found the config successfully.
java -Dlog4j.configurationFile=conf\log4j2.xml -jar log4j2test1-1.0-SNAPSHOT.jar
For others who may have this issue...
Make sure your -Dlog4j.configurationFile options occur before your '-jar' not after. Might seem obvious, but saw that mistake once.
Try treating the file location as a url and see if that works. I.e. escape spaces with %20 etc. Also use 'file://path', replace backslashes with forwardslashes.
Windows paths can be written as file://c:/path/to/log4j2.xml
Hence if you have a log4j2.xml in your program folder for your exampleApp in C:\Program Files\ExampleApp then...
java.exe -Dlog4j.configurationFile=file://c:/program%20files/exampleapp/log4j2.xml -jar exampleApp.jar ...
...should work
I solved the problem of specifying the location of log4j2 configuration in a runnable Jar that I created from Eclipse by including this in my java code:
System.setProperty("log4j.configurationFile", "resources/log4j2.xml");
I have a package and so I needed to specify the path to my "resources" folder (in my "src" folder in Eclipse):
System.setProperty("log4j.configurationFile", "com/company/app/resources/log4j2.xml");
Notice I didn't include "src" in my path and I think it's the path in the "bin" folder that's required: ie in my case "com/company/app/resources/log4j2.xml"
My configuration file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level - %msg%n"/>
</Console>
<RollingFile
name="RollingFile"
fileName="${sys:logFilename}"
filePattern="${sys:logFilename}-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level - %msg%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="1 MB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</appenders>
<loggers>
<root level="all">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFile"/>
</root>
</loggers>
Also notice I dynamically assign the rolling log file path + name "${sys:logFilename}" by including this in my java code:
System.setProperty("logFilename", "logs/myApp.log");
In order to get these 2 dynamic System.setProperty assignments to work they need to execute before the "getLogger" statement and so my java code looks like:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class MyTestLoggingClass {
public static Logger logger = null;
...................
setUpLogging();
...............
public static void setUpLogging() {
System.setProperty("log4j.configurationFile", "com/company/app/resources/log4j2.xml");
System.setProperty("logFilename", "logs/myApp.log");
logger = LogManager.getLogger(Logger.class.getName());
}
}
Having "logger" declared at the start of my class (but without invoking "getLogger" before my 2 System.setProperty statements) enables me to reference "logger" in other methods. I am obliged to initialise it though and so I chose "null" but then later update it with the "getLogger" statement - given this I can't make it "final" (can only assign it once) but can make it static - a constant class variable.
nb the 2 log4j2 jars I included in the build path are:
log4j-api-2.6.2.jar
log4j-core-2.6.2.jar
I had this issue with version 2.8 of Log4j2.
This was gone when the respective Log4j2 jars were replaced with version 2.6 of Log4j2.

unable to find logback.xml

I'm trying to use logback as my logger in my simple program but it does not work fine!
I put logback/logback.xml and logback/Logback.java in the source directory logback and run through this command line
\logback>java -cp .;%CLASSPATH% Logback
which the %CLASSPATH% is an environment variable that has the path of .jar file that logback needs like:
logback-access-1.1.2.jar
logback-classic-1.1.2.jar
logback-core-1.1.2.jar
slf4j-api-1.7.6.jar
This is my logback.xml file
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>test.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>tests.%i.log</fileNamePattern>
<minIndex>1</minIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>2MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="FILE" />
</root>
</configuration>
and there is my simple program
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Logback{
private final static Logger logger = LoggerFactory.getLogger(Logback.class);
public static void main(String[] args){
for(int i=0;i<1000000;i++)
logger.debug("hello");
}
}
but unfortunately i just receive log in the console instead of test.log files. it seems the logger object just use the default configuration!!!
If i set the -Dlogback.configurationFile=logback.xml variable as below, it works properly. but how to run without this variable?
\logback>java -cp .;%CLASSPATH% -Dlogback.configurationFile=logback.xml Logback
From logback documentation:
1. Logback tries to find a file called logback.groovy in the classpath.
2. If no such file is found, logback tries to find a file called logback-test.xml in the classpath.
3. If no such file is found, it checks for the file logback.xml in the classpath..
4. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.
Where should the configuration files such as logback.groovy, logback-test.xml or logback.xml be located on the classpath?
Configuration files such as logback.groovy, logback-test.xml or logback.xml can be located directly under any folder declared in the class path. For example, if the class path reads "c:/java/jdk15/lib/rt.jar;c:/mylibs/" then the logback.xml file should be located directly under "c:/mylibs/", that is as "c:/mylibs/logback.xml". Placing it under a sub-folder of c:/mylibs/, say, c:/mylibs/other/, will not work.
For web-applications, configuration files can be placed directly under WEB-INF/classes/.
So you need to put logback.xml in the classpath. On one project we had a similar problem although logback.xml was in the right place. Renaming it to logback-test.xml helped.
If you add the jar files to C:\Program Files\Java\jre7\lib\ext . and try to run the program like below:
\logback>java Logback
it wont see the logback.xml file in the source directory
when i deleted the
logback-access-1.1.2.jar
logback-classic-1.1.2.jar
logback-core-1.1.2.jar
slf4j-api-1.7.6.jar
files from C:\Program Files\Java\jre7\lib\ext, it went OK!

Log4j2 configuration - No log4j2 configuration file found

Lately I decided to learn how to use the log4j2 logger. I downloaded required jar files, created library, xml comfiguration file and tried to use it. Unfortunately i get this statement in console (Eclipse) :
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
This is my testing class code:
package log4j.test;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Log4jTest
{
static final Logger logger = LogManager.getLogger(Logger.class.getName());
public static void main(String[] args) {
logger.trace("trace");
logger.debug("debug");
logger.info("info");
logger.warn("warn");
logger.error("error");
logger.fatal("fatal");
}
}
And my xml config file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration package="log4j.test"
status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="log4j.test.Log4jTest" level="trace">
<AppenderRef ref="Console"/>
</Logger>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
I tried also with xml without <Logger> tags, and package specification and in various folders/packages directories, but it didn't help. Now my log4j2.xml file is located directly in project folder in eclipse.
Is this a simple eclipse java project without maven etc? In that case you will need to put the log4j2.xml file under src folder in order to be able to find it on the classpath.
If you use maven put it under src/main/resources or src/test/resources
You need to choose one of the following solutions:
Put the log4j2.xml file in resource directory in your project so the log4j will locate files under class path.
Use system property -Dlog4j.configurationFile=file:/path/to/file/log4j2.xml
Was following the documentations - Apache Log4j2 Configuratoin and Apache Log4j2 Maven in configuring log4j2 with yaml. As per the documentation, the following maven dependencies are required:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
and
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.8.6</version>
</dependency>
Just adding these didn't pick the configuration and always gave error. The way of debugging configuration by adding -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE helped in seeing the logs. Later had to download the source using Maven and debugging helped in understanding the depended classes of log4j2. They are listed in org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory:
com.fasterxml.jackson.databind.ObjectMapper
com.fasterxml.jackson.databind.JsonNode
com.fasterxml.jackson.core.JsonParser
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
Adding dependency mapping for jackson-dataformat-yaml will not have the first two classes. Hence, add the jackson-databind dependency to get yaml configuration working:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
You may add the version by referring to the Test Dependencies section of log4j-api version item from MVN Repository. E.g. for 2.8.1 version of log4j-api, refer this link and locate the jackson-databind version.
Moreover, you can use the below Java code to check if the classes are available in the classpath:
System.out.println(ClassLoader.getSystemResource("log4j2.yml")); //Check if file is available in CP
ClassLoader cl = Thread.currentThread().getContextClassLoader(); //Code as in log4j2 API. Version: 2.8.1
String [] classes = {"com.fasterxml.jackson.databind.ObjectMapper",
"com.fasterxml.jackson.databind.JsonNode",
"com.fasterxml.jackson.core.JsonParser",
"com.fasterxml.jackson.dataformat.yaml.YAMLFactory"};
for(String className : classes) {
cl.loadClass(className);
}
Eclipse will never see a file until you force a refresh of the IDE. Its a feature! So you can put the file all over the project and Eclipse will ignore it completely and throw these errors. Hit refresh in Eclipse project view and then it works.
Additionally to what Tomasz W wrote, by starting your application you could use settings:
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=TRACE
to get most of configuration problems.
For details see Log4j2 FAQ: How do I debug my configuration?
In my case I had to put it in the bin folder of my project even the fact that my classpath is set to the src folder. I have no idea why, but it's worth a try.
log4j-test.xml => name of the configuration file if placed in /test/resources
#TestPropertySource(properties = {
"log4j.configurationFile","log4j-test.xml"
})
#CucumberContextConfiguration
#ContextConfiguration(classes = TestConfiguration.class)
public class Steps{
private Logger log = LogManager.getLogger(Steps.class);
//implementation
}

How to setup LogBack Configuration

I'm completely new to LogBack, and I'd like to use it. I notice that you can use a Configuration as an XML, but I have no idea how to implement that XML and have Logback use that instead of the default one.
My programs packages are like me.iarekylew00t.a.b and so on. It'll also be compiled into a runnable JAR at the end. How should I go about adding a logback.xml file, without the enduser needing to have it?
Sorry if this is a noob question, but I've been trying to look this up for hours and I can't find anything that clearly tells someone how to go about adding a configuration - most assume you already know how... Thanks. (please be as detailed as possible)
Add a logback.xml in the root of your classpath containing (tune to your needs):
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</encoder>
</appender>
<logger name="some.logger.name" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
and that's all.
EDIT: usual directory structure:
src/main/java/
some/package/
someClass.java
some/other/package/
someOtherClass.java
src/main/resources/
logback.xml
in the jar:
some/package/
someClass.class
some/other/package/
someOtherClass.class
logback.xml
I had the same issue and resolved it by copying logback.xml to src/main/java - this was the only way I found to make the executable JAR find it and use it.
Since I didn't want to have two (possibly different) config files, I kept the original logback.xml in my src/resources folder (where Eclipse would find it and use it during development) and replaced the one under src/main/java with a symlink. Works well for me.

log4j 2 - configuration issue

I am trying to configure log4j 2.0 to report logs.
My config is saved as log4j2.xml and this is its content:
<?xml version="1.0" encoding="UTF-8"?>
<configuration name="PRODUCTION" status="OFF">
<appenders>
<RollingFile name="MyFileAppender"
fileName="../Logs/app.log"
filePattern="../Logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingFile>
</appenders>
<loggers>
<root level="trace">
<appender-ref ref="MyFileAppender"/>
</root>
</loggers>
</configuration>
It exists in the classpath of the project and I tried putting it in many other directories..
I created a logger in the code like so:
Logger logger = LogManager.getLogger(MyClass.class.getName());
logger.info("test");
And nothing is written and no file is created.
When I debug the code I see that the logger is the default logger(console).
place log4j2.xml file under src/main/resources. It works
Actually This is a straight forward process. Two main classes of Log4j 2 are as follows that you need to import like this:
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
Now get a Logger instance by using this code.
private static final Logger logger = LogManager.getLogger();
Note I didn't specified the class name to getLogger() method as a parameter. Log4j 2 automatically figures it out.
Now you can use any of the info(), trace(), debug(), warn(), error(), fatal() method from the Logger class. But to get the output from all of these methods you'll need a XML configuration file. By default Log4j 2 only produces output from the error() and fatal() methods.
Configuration file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="MyCustomLogFile" fileName="/home/me/mylogfile.log">
<PatternLayout>
<Pattern>%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Pattern>
</PatternLayout>
</File>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="MyCustomLogFile"/>
<!--<AppenderRef ref="Console"/>-->
</Root>
</Loggers>
</Configuration>
Save this file with any name any where. I use Log4j2.xml as name. Now you'll need this file to be put in classpath, which you can do by passing a system property when running the program as follows:
java -Dlog4j.configurationFile=/path/to/xml/configuration/file/Log4j2.xml MyMainClass
And you've done it. Logging will be right away on your console.
Special Notes:
In XML file I've provided 2 appenders: A file and a console. You can see that you just need to uncomment the commented AppenderRef tag to get output in a file instead of console.
You can also provide an environment variable as a system property. Log4j 2 will read the configuration file from the environment variable first and then in -D argument if not found an environment variable.
Have fun with logging. :-)
you should put your log4j2.xml into the classpath.
or set "log4j.configurationFile" system property to force to use your log4j2.xml
Please refer to: http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration
It exists in the classpath of the project and I tried putting it in
many other directories.
Where exactly? There is often confusion about where "in the classpath" means. It can't just be anywhere. It has to be at the 'top' or the 'default package'.
src
├── main
│   └── java
│   ├── com
│   │   └── example
│   └── log4j2.xml
A tip for eclipse users:
Right click on the project and click "refresh". Make sure you could see the log4j2.xml file in eclipse.
(This solved my problem.)
To be verbose:
You shouldn't add the file to build path.(If you do, eclipse will warn you about this)
The name of this file doesn't appear in '.classpath' file.
I put my log4j2.xml under src/ directory. It works.
I had similar problem. I put the file under src folder and it worked. I did not mention any package name in the log4j2.xml file.
In the documentation of log4j 2: http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration
"If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath."
but it is not working with classpath. Instead if we keep it in src folder, then it is working.
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2.xml</param-value>
</context-param>
similar problem is mentioned here : https://issues.apache.org/jira/browse/LOG4J2-357
I had the problem, I tried some solutions, but only this worked to me:
Go to web.xml, and add this parameter:
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>log4j2.xml</param-value>
</context-param>
I'm quite sure that you have to write down the full qualified name of the class whose messages you want to be logged - something like com.application.log4jtest.YourClass. If that doesn't work, try fiddling with the log level.
Also - just as a notice - you can also write
Logger logger = LogManager.getLogger(MyClass.class); // omit .getClass()
I also faced the same problem.I kept my log4j2.xml file in System environment variable.
Variable name : sys_logroot Variable value : D:\user\gouse
and no logs are created for me.
use the system variable-Dlog4j.configurationFile=path/to/log4j2.xmlSee here
This solve my problem
I had the same 'ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.' message over and over. It made me crazy. The log4j2.xml file was placed correctly at src/main/resources, like i did at thousands of projects before.
The solution in my case was to remove <packaging>pom</packaging> from the root pom.xml. packaging pom causes the content of src/main/resources not to be copied to target/classes.
Happy logging for anyone with the same root cause.
Ok, I solved the problem.
I had to specify in the xml the package="myPackage"

Categories

Resources