log4j文件配置资源

本文介绍如何配置log4j,使其能在项目中自动创建名为log4j.log的文件,并详细记录日志信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

### set log level ###
log4j.rootLogger=debug,stdout,C
### consle ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %n %d %p %[l] %m %n
###out file###
log4j.appender.C=org.apache.log4j.DailyRollingFileAppender
log4j.appender.C.File=./log4j.log
log4j.appender.C.Append=true
log4j.appender.C.Threshold=Debug
log4j.appender.C.layout=org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern= %n %d %p %[l] %m %n

可自动在项目下创建文件log4j.log并记录日志

内容效果如下:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver] 

 2021-09-29 09:56:16,082 DEBUG %[l] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@123772c4 

 2021-09-29 09:56:16,398 DEBUG %[l] Loaded 3 bean definitions from class path resource [spring-jdbc.xml] 

 2021-09-29 09:56:16,458 DEBUG %[l] Creating shared instance of singleton bean 'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0' 

 2021-09-29 09:56:16,545 DEBUG %[l] Found key 'driver' in PropertySource 'localProperties' with value of type String 

 2021-09-29 09:56:16,546 DEBUG %[l] Found key 'url' in PropertySource 'localProperties' with value of type String 

 2021-09-29 09:56:16,546 DEBUG %[l] Found key 'user' in PropertySource 'localProperties' with value of type String 

 2021-09-29 09:56:16,546 DEBUG %[l] Found key 'password' in PropertySource 'localProperties' with value of type String 

 2021-09-29 09:56:16,554 DEBUG %[l] Creating shared instance of singleton bean 'dataSource' 

 2021-09-29 09:56:16,569 WARN %[l] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring-jdbc.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver] 

运行输出:

log4j:ERROR Unexpected char [[] at position 11 in conversion patterrn.
log4j:ERROR Unexpected char [[] at position 11 in conversion patterrn.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值