How to disable tomcat server console log?

这一生的挚爱 提交于 2021-02-08 04:09:23

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/16732069/how-to-disable-tomcat-server-console-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!