log4j JDBCAppender旋转表名 [英] log4j JDBCAppender rotate table name

查看:84
本文介绍了log4j JDBCAppender旋转表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功配置了一个使用log4j进行登录的应用程序,以登录到MySQL数据库. (使用org.apache.log4j.jdbc.JDBCAppender).

I have successfully configured an application that uses log4j for it's logging to log into a MySQL database. (Using org.apache.log4j.jdbc.JDBCAppender).

我也有一些Perl应用程序也可以登录数据库.我的perl应用程序已安装,因此数据库表的名称每个月都会更改(log_2010_11,log_2010_10等).在每个月的月底,我都会在刚结束的那个月运行报告脚本,将表转储到外部文件(已压缩并存档),然后删除表.这样,日志数据库的总大小将保持在合理的范围内.

I also have some perl applications that log into the database as well. My perl apps are setup so that the name of the database table changes every month (log_2010_11, log_2010_10 etc). At the end of each month, I run reporting scripts on the month just completed, dump the table to an external file (which gets compressed and archived), and then drop the table. This way the total size of the logging database stays within sensible limits.

我想对log4j做同样的事情,但是似乎没有适合此目的的log4j附加器.

I would like to do the same with log4j, but there does not appear to be a log4j appender suitable for the purpose.

是否可以执行以下操作:

Is it possible to do something like this:

log4j.appender.SQ=org.apache.log4j.jdbc.JDBCRollingAppender

log4j.appender.SQ.Driver=com.mysql.jdbc.Driver

log4j.appender.SQ.URL=jdbc:mysql://localhost:3306/logs_{%year}_{%month}

谢谢.

推荐答案

我想出了如何做到这一点:

I figured out how to do this:

log4j.appender.SQ=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.SQ.Driver=com.mysql.jdbc.Driver
log4j.appender.SQ.URL=jdbc:mysql://localhost:3306/logs
log4j.appender.SQ.sql=INSERT INTO accesslog_%d{yyyy_MM} (date, time, tz, ...

似乎您可以将日期格式的字符串放入SQL语句中,然后JDBCAppender将其展开并登录到核心响应表中.

It appears you can just put date format strings into the SQL statement, and JDBCAppender will expand them and log into the coresponding table.

但是,它不会在新月初创建新表,因此目前我必须手动手动创建表,这远非理想.

However, it will not create new tables at the start of the new month, so currently I have to manualy create the tables beforehand, which is far from ideal.

这篇关于log4j JDBCAppender旋转表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆