java中怎么编写操作日志,并将每一步操作输入到数据库中

这是把日志打印到文件,操作到数据库里还需要你自己具体弄
1.将log4j-1.2.14.jar加入你的项目中;
2.在src/下创建log4j.properties|log4j.xml文件;
3.在web.xml中配置log4j的信息,如下:

log4jConfigLocation
/WEB-INF/classes/log4j.properties


org.springframework.web.util.Log4jConfigListener

4.在项目webroot下创建你想要保存日志文件的文件夹及文件,如webroot/logs/web_app.log;
具体log4j.properties文件,给你一个示例吧,如下:
log4j.rootLogger=INFO, stdout, logfile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
https://www.360docs.net/doc/9a17584309.html,yout=org.apache.log4j.PatternLayout
#https://www.360docs.net/doc/9a17584309.html,yout.ConversionPattern=%d %p [%c] - %m%n
https://www.360docs.net/doc/9a17584309.html,yout.ConversionPattern=- %m%n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=${webapp.root}/logs/webapp.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex=3
# Pattern to output: date priority [category] - message
https://www.360docs.net/doc/9a17584309.html,yout=org.apache.log4j.PatternLayout
https://www.360docs.net/doc/9a17584309.html,yout.ConversionPattern=%d %p [%c] - %m%n

https://www.360docs.net/doc/9a17584309.html,.opensymphony.xwork2=ERROR

# Control logging for other open source packages
https://www.360docs.net/doc/9a17584309.html,.springframework=ERROR
https://www.360docs.net/doc/9a17584309.html,.quartz=ERROR
https://www.360docs.net/doc/9a17584309.html,.sf.ehcache=ERROR
https://www.360docs.net/doc/9a17584309.html,.sf.navigator=ERROR
https://www.360docs.net/doc/9a17584309.html,mons=ERROR
https://www.360docs.net/doc/9a17584309.html,.apache.struts=ERROR

# Struts OgnlUtil issues unimportant warnings
https://www.360docs.net/doc/9a17584309.html,.opensymphony.xwork2.util.OgnlUtil=error
https://www.360docs.net/doc/9a17584309.html,.opensymphony.xwork2.ognl.OgnlValueStack=error
具体写法可根据自己的项目进行配置。

相关文档
最新文档