Questions tagged [log4j]

log4j is a popular Java-based logging utility. It is a project of the Apache Software Foundation and is licensed under The Apache Software License, Version 2.0

Apache Log4j is a Java-based logging utility. It is a project of the Apache Software Foundation. Log4j is one of several Java Logging Frameworks.

Log4j in written in Java and also support cross platform and available with Apache License 2.0 License.

Log4j helps programmers output log statements from their programs. The log statements can be configured to be output to a variety of locations including the console, files and email. Log4j is a hierarchical logging utility which makes it possible to change the granularity at which log statements are output.

It is common practice to use the program's package structure as the basis for the hierarchy since the package structure of an application is inherently hierarchical and usually correlates to the hierarchy of the program code.

Log4j2.x changes the API and is no longer downward compatible to log4j1.x

Official Website:

Useful Links:

stackoverflow posts

See Also

Latest release log4j1: 1.2.17 released on August 5, 2015

Latest release log4j2: 2.13.3 released on 2020-05-10

9578 questions
139
votes
7 answers

If using maven, usually you put log4j.properties under java or resources?

Where should I put the log4j.properties file when using the conventional Maven directories?
user496949
  • 83,087
  • 147
  • 309
  • 426
131
votes
18 answers

Setting log level of message at runtime in slf4j

When using log4j, the Logger.log(Priority p, Object message) method is available and can be used to log a message at a log level determined at runtime. We're using this fact and this tip to redirect stderr to a logger at a specific log level. slf4j…
Edward Dale
  • 29,597
  • 13
  • 90
  • 129
121
votes
7 answers

Eclipse: Referencing log4j.dtd in log4j.xml

I've been using log4j for quite a while now and I usually use this at the top of the log4j.xml (probably just like many others and according to Google this is the way to do it): Obviously this is…
sjngm
  • 12,423
  • 14
  • 84
  • 114
118
votes
8 answers

What's Up with Logging in Java?

Why one would use one of the following packages instead of the other? Java Logging Commons Logging Log4j SLF4j Logback
Loki
  • 29,950
  • 9
  • 48
  • 62
116
votes
1 answer

Where is logback encoder pattern documentation

I've gone through all the documentation of logback and I can't find anywhere the documentation to configure the encoder's pattern when logging, such as: %d{HH:mm:ss.SSS} %-4relative %-5level %logger{35} -…
pakore
  • 11,395
  • 12
  • 43
  • 62
108
votes
3 answers

What is the significance of log4j.rootLogger property in log4j.properties file? What happens if I don't use this property?

What is the significance of log4j.rootLogger property in log4j.properties file? What happens if I don't use this property? Example: # Set root logger level to DEBUG and its only appender to A1. log4j.rootLogger=DEBUG, A1 # A1 is set to be a…
Jitendra
  • 1,193
  • 2
  • 8
  • 7
105
votes
3 answers

What is the difference between Log4j, SLF4J and Logback?

I am little bit confused by these three logger libraries. It seems like that they can do the similar thing in Java logging...
Ev3rlasting
  • 2,145
  • 4
  • 18
  • 31
97
votes
9 answers

Difference between logger.info and logger.debug

What is the difference between logger.debug and logger.info ? When will logger.debug be printed?
Senthilnathan
  • 1,157
  • 2
  • 10
  • 10
96
votes
1 answer

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 ? Almost in all examples here…
Yurii Bondarenko
  • 3,460
  • 6
  • 28
  • 47
93
votes
3 answers

Is it possible to make log4j display which file it used to configure itself?

Question Is it possible to make Log4J display the full path of the file it used for configuration? Background I have a love-hate relationship with log4j. In good times, it's great but when it's not working, it can be one of the most difficult…
gMale
  • 17,147
  • 17
  • 91
  • 116
92
votes
4 answers

Where do I configure log4j in a JUnit test class?

Looking at the last JUnit test case I wrote, I called log4j's BasicConfigurator.configure() method inside the class constructor. That worked fine for running just that single class from Eclipse's "run as JUnit test case" command. But I realize…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
92
votes
6 answers

Disabling Log4J Output in Java

How can one quickly turn off all Log4J output using a log4j.properties file?
cmcginty
  • 113,384
  • 42
  • 163
  • 163
90
votes
6 answers

Configuring Hibernate logging using Log4j XML config file?

I haven't been able to find any documentation on how to configure Hibernate's logging using the XML style configuration file for Log4j. Is this even possible or do I have use a properties style configuration file to control Hibernate's logging? If…
James McMahon
  • 48,506
  • 64
  • 207
  • 283
89
votes
7 answers

How do I set log4j level on the command line?

I want to add some log.debug statements to a class I'm working on, and I'd like to see that in output when running the test. I'd like to override the log4j properties on the command line, with something like…
Kevin Peterson
  • 7,189
  • 5
  • 36
  • 43
88
votes
4 answers

What does threshold mean in Log4J?

I have a log4j properties something like below. Everything that is logged in TextProcessor.log is something above WARN level. I don't understand the threshold that is set here to debug. Can someone explain what the threshold…
javanerd
  • 2,802
  • 4
  • 24
  • 32