I am using the log4j API for logging in my Java based Tomcat application and using version 1.2.14 (log4j-1.2.14.jar). The problem is that it creates more logs in the catalina.out
log file, which are very micro level logs and not required for me. I am facing the problem of memory in my machine, and I want to reduce the logging of the log4j logger. Is there a way to reduce logs such that I can save my memory?
Asked
Active
Viewed 5,143 times
1

Peter Mortensen
- 30,738
- 21
- 105
- 131

Bhavik Ambani
- 6,557
- 14
- 55
- 86
-
How is log4j currently configured in your application? Show us the config file, please – Alfabravo Mar 01 '12 at 13:07
-
There is not any configuration, I have just used that jar as my API for logging. – Bhavik Ambani Mar 01 '12 at 13:08
2 Answers
4
Setting a properties or a XML configuration file will allow you to control log4j output as stated in the log4j manual.
An example of the properties file would be like this
# Root logger option
log4j.rootLogger=**ERROR**, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\mylogging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
Note the rootLogger parameter, as it controls how much information you get, whether you need only error messages or everything down to information messages.
In order to set it properly, look in Log4j Configuration Using Properties File for extra information as you can also use it in the XML version (see Multiple Appenders Using XML File). Tip: place it in src/ or in project root.

Peter Mortensen
- 30,738
- 21
- 105
- 131

Alfabravo
- 7,493
- 6
- 46
- 82
1
You will have to look at CATALINA_HOME/conf folder for log4j.properties and raise the logging level to say, warn or error depending upon your needs

Sumit Bisht
- 1,507
- 1
- 16
- 31
-
-
I am unable to comprehend your problem. Could you provide the file contents as requested by either Alfabravo or me in your question? – Sumit Bisht May 03 '12 at 07:54