简体   繁体   中英

How to disable tomcat server console log?

My log4j.proerties

log4j.rootLogger=DEBUG,R
log4j.appender.R = org.apache.log4j.RollingFileAppender
log4j.appender.R.File = logs/backup.log
log4j.appender.R.Append = true
log4j.appender.R.DatePattern = '.'yyy-MM-dd
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
log4j.additivity.info.release.scheduler=false

My Action class is

private static final Logger logger = Logger.getLogger(LogAction.class);
if(getUname().equals("admin")&&getPwd().equals("123"))
{   
logger.info("Success");
return "su";
}
else
{
  addActionMessage("user name and password incorrectly!");
  logger.info("Failure");
  return "fa";
}

My backup.log file contain the following logs. These logs are coming from tomcat server

a2013-05-24 15:06:44 XmlConfigurationProvider [DEBUG] Loading action configurations 
from:   struts-default.xml
2013-05-24 15:06:44 XmlConfigurationProvider [DEBUG] Loaded action configuration
from:       struts-default.xml
2013-05-24 15:06:44 XmlConfigurationProvider [INFO] Parsing configuration file
[struts-default.xml]
2013-05-24 15:06:44 XmlConfigurationProvider [DEBUG] Loaded type: 
name:xwork   impl:com.opensymphony.xwork2.ObjectFactory
2013-05-24 15:06:44 XmlConfigurationProvider [DEBUG] 
Loaded    type:com.opensymphony.xwork2.ObjectFactory name:struts 

but I want the following format only

2013-05-24 15:06:44 Login successfull.
2013-05-24 15:06:44 Login failure.

and my question is how to avoid unwanted logs write into the log file? And I am using Struts2 and log4j properties.

To turn off unwanted log using log4j configuration properties file via specifying the level for the logger based on the logger instantiated for the given class. For example

log4j.logger.org.apache=OFF,R
log4j.logger.com.opensymphony.xwork2=OFF,R

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM