Some questions about DBAppender of the logback

Hi,everyone, Following is my logback.xml about implement DBAppender just to storage the log message to mysql database. <appender name="DB" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <driverClass>com.mysql.jdbc.Driver</driverClass> <url>jdbc:MySQL://127.0.0.1:3306/EventDataBase</url> <user>root</user> <password>root</password> </connectionSource> </appender> then: The following is the result ,the log message was storage in the mysql database,but the "timestmp" filed in the table named logging_event ,the timestmp's pattern is not as{HH:mm:ss.SSS} just as the consoleAppender,can I transform it's pattern to {HH:mm:ss:SSS} ? Could you please give me some help?I have tried add <encoder> <pattern>%d{HH:mm:ss.SSS} </pattern></encoder> as the ConsoleAppender's logback.xml,but I failed.

I've never understood why DBAppender logs the time using a long instead of a java.sql.Timestamp. It's quite annoying and I never found a way to change it. What I wound up doing instead to write a SQL function to convert milliseconds to a DATETIME (you can find it on stack overflow) and incorporating that into a view. Thanks, Paul On Mar 14, 2016, at 02:35, Yun He <canalyun@gmail.com<mailto:canalyun@gmail.com>> wrote: Hi,everyone, Following is my logback.xml about implement DBAppender just to storage the log message to mysql database. <appender name="DB" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <driverClass>com.mysql.jdbc.Driver</driverClass> <url>jdbc:MySQL://127.0.0.1:3306/EventDataBase<http://127.0.0.1:3306/EventDataBase></url> <user>root</user> <password>root</password> </connectionSource> </appender> then: The following is the result ,the log message was storage in the mysql database,but the "timestmp" filed in the table named logging_event ,the timestmp's pattern is not as{HH:mm:ss.SSS} just as the consoleAppender,can I transform it's pattern to {HH:mm:ss:SSS} ? Could you please give me some help?I have tried add <encoder> <pattern>%d{HH:mm:ss.SSS} </pattern></encoder> as the ConsoleAppender's logback.xml,but I failed. [https://mail.bjut.edu.cn/?q=compose.output&action=mail.attach&aid=20715&mid=...] _______________________________________________ logback-user mailing list logback-user@qos.ch<mailto:logback-user@qos.ch> http://mailman.qos.ch/mailman/listinfo/logback-user

Hello Yun, DBAppender sends the value returned by System.currentMillis(), a value of type long, as the timestamp value to MySql. There is no pattern to be specified for DBAppender. The output format for the date should be specified at query-time, i.e. in select from... I hope this helps, -- Ceki On 3/14/2016 7:35, Yun He wrote:
Hi,everyone, Following is my logback.xml about implement DBAppender just to storage the log message to mysql database. <appender name="DB" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <driverClass>com.mysql.jdbc.Driver</driverClass> <url>jdbc:MySQL://127.0.0.1:3306/EventDataBase <http://127.0.0.1:3306/EventDataBase></url> <user>root</user> <password>root</password> </connectionSource> </appender>
then: The following is the result ,the log message was storage in the mysql database,but the "timestmp" filed in the table named logging_event ,the timestmp's pattern is not as{HH:mm:ss.SSS} just as the consoleAppender,can I transform it's pattern to {HH:mm:ss:SSS} ? Could you please give me some help?I have tried add <encoder> <pattern>%d{HH:mm:ss.SSS}</pattern></encoder> as the ConsoleAppender's logback.xml,but I failed.
participants (3)
-
Ceki Gulcu
-
Paul Krause
-
Yun He