手册的配置,只能记录struts2的,不能记录hibernate;
https://www.yiibai.com/struts_2/struts-2-log4j-integration-example.html
log4语法讲解的很清晰
http://blog.sina.com.cn/s/blog_5ed94d710101go3u.html
hibernate配置,但是很多信息打印出来;hibernate的配置信息,sql语句等;
# Log everything. Good for troubleshooting log4j.logger.org.hibernate=INFO
# Log all JDBC parameters log4j.logger.org.hibernate.type=ALL
原文出自【易百教程】,商业转载请联系作者获得授权,非商业转载请保留原文链接:
https://www.yiibai.com/hibernate/hibernate-logging-by-log4j-using-properties-file.html
struts2和hibernate联合使用log4日志
https://blog.csdn.net/u010503822/article/details/78696669
博主的意思也是struts2 的err信息,sql的debug,总的级别是debug;
DEBUG,INFO,WARN,ERROR
日志函数;低级别的函数不会在高级配置中出现
Logger logger = Logger.getLogger(WelcomeAction.class);
logger.info("info---");
logger.warn("warn---");
// logs debug message
if (logger.isDebugEnabled()) {
logger.debug("execute()!");
}
logger.error("This is Error message", new Exception("Testing"));
最后;附上系统全部出错配置和sql的信息配置;我使用的,测试可用的,日志信息是error和hibernate的debug信息;
文本的内容也很少。另外,数据库的权限配置,也可以增加系统的安全性。。
#DEBUG,INFO,WARN,ERROR
log4j.rootLogger=ERROR, stdout, file
#hibernate的日志配置
log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN
log4j.logger.org.hibernate=WARN
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
#文件和控制台的配置;error级别
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
#org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生一个新的文件)
# Redirect log messages to a log file, support rolling backup file.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/yourPrograme.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} %-5p %c{1}\:%L - %m%n
第二次配置,出错级别;hibernate为debug
log4j.rootLogger=ERROR,console,R
#console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.threshold=DEBUG
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%5p] - %c -%F(%L) -%m%n
#file
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.Append=true
log4j.appender.R.File=${catalina.home}/logs/babasport.log
log4j.appender.R.Threshold=ERROR
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%5p] - %c -%F(%L) -%m%n
log4j.appender.R.MaxFileSize=10MB
#struts2
log4j.logger.com.opensymphony.xwork2=ERROR
log4j.logger.org.apache.struts2=ERROR
log4j.logger.org.apache.struts2.convention=ERROR
log4j.logger.com.opensymphony.xwork2.util.finder=ERROR
#hibernate
log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN
log4j.logger.org.hibernate=WARN
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
#other
log4j.logger.com.opensymphony.oscache=INFO
log4j.logger.net.sf.navigator=ERROR
log4j.logger.org.apache.commons=ERROR
log4j.logger.org.displaytag=ERROR
log4j.logger.org.apache.velocity=FATAL
#jsp off
log4j.logger.org.apache.jasper.servlet=ERROR
log4j.logger.org.apache.catalina.core=ERROR