Title recommends that you set the log level to error. This avoids storing too much data in the data.
1 logback configuration file (see below)
<?XML version= "1.0" encoding= "UTF-8"?><ConfigurationScan= "true"> <Appendername= "STDOUT"class= "Ch.qos.logback.core.ConsoleAppender"> <Encoder> <pattern>%D{HH:MM:SS} [%thread]%-5level%logger{36}-%msg%n</pattern> </Encoder> </Appender> <!--write log to log file - <Appendername= "FILE"class= "Ch.qos.logback.core.FileAppender"> <file>${catalina.base}/logs/cnsurvey-order-ws.log</file> <Append>True</Append><!--Log Append - <Encoder> <pattern>%D{HH:MM:SS} [%thread]%-5level%logger{36}-%msg%n</pattern> </Encoder> </Appender> <!--write logs to the database - <Appendername= "Db-classic-mysql-pool"class= "Ch.qos.logback.classic.db.DBAppender"> <Connectionsourceclass= "Ch.qos.logback.core.db.DataSourceConnectionSource"> <DataSourceclass= "Org.apache.commons.dbcp.BasicDataSource"> <Driverclassname>Com.mysql.jdbc.Driver</Driverclassname> <URL>Jdbc:mysql://localhost:3306/cbs_ifs_order?characterencoding=utf-8</URL> <username>Root</username> <Password>Root</Password> </DataSource> </Connectionsource> </Appender> <Root Level= "ERROR"> <Appender-refref= "STDOUT" /> <Appender-refref= "FILE" /> <Appender-refref= "Db-classic-mysql-pool" /> </Root></Configuration>
If you want the log to be written to the database, you must manually add additional database tables (MySQL tests). If no table is specified in MySQL, the data is not written.
Table structure is as follows
BEGIN;DROP TABLE IF EXISTSLogging_event_property;DROP TABLE IF EXISTSlogging_event_exception;DROP TABLE IF EXISTSlogging_event;COMMIT;BEGIN;CREATE TABLElogging_event (timestmpBIGINT not NULL, Formatted_messageTEXT not NULL, Logger_nameVARCHAR(254) not NULL, Level_stringVARCHAR(254) not NULL, Thread_nameVARCHAR(254), Reference_flagSMALLINT, arg0VARCHAR(254), Arg1VARCHAR(254), arg2VARCHAR(254), Arg3VARCHAR(254), Caller_filenameVARCHAR(254) not NULL, Caller_classVARCHAR(254) not NULL, Caller_methodVARCHAR(254) not NULL, Caller_lineCHAR(4) not NULL, event_idBIGINT not NULLAuto_incrementPRIMARY KEY );COMMIT;BEGIN;CREATE TABLELogging_event_property (event_idBIGINT not NULL, Mapped_keyVARCHAR(254) not NULL, Mapped_valueTEXT, PRIMARY KEY(event_id, Mapped_key),FOREIGN KEY(event_id)REFERENCESlogging_event (event_id));COMMIT;BEGIN;CREATE TABLElogging_event_exception (event_idBIGINT not NULL, ISMALLINT not NULL, Trace_lineVARCHAR(254) not NULL, PRIMARY KEY(event_id, i),FOREIGN KEY(event_id)REFERENCESlogging_event (event_id));COMMIT;
Set the log to the error level. will automatically insert error messages into the database
Reference:
Http://logback.qos.ch/manual/appenders.html
http://blog.csdn.net/kimsoft/article/details/16330869
http://blog.csdn.net/jiaincs/article/details/5686287#
Logback Log Write Database (mysql) configuration