### 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.