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
61
votes
5 answers

How to configure log4j to log different log levels to different files for the same logger

I have a normal INFO level log for application. What I need is to additionally log all ERROR level events to separate error log. I am using configuration like this:
vilmonts
  • 613
  • 1
  • 5
  • 4
61
votes
5 answers

How do you Change a Package's Log Level using Log4j?

I've encountered the following bug: http://issues.apache.org/jira/browse/AXIS2-4363 It states the following: This error only occurs when log level for org.apache.axiom is DEBUG so a workaround is to set log level > DEBUG. My question is HOW…
Ryan Elkins
  • 5,731
  • 13
  • 41
  • 67
60
votes
10 answers

How can I find out what version of Log4J I am using?

As we all know, at least four or five Log4j JAR files end up being in the classpath. How can I tell which version I am using?
markthegrea
  • 3,731
  • 7
  • 55
  • 78
60
votes
14 answers

How to configure log4j to only keep log files for the last seven days?

I have the following logging problem with several Java applications using log4j for logging: I want log files to be rotated daily, like log.2010-09-10 log.2010-09-09 log.2010-09-08 log.2010-09-07 log.2010-09-06 log.2010-09-05 log.2010-09-04 But for…
asmaier
  • 11,132
  • 11
  • 76
  • 103
60
votes
4 answers

Set System Property With Spring Configuration File

Configuration: Spring 2.5, Junit 4, Log4j The log4j file location is specified from a system property ${log.location} At runtime, system property set with -D java option. All is well. Problem / What I Need: At unit test time, system property not…
Steve
  • 655
  • 1
  • 8
  • 8
60
votes
2 answers

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 what if developer forgets to set this property? Then…
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
59
votes
7 answers

Change location of log4j.properties

I want to put all my config files in a /config subfolder of my application directory. Log4j is expecting the log4j.properties file in the root folder of my application. Is there a way to tell log4j where to look for the properties file?
markus
  • 6,258
  • 13
  • 41
  • 68
59
votes
9 answers

Is there a log file analyzer for log4j files?

I am looking for some kind of analyzer tool for log files generated by log4j files. I am looking something more advanced than grep? What are you using for log file analysis? I am looking for following kinds of features: The tool should tell me how…
Juha Syrjälä
  • 33,425
  • 31
  • 131
  • 183
59
votes
1 answer

What is the result of making log4j additivity equals to true or false?

In simple terms what is the result of making additivity="true" or additivity="false" when adding a Log4j configuration for a specific class like this?
user3433510
  • 593
  • 1
  • 4
  • 4
58
votes
5 answers

How to find which library slf4j has bound itself to?

I am using slf4j for logging in my application. I get the purpose of slf4j. I would like to know how to find out which logging-library slf4j is currently binding to. I have log4j in my referenced libraries. I am assuming that slf4j has bound itself…
psykeron
  • 796
  • 1
  • 6
  • 14
57
votes
6 answers

How can I test with junit that a warning was logged with log4j?

I'm testing a method that logs warnings when something went wrong and returns null. something like: private static final Logger log = Logger.getLogger(Clazz.class.getName()); .... if (file == null || !file.exists()) { // if File not found …
Asaf
  • 2,480
  • 4
  • 25
  • 33
57
votes
2 answers

Log4j2 why would you use it over log4j?

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, log4j2 is advertised as simpler to configure, but its…
Scott Neville
  • 848
  • 1
  • 7
  • 14
57
votes
3 answers

Which Android logging framework to use?

My question seems to be easily answerable, but there are several good solutions. I like to choose the 'best' one. Available frameworks (feel free to suggest more): Androlog SLF4J Android Log4J - Android Pros/Cons: Androlog: Pro: Similar to…
Marcell
  • 973
  • 1
  • 6
  • 13
56
votes
5 answers

Is there a need to do a if(log.isDebugEnabled()) { ... } check?

is there a need to do an explicit if(log.isDebugEnabled()) { ... } check? I mean i have seen some post mentioning that log.debug("something") does an implicit call to see if debug mode logging has been enabled, before it does the logging. Am i…
Oh Chin Boon
  • 23,028
  • 51
  • 143
  • 215
56
votes
2 answers

log4j - set different loglevel for different packages/classes

I use log4j for logging and i want to print all logger.debug statements in a particular class / selected package. i set the cfg as below> log4j.category.my.pkg=info log4j.category.my.pkg.ab.class1=debug but still only info messages are shown.. is…
jch
  • 1,155
  • 3
  • 14
  • 27