重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
一:pom.xml配置:去掉Spring boot 默认的spring-boot-starter-logging,引入spring-boot-starter-log4j2
创新互联是一家专注于成都做网站、成都网站制作、成都外贸网站建设与策划设计,稷山网站建设哪家好?创新互联做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:稷山等地区。稷山做网站价格咨询:13518219792org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-logging org.springframework.boot spring-boot-starter-log4j2
二:应用配置application.yaml
# logging logging: config: classpath:log4j2.xml
三:log42j.xml配置
D:/logs [%-5p] [%d{yyyy-MM-dd HH:mm:ss SSS}] %c - %m%n [%-5p] [%d{yyyy-MM-dd HH:mm:ss SSS}] %c - %m%n [%-5p] [%d{yyyy-MM-dd HH:mm:ss SSS}] %c - %m%n [%-5p] [%d{yyyy-MM-dd HH:mm:ss SSS}] %c - %m%n
四:Druid配置
# mysql,druid spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/upin_charge?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 username: username: password: password: druid: # 连接池的配置信息 initial-size: 10 max-active: 100 min-idle: 10 max-wait: 60000 # 打开PSCache,并且指定每个连接上PSCache的大小 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 time-between-eviction-runs-millis: 60000 # 配置一个连接池中最小生存的时间,单位是毫秒 min-evictable-idle-time-millis: 300000 validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false #配置DruidStatViewServlet stat-view-servlet: enabled: true url-pattern: /druid/* #login-username: admin #login-password: admin # # 配置监控统计拦截的filters,去掉后,监控界面sql无法统计,'wall'用于防火墙 filters: stat,wall,log4j2 filter: stat: log-slow-sql: true slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true log4j2: enabled: true result-set-log-enabled: true statement-executable-sql-log-enable: true statement-create-after-log-enabled: false statement-close-after-log-enabled: false result-set-open-after-log-enabled: false result-set-close-after-log-enabled: false
五:日志文件查看
[DEBUG] [2019-08-06 16:58:20 570] druid.sql.Statement - {conn-10010, pstmt-20000} created. SELECT push_id,uuid,user_id,user_name,msg_type,msg_object,msg_title,msg_content,status,read_status,read_date,receive_date,receive_user_id,create_date FROM upin_msg.msg_push_info WHERE status='01' [DEBUG] [2019-08-06 16:58:20 577] druid.sql.Statement - {conn-10010, pstmt-20000} Parameters : [] [DEBUG] [2019-08-06 16:58:20 577] druid.sql.Statement - {conn-10010, pstmt-20000} Types : [] [DEBUG] [2019-08-06 16:58:20 595] druid.sql.Statement - {conn-10010, pstmt-20000} executed. SELECT push_id,uuid,user_id,user_name,msg_type,msg_object,msg_title,msg_content,status,read_status,read_date,receive_date,receive_user_id,create_date FROM upin_msg.msg_push_info WHERE status='01' [DEBUG] [2019-08-06 16:58:20 595] druid.sql.Statement - {conn-10010, pstmt-20000} executed. 19.4173 millis. SELECT push_id,uuid,user_id,user_name,msg_type,msg_object,msg_title,msg_content,status,read_status,read_date,receive_date,receive_user_id,create_date FROM upin_msg.msg_push_info WHERE status='01' [DEBUG] [2019-08-06 16:58:20 601] druid.sql.ResultSet - {conn-10010, pstmt-20000, rs-50000} Result: [2, null, 1, test, 01, test, null, test, 01, 00, null, null, null, 2019-08-05 13:41:12.0] [DEBUG] [2019-08-06 16:58:20 603] druid.sql.ResultSet - {conn-10010, pstmt-20000, rs-50000} Result: [3, null, 1, test, 01, test, null, test, 01, 00, null, null, null, 2019-08-05 13:52:05.0] [DEBUG] [2019-08-06 16:58:20 603] druid.sql.ResultSet - {conn-10010, pstmt-20000, rs-50000} Result: [4, null, 1, test, 01, test, null, test, 01, 00, null, null, null, 2019-08-05 13:53:50.0] [DEBUG] [2019-08-06 16:58:20 603] druid.sql.ResultSet - {conn-10010, pstmt-20000, rs-50000} Result: [5, null, 1, test, 01, test, null, test, 01, 00, null, null, null, 2019-08-06 10:41:10.0] [DEBUG] [2019-08-06 16:58:20 604] druid.sql.ResultSet - {conn-10010, pstmt-20000, rs-50000} Result: [6, null, 1, test, 01, test, null, test, 01, 00, null, null, null, 2019-08-06 13:49:58.0] [DEBUG] [2019-08-06 16:58:20 605] druid.sql.Statement - {conn-10010, pstmt-20000} clearParameters. [DEBUG] [2019-08-06 16:58:20 608] druid.sql.Statement - {conn-10010, pstmt-20000} Parameters : [] [DEBUG] [2019-08-06 16:58:20 608] druid.sql.Statement - {conn-10010, pstmt-20000} Types : []