log4j JDBCAppender rotate table name

前端 未结 3 1723
旧巷少年郎
旧巷少年郎 2021-01-22 13:31

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 som

3条回答
  •  长发绾君心
    2021-01-22 13:40

    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, ...
    

    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.

提交回复
热议问题