Dump Druid monitoring logs to log file

Source: Internet
Author: User
Tags relative tomcat log4j

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.