将log4j的日志配置输出到mysql中

jopen的头像 jopen 1016 2015-01-19 11:38 1

 基本信息

× 1   

浏览数: 9154

分享时间: 4 年 前

3

log4j可以支持将log输出到文件,数据库,甚至远程服务器,这次给大家分享下如何输出到mysql中。

(1)log4j.properties的配置内容如下:

log4j.rootLogger=ERROR,appender1,appender2

log4j.appender.appender1=org.apache.log4j.ConsoleAppender
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建表语句

    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;  


12 [下一页]

  • opennejack的头像 opennejack 2017-08-12 09:58 代码数:0

    好好好,!!!

  • ossaa的头像 ossaa 2018-10-17 18:04 代码数:0

    Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work.

    Enjoy Mexico Villa Rentals in Cabo San Lucas

  • zzxzhy的头像 zzxzhy 2017-12-21 05:57 代码数:0

    学习性很高,值的收藏

  • jerrykome的头像 jerrykome 2019-01-03 23:09 代码数:0

    Amazing stuff. Truly wonderful and a sensational post. Looking forward to the regular sharing. Smoke And Vape Shop South Elgin - UncleStusSmokeVape

  • jerrykome的头像 jerrykome 2019-01-03 23:10 代码数:0

    Amazing stuff. Truly wonderful and a sensational post. Looking forward to the regular sharing. Smoke And Vape Shop South Elgin - UncleStusSmokeVape

  • ossaa的头像 ossaa 2018-11-12 20:54 代码数:0

    I am no expert, but I believe you just made an excellent point. You certainly fully understand what you are speaking about, and I can truly get behind that. 

    Bücher für plastische Chirurgie

  • JackP的头像 JackP 2018-11-13 13:11 代码数:0

    It was nice to learn about Output log4j log configuration to MySQL along with table statement which can support the output of the log to the file, database, set up the remote server, this time for everyone to share how to output to MySQL.

    Jack,

    An essay writer who helps students in writing their essay by offering essay help at Quality Dissertation with pass guarantee.

  • cixexey的头像 cixexey 2018-09-30 00:29 代码数:0

    i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future.. https://www.butcherblockco.com/portable-kitchen-island 

  • cixexey的头像 cixexey 2018-09-30 22:59 代码数:0

    I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me  jovell condo

  • jhoneila的头像 jhoneila 2018-12-01 16:21 代码数:0

    Thanks  for every other informative site. The place else may just I get that kind of information written in such an ideal means? I have a venture that I’m just now operating on, and I have been on the look out for such information. affinity at serangoon showflat

您的评论: