Output the log configuration of javalog4j to mysql.

Source: Internet
Author: User

Output the log configuration of javalog4j to mysql.

Log4j supports outputting logs to files, databases, and even remote servers. This time I will share with you how to output logs to mysql.

(1) The configuration of log4j. properties is as follows:

Log4j. rootLogger = ERROR, appender1, appender2

Log4j. appender. appender1 = org. apache. log4j. leleappender
Log4j. appender. appender1.layout = org. apache. log4j. PatternLayout
Log4j. appender. appender1.layout. ConversionPattern = % d {yyyy-MM-dd HH: mm: ss: SSS} [% p]: % m % n


Log4j. appender. appender2 = org. apache. log4j. jdbc. JDBCAppender
Log4j. appender. appender2.driver = com. mysql. jdbc. Driver
Log4j. appender. appender2.URL = jdbc: mysql: // localhost: 3306/zuidaima_log4j_write_mysql? UseUnicode = true & characterEncoding = UTF-8
Log4j. appender. appender2.user = root
Log4j. appender. appender2.password = 111111
Log4j. appender. appender2. SQL = insert into zuidaima_log (create_time, log) VALUES ('% d {yyyy-MM-dd hh: mm: ss}', '% c % p % m % n ')
Log4j. appender. appender2.layout = org. apache. log4j. PatternLayout

(2) mysql table creation statement

 

create database `zuidaima_log4j_write_mysql`;use `zuidaima_log4j_write_mysql`;CREATE TABLE `zuidaima_log` (  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,  `create_time` datetime NOT NULL,  `log` varchar(200) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

 

(3) Running instance:


Related Article

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.