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).
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.
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}
Thank you.
I figured out how to do this:
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.