现在的位置: 首页 > 综合 > 正文

log4j日志如何存入数据库

2013年11月13日 ⁄ 综合 ⁄ 共 856字 ⁄ 字号 评论关闭

# This defines the logging level for the rootLogger. It is not required
# if you are going to keep the level at debug as the rootLogger by default
# is at the debug level. The value after the comma is the appender for the
# root and we have given it the name R
#
log4j.rootLogger=debug, R

#
# Since we plan to log to a database, we tell log4j that we will use the
# JDBCAppender. To complete the configuration for this, we need to tell
# some basic things to this appender. Database, Username, password and the
# actual values to log. %m represents the message that will be generated by
# our log statements.
#
log4j.appender.R=org.apache.log4j.jdbc.JDBCAppender
#数据库连接串
log4j.appender.R.URL=jdbc:mysql://localhost/test
log4j.appender.R.user=root
log4j.appender.R.password=
log4j.appender.R.sql=INSERT INTO messages (message) VALUES ('%d - %c - %p - %m')#
# These definea the layout to be used.
#
log4j.appender.R.layout=org.apache.log4j.PatternLayout

上面是log4j的配置文件的内容。

在数据库中建立一个messages表,表中有message字段。 

抱歉!评论已关闭.