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
87
votes
7 answers

How to send java.util.logging to log4j?

I have an existing application which does all of its logging against log4j. We use a number of other libraries that either also use log4j, or log against Commons Logging, which ends up using log4j under the covers in our environment. One of our…
matt b
  • 138,234
  • 66
  • 282
  • 345
86
votes
12 answers

log4j:WARN No appenders could be found for logger in web.xml

I already put the log4jConfigLocation in web.xml, but I still get the following warning: log4j:WARN No appenders could be found for logger ⤦ ⤥ (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system…
cometta
  • 35,071
  • 77
  • 215
  • 324
84
votes
9 answers

Logging in Java and in general: Best Practices?

Sometimes when I see my logging code I wonder if I am doing it right. There might be no definitive answer to that, but I have the following concerns: Library Classes I have several library classes which might log some INFO messages. Fatal Errors are…
Malax
  • 9,436
  • 9
  • 48
  • 64
82
votes
9 answers

log4j logging twice

I am using log4j to log error and other system information. but come of the info logged twice at INFO level. public static void main(final String... args) throws Exception { LOGGER.info("program started"); try { // try body codes …
Talha Bin Shakir
  • 2,563
  • 10
  • 38
  • 54
81
votes
5 answers

Creating multiple log files of different content with log4j

Is there a way to configure log4j so that it outputs different levels of logging to different appenders? I'm trying to set up multiple log files. The main log file would catch all INFO and above messages for all classes. (In development, it would…
Daniel
80
votes
1 answer

Difference between slf4j-log4j12 and log4j-over-slf4j

What's the difference between slf4j-log4j12 and log4j-over-slf4j and when should each be used? org.slf4j slf4j-log4j12 1.7.12
Kumar Sambhav
  • 7,503
  • 15
  • 63
  • 86
80
votes
10 answers

Log4j, configuring a Web App to use a relative path

I have a java webapp that has to be deployed on either Win or Linux machines. I now want to add log4j for logging and I'd like to use a relative path for the log file as I don't want to change the file path on every deployment. The container will…
Iker Jimenez
  • 7,105
  • 9
  • 49
  • 46
80
votes
18 answers

Java Log Viewer

Unfortunately, sometimes the only way to debug a program is by going through its long log files. I searched for a decent log viewer for a while now, and haven't found a real solution. The only program that seemed to be most appropriate was Chainsaw…
Nadav
  • 1,792
  • 2
  • 16
  • 20
79
votes
7 answers

Are there technical reasons to prefer using logback instead of log4j?

Should new projects use logback instead of log4j as a logging framework ? Or with other words :'Is logback better than log4j (leaving the SLF4J-'feature' of logback beside)?'
TimmiB
78
votes
17 answers

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 configuration: logging only errors to the…
Jeff Maass
  • 3,632
  • 3
  • 26
  • 30
78
votes
8 answers

log4j not printing the stacktrace for exceptions

I am using log4j with tomcat. When I log exceptions in my JSPs, servlets: private Logger _log = Logger.getLogger(this.getClass()); ... try{...} catch (Exception e) { _log.error("Error refreshing all prices", e); } I only get the first line of…
Ryan
  • 3,924
  • 6
  • 46
  • 69
75
votes
5 answers

how to make log4j to write to the console as well

Is there any way to tell to log4j to write its log to the file and to the console? thanks there are my properties: log4j.rootLogger=DEBUG,console,R log4j.rootLogger=INFO,…
fatnjazzy
  • 6,070
  • 12
  • 57
  • 83
75
votes
10 answers

log4j redirect stdout to DailyRollingFileAppender

I have a java app that uses log4j. Config: log4j.rootLogger=info,…
letronje
  • 9,002
  • 9
  • 45
  • 53
74
votes
2 answers

How can I create 2 separate log files with one log4j config file?

I can't figure out how to configure my log4j so that my debugLog and my reportsLog are separate from each other (not additive). Why is it, that in the configuration below, the reportsLog is always empty? log4j.rootLogger=TRACE, stdout,…
djangofan
  • 28,471
  • 61
  • 196
  • 289
73
votes
11 answers

Setting a log file name to include current date in Log4j

I would like to set the log file name for a log4j and log4net appender to have the current date. We are doing Daily rollovers but the current log file does not have a date. The log file name format would be logname.2008-10-10.log Anyone know the…
Tim
  • 1,478
  • 1
  • 17
  • 20