Druid monitoring records in the cache, after reboot can not be retrieved, so need to do persistent, regularly dump the monitoring records into the log file, the implementation steps are as follows:
1. Added configuration in datasource: <!--output monitoring data to log every 10 minutes--< property name = "Timebetweenlogstatsmillis" value = "600000" /> <!--Custom implementation input monitoring data to log--< property name = "Statlogger" ref = "Localstatlogger"/> 2, define bean < Bean id = "Localstatlogger" class = "Com.asia.druid.LocalStatLogger" > </Bean > 3, Class Localstatlogger, overriding API method to implement a custom log storage (source code is also output to the log file, but with its own log library, by reading System.properties in the druid.stat.loggerName to define the corresponding log class library, such as log4j, etc., because I do not know Druid.stat.loggerName How to specify, directly rewrite the ╮(╯▽╰)╭) PublicclassLocalstat LoggerextendsDruiddatasourcestat LoggeradapterImplementsDruiddatasourcestatlogger PublicvoidLog (Druiddatasourcestatvalue Statvalue) 4, log4j.properties, define dump log file location and name log4j.appender.druid= Org.apache.log4j.DailyRollingFileAppender log4j.appender.druid.layout= Org.apache.log4j.PatternLayout log4j.appender.druid.layout.conversionpattern= [Druid]%d [%-15.15t]%-5p%-30.30c{1}-%m%n log4j.appender.druid.file=. /logs/my_druid_ log4j.appender.druid.datepattern= yyyy-mm-dd '. Log ' log4j.appender.druid.append= true Log4j.appender.druid.immediateflush= true
Log4j.logger.com.mycompany.druid= Info,druid >dailyrollingfileappender is able to generate logs by date, the file name of the day is the name of the Rename the file the day before, plus the specified suffix >log4j.logger. The following is the package name, the package under the Logger.info and other methods to take effect, the following log level is not related to Log4j.rootlogger; /LOGS specifies a relative path, relative to the location of the deployment project, such as Tomcat under the Logs folder under Tomcat