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 is a standalone upgrade to Log4j 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.x changes the API and is no longer downward compatible to log4j1.x

See Also

4386 questions
55
votes
5 answers

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 (won't compile): if (arg[0].equals("log") ) { …
Brian Johnson
  • 1,629
  • 5
  • 21
  • 26
52
votes
5 answers

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.xml
daker
  • 3,430
  • 3
  • 41
  • 55
50
votes
4 answers

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 should be able to use a double "$" and a context…
user84756
  • 1,195
  • 2
  • 9
  • 10
49
votes
7 answers

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?
Ben
  • 2,771
  • 6
  • 33
  • 45
49
votes
8 answers

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.
Govinnage Rasika Perera
  • 2,134
  • 1
  • 21
  • 33
49
votes
9 answers

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); Configurator.initialize(null, source); and…
HashimR
  • 3,803
  • 8
  • 32
  • 49
48
votes
3 answers

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) { Logger logger = LoggerFactory.getLogger(Main.class); …
Akshay
  • 2,622
  • 1
  • 38
  • 71
43
votes
4 answers

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 should be possible to associate either an XML Schema or…
glts
  • 21,808
  • 12
  • 73
  • 94
40
votes
9 answers

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
  • 3,922
  • 3
  • 31
  • 53
38
votes
1 answer

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 past that amount indefinitely. Here's my…
Ceiling Gecko
  • 3,104
  • 2
  • 24
  • 33
36
votes
5 answers

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"); using the following VM…
John F Kanagawa
  • 361
  • 1
  • 3
  • 3
35
votes
7 answers

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 { private static Logger log =…
huahsin68
  • 6,819
  • 20
  • 79
  • 113
32
votes
2 answers

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

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) At runtime, I receive the following error: WARNING:…
Daniel Scott
  • 7,418
  • 5
  • 39
  • 58
32
votes
4 answers

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 StatusLogger Unrecognized format specifier [d] ERROR…
hudi
  • 15,555
  • 47
  • 142
  • 246
32
votes
1 answer

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 problem where the new code in the application writes…
FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202