Questions tagged [log4j2]

Log4j 2 is an upgrade to Log4j, a Java-based logging utility, that provides significant improvements over its predecessor, Log4j 1.x, and provides many of the improvements available in Logback while fixing some inherent problems in Logback's architecture.

log4j2
Filter by
Sorted by
Tagged with
291 votes
4 answers
225k views

Very simple log4j2 XML configuration file using Console and File appender

I'd like a very simple XML configuration file with a console and a file appender using log4j2. (The Apache Website is killing me with much Information.)
Thorsten Niehues's user avatar
189 votes
3 answers
116k views

Is it worth to use slf4j with log4j2

I am not able to decide whether to use slf4j or not with log4j2. Based on online posts, does not look like it will have any performance hit but is it really required. Also these points rule in favor ...
Andy897's user avatar
  • 7,013
157 votes
9 answers
140k views

Programmatically change log level in Log4j2

I'm interested in programmatically changing the log level in Log4j2. I tried looking at their configuration documentation but that didn't seem to have anything. I also tried looking in the package: ...
CorayThan's user avatar
  • 17.5k
98 votes
7 answers
195k views

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 (...
Qbisiek's user avatar
  • 1,043
98 votes
1 answer
48k views

What does “status” mean in Log4j2 configuration?

I just have finished adjustment of log4j2.xml configuration file and spotted something I don't really understand. So what is <Configuration status="SOME_STATUS_HERE">? Almost in all ...
Yurii Bondarenko's user avatar
80 votes
6 answers
144k views

Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

In my Spring boot 2 project: In build.gradle: dependencies { implementation 'com.google.code.gson:gson:2.7' implementation 'com.h2database:h2' implementation 'javax.servlet:jstl:1.2' ...
Alexei's user avatar
  • 15k
80 votes
17 answers
342k views

No log4j2 configuration file found. Using default configuration: logging only errors to the console

$ java -Dlog4j.configuration=file:///path/to/your/log4j2.xml -jar /path/to/your/jar_file.jar Written to the console, you get ERROR StatusLogger No log4j2 configuration file found. Using default ...
Jeff Maass's user avatar
  • 3,692
76 votes
6 answers
63k views

Is log4j2 compatible with Java 11?

I tried to run my project on the latest Java 11. Everything works, except the specific file logger. Logging works fine on previous Java versions - 10, 9, 8, but not on Java 11. During server run I ...
Dmitriy Dumanskiy's user avatar
63 votes
2 answers
72k views

Log4J2 property substitution - default

I just wonder if there is any way to provide default value for property substitution in LOG4J? I want to pass file path in java system property and then use it with "${env:mySystemProperty}". But ...
Leos Literak's user avatar
  • 9,089
63 votes
3 answers
74k views

How to Create a Custom Appender in log4j2?

As disscussed in this link : How to create a own Appender in log4j? For creating a custom appender in log4j 1.x we have to extend the AppenderSkeleton class and implements its append method. ...
saurabh goyal's user avatar
63 votes
10 answers
254k views

ERROR StatusLogger Log4j2 could not find a logging implementation

I am trying to implement log4j 2 but it keeps throwing the following error. > ERROR StatusLogger Log4j2 could not find a logging implementation. > Please add log4j-core to the classpath. Using ...
Alok's user avatar
  • 1,471
62 votes
3 answers
58k views

Log4j vulnerability - Is Log4j 1.2.17 vulnerable (was unable to find any JNDI code in source)?

With regard to the Log4j JNDI remote code execution vulnerability that has been identified CVE-2021-44228 - (also see references) - I wondered if Log4j-v1.2 is also impacted, but the closest I got ...
Ravindra HV's user avatar
  • 2,598
61 votes
11 answers
71k views

log4j2 ERROR StatusLogger Unrecognized conversion specifier

I have log4j2 in my project when I run main method in intellij Idea ,it correct to print log. when i use maven-shade-plugin package project to jar file, and run jar as standalone application it ...
CoderMeng's user avatar
  • 809
59 votes
2 answers
45k views

log4j2 specify relative path to tomcat home dir for FileAppender

I am trying to configure log4j2 for my tomcat server running locally. I am unable to pipe the logs to a location that is relative to the tomcat install. If I specify an absolute path it works. If I ...
Moemars's user avatar
  • 4,762
57 votes
2 answers
63k views

Log4j2 why would you use it over log4j? [closed]

I must be missing something but I have been looking at this for a few days now, but why on earth would you ever use log4j2 over log4j (other than the performance)? From what I have seen so far, ...
Scott Neville's user avatar
55 votes
5 answers
68k views

How to add Log4J2 appenders at runtime programmatically?

Is it possible to add Log4J2 appenders programmatically using the specifications from the XML configuration? I plan to define it all in the log4j2.xml and then pick appenders situationally like this (...
Brian Johnson's user avatar
52 votes
5 answers
91k views

log4j2 xml configuration - Log to file and console (with different levels)

I want to do two things: Log to console with a certain log-level Log to file with another log-level Console logging seems to work just fine but the log file keeps beeing empty. This is my log4j2....
daker's user avatar
  • 3,460
52 votes
4 answers
60k views

Log4J2 - assigning file appender filename at runtime

I have a log4j2.xml config file in the class path. One of the appenders is a File appender, and I would like to set the target file name at run time in the Java application. According to the docs I ...
user84756's user avatar
  • 1,225
51 votes
8 answers
58k views

log4j 2 adding multiple colors to console appender

Hi I just downloaded and configured log4j-2. I am stuck on applying color codes to the SlowConsole console appender. My console appender is like below. <?xml version="1.0" encoding="UTF-8"?> &...
Govinnage  Rasika Perera's user avatar
51 votes
7 answers
72k views

Where to put formatMsgNoLookups in the Log4j XML configuration file

I configure my Log4j with an XML file. Where should I add the formatMsgNoLookups=true? <?xml version="1.0" encoding="UTF-8"?> <!-- Upload files compare config --> <...
Ben's user avatar
  • 2,791
50 votes
9 answers
71k views

Load Log4j2 configuration file programmatically

I want to load Log4j2 XML configuration file programmatically from my application. Tried this: ConfigurationSource source = new ConfigurationSource(); source.setLocation(logConfigurationFile); ...
HashimR's user avatar
  • 3,833
48 votes
4 answers
40k views

Using log4j2 with slf4j: java.lang.StackOverflowError

So I have tried following this (non-maven implementation) and requirements in their web site for adding slf4j to log4j. and tried using this code public static void main(String[] args) { ...
Akshay's user avatar
  • 2,695
43 votes
4 answers
34k views

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

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 ...
glts's user avatar
  • 22.1k
41 votes
5 answers
62k views

ERROR StatusLogger Reconfiguration failed: No configuration found for '73d16e93' at 'null' in 'null'

I am using log4j2 the jar files are following: log4j-api-2.14.0.jar log4j-core-2.14.0.jar log4j-slf4j-impl-2.14.0.jar Executing the following line: LogManager.getLogger("com.foo.Bar1"); ...
John F Kanagawa's user avatar
41 votes
9 answers
98k views

How to specify Log4J 2.x config location?

Is there any way to specify Log4J 2.x log4j2.xml file location manually (like DOMConfigurator in Log4J 1.x), without messing with classpath and system properties?
Andrei Petrenko's user avatar
40 votes
1 answer
67k views

How does Log4j2 DefaultRolloverStrategy's max attribute really work?

I've configured a RollingRandomAccessFileAppender with only the OnStartupTriggeringPolicy set, but when I set the max attribute of the DefaultRolloverStrategy to some number, the logs keep generating ...
Ceiling Gecko's user avatar
37 votes
8 answers
70k views

Method getLogger() no longer a member of Logger in log4j2?

I have the log4j-api-2.0.0.jar and log4j-core-2.0.2.jar import into my build path. But somehow the following code were fail: import org.apache.logging.log4j.core.Logger; public class TheClass { ...
huahsin68's user avatar
  • 6,909
33 votes
8 answers
98k views

Time based triggering policy in log4j2

I am trying to create new log files on an hourly basis. I am using TimeBasedTriggerringPolicy of lo4j2 in RollingFileAppender. Below is the sample xml configuration code i have taken from log4j2 ...
user1890780's user avatar
33 votes
2 answers
19k views

LogManager.getLogger() is unable to determine class name on Java 11 [duplicate]

I'm using log4j2 (2.11.1) with Java 11 and attempting to get a Logger object using: private static final Logger LOG = LogManager.getLogger(); (Imported from log4j-api in org.apache.logging.log4j) ...
Daniel Scott's user avatar
  • 7,618
32 votes
1 answer
24k views

Mixing log4j 1.x and log4j 2

I have a new application that is being written using log4j2, to take advantage of some of its new features. One of the libraries it uses is a bit older and was built with log4j 1.x. I'm having a ...
FrustratedWithFormsDesigner's user avatar
32 votes
5 answers
40k views

How to configure log4j 2.x purely programmatically?

How do I configure log4j 2.3 with console appender pure programmatically (no configuration files of any format)? Basically I'm looking for 2.x version of this 1.x code. In my classes I would then ...
PM 77-1's user avatar
  • 13.1k
32 votes
4 answers
29k views

Log4j2 configuration not found when running standalone application built by shade plugin

I have application which when I run from maven log4j2 it is working: mvn exec:java -Dexec.args=... but when I run jar as standalone application then it shows error: java -jar log: ERROR ...
hudi's user avatar
  • 16k
31 votes
6 answers
50k views

Log4j2 - configuring

I am trying to adopt Log4j2 in my new project, but I get my logs in catalina.out, and the first one is always: ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger. It ...
Ibolit's user avatar
  • 9,466
31 votes
3 answers
54k views

Log4j 2 doesn't support log4j.properties file anymore?

I am running an example using log4j 2.0-rc1 and log4j.properties file, but log4j lib always runs it with the default configuration (log level, appender, etc). I also tried changing the name to log4j2....
emanuell's user avatar
  • 313
31 votes
2 answers
14k views

Difference between AsyncLogger and AsyncAppender in Log4j2

I have understanding that AsyncAppender do the appending job in a separate thread. They use ArrayBlockingQueue for this purpose. AND AsyncLogger uses LMAX disruptor library to move logging event from ...
saurabh goyal's user avatar
31 votes
1 answer
30k views

In log4j 1.2 to log4j 2 migration, what to do with the DailyRollingFileAppender class?

I'm working on migrating a Java project from using log4j 1.2 for logging to using log4j 2. log4j 1.x has a class org.apache.log4j.DailyRollingFileAppender which is mentioned in my project's log4j....
Meng Lu's user avatar
  • 14.3k
29 votes
3 answers
19k views

How to log within shutdown hooks with Log4j2?

Log4j2 also uses shutdown hooks to end it's services. But of course I want to log throughout the whole lifecycle of my application - shutdown included. With Log4j this was no problem. Now it seems to ...
Martin's user avatar
  • 637
29 votes
4 answers
44k views

slf4j & log4j2 maven setup query

I am using log4j2 and slf4j in my project & using maven for the build. I am using the following pom file (releveant dependencies shown only) but I am getting the error copied below with this pom ...
user avatar
28 votes
8 answers
68k views

How can I change the default location of log4j2.xml in Java Spring Boot?

Log4j2 is working nicely with Spring Boot through the log4j2.xml configuration file in the root classpath, exactly as the documentation states. When trying to move this file to a different location ...
Michele Palmia's user avatar
28 votes
5 answers
68k views

Migrating from log4j to log4j2 - properties file configuration

I have a Java application which is using log4j configured as below. log4j.properties: log4j.rootLogger=INFO, R log4j.appender.R = org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File = /...
Raju Guduri's user avatar
  • 1,277
28 votes
2 answers
20k views

How to set the log level on a class in log4j2 properties

In log4j I could specify a class in the properties file to log at the debug level like this: log4j.logger.com.mycompany.mypackage.ClassName=DEBUG How do I do this in log4j2? Note I still need to use ...
sproketboy's user avatar
  • 9,145
27 votes
1 answer
14k views

What is a sample default config file in YAML for log4j2?

The documentation for log4j2 configuration provides a nice sample XML document equivalent to the default configuration: <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN">...
sea-rob's user avatar
  • 2,295
27 votes
2 answers
24k views

Configuring log4j2 and log4j using a single log4j2 xml file

I've migrated my application to log4j 2, and I've configured it via log4j2.xml However, some of the libraries I'm using depend on log4j 1. If I run the application using: -Dlog4j.configurationFile=...
Justin Wong's user avatar
  • 1,485
27 votes
2 answers
15k views

Why is Logback the default logging framework in Spring Boot? [closed]

I've tried to search on Spring documentation + articles on the internet + questions from Stackoverflow but I didn't find any information about it. For me the configuration of Log4J2 (especially the ...
OmriYaHoo's user avatar
  • 605
26 votes
5 answers
18k views

How to colorize Log4j2 output on console in intelliJ?

I've tried to change the config file to like below but still, the output is plain white. How can I change it to any color? Like different color for each level. Code: import org.apache.log4j.*; ...
user2962142's user avatar
  • 1,996
26 votes
4 answers
66k views

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, ...
Steph's user avatar
  • 2,155
26 votes
2 answers
17k views

My log4j2 log file always have double output of each line. How can I stop the duplication please?

My log4j2 log file always has double output of each line. How can I stop the duplication please? <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN&...
tsquare's user avatar
  • 279
26 votes
4 answers
21k views

Reload log4j2 configuration on demand

I have my log4j2.xml config file set to be checked every 30 seconds: <Configuration status="WARN" monitorInterval="30"> ... </Configuration> Is it possible to programmatically tell ...
jamp's user avatar
  • 2,227
26 votes
2 answers
17k views

BasicConfigurator replacement in log4j2

I am working on a log4j 1 to log4j 2 migration. Inside a AppConfigInitializer file we use something like this - BasicConfigurator.configure(consoleAppender); What shall I replace this with to get ...
Andy897's user avatar
  • 7,013
26 votes
4 answers
54k views

Dynamically add appender with slf4j and log4j2

I want to dynamically create an appender and add it to a logger. However, this seems not to be possible with slf4j. I can add my appender to a log4j logger but then I fail to retrieve the logger with ...
Daniele Torino's user avatar

1
2 3 4 5
89