更改日志 设为logback,修复错误不打印bug

This commit is contained in:
zxm 2018-06-02 12:48:00 +08:00
parent e753e3c689
commit 73a5a3e3ba
5 changed files with 69 additions and 153 deletions

View File

@ -24,13 +24,6 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<!--去除logback依赖-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -4,13 +4,6 @@ import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter; import com.alibaba.druid.support.http.WebStatFilter;
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor; import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
import org.springframework.aop.support.JdkRegexpMethodPointcut; import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
@ -22,6 +15,11 @@ import org.springframework.context.annotation.Scope;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.filter.DelegatingFilterProxy; import org.springframework.web.filter.DelegatingFilterProxy;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author zhuxiaomeng * @author zhuxiaomeng
* @date 2018/1/2. * @date 2018/1/2.
@ -31,65 +29,65 @@ import org.springframework.web.filter.DelegatingFilterProxy;
@EnableTransactionManagement @EnableTransactionManagement
public class DruidConfig { public class DruidConfig {
@Value("${spring.datasource.url}") @Value("${spring.datasource.url}")
private String url; private String url;
@Value("${spring.datasource.username}") @Value("${spring.datasource.username}")
private String username; private String username;
@Value("${spring.datasource.password}") @Value("${spring.datasource.password}")
private String password; private String password;
@Value("${spring.datasource.filters}") @Value("${spring.datasource.filters}")
private String filters; private String filters;
@Value("${spring.datasource.driver-class-name}") @Value("${spring.datasource.driver-class-name}")
private String driverClassName; private String driverClassName;
@Value("${spring.datasource.initialSize}") @Value("${spring.datasource.initialSize}")
private int initialSize; private int initialSize;
@Value("${spring.datasource.minIdle}") @Value("${spring.datasource.minIdle}")
private int minIdle; private int minIdle;
@Bean @Bean
@Primary @Primary
public DataSource getDataSource(){ public DataSource getDataSource() {
DruidDataSource datasource = new DruidDataSource(); DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url); datasource.setUrl(url);
datasource.setUsername(username); datasource.setUsername(username);
datasource.setPassword(password); datasource.setPassword(password);
datasource.setDriverClassName(driverClassName); datasource.setDriverClassName(driverClassName);
datasource.setInitialSize(initialSize); datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle); datasource.setMinIdle(minIdle);
try { try {
datasource.setFilters(filters); datasource.setFilters(filters);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
}
return datasource;
} }
return datasource;
}
@Bean @Bean
public FilterRegistrationBean filterRegistrationBean() { public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter()); filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns("/*"); filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*,*.html"); filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*,*.html");
DelegatingFilterProxy proxy = new DelegatingFilterProxy(); DelegatingFilterProxy proxy = new DelegatingFilterProxy();
proxy.setTargetFilterLifecycle(true); proxy.setTargetFilterLifecycle(true);
proxy.setTargetBeanName("shiroFilter"); proxy.setTargetBeanName("shiroFilter");
filterRegistrationBean.setFilter(proxy); filterRegistrationBean.setFilter(proxy);
return filterRegistrationBean; return filterRegistrationBean;
} }
@Bean @Bean
public ServletRegistrationBean druidServlet() { public ServletRegistrationBean druidServlet() {
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(); ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
servletRegistrationBean.setServlet(new StatViewServlet()); servletRegistrationBean.setServlet(new StatViewServlet());
servletRegistrationBean.addUrlMappings("/druid/*"); servletRegistrationBean.addUrlMappings("/druid/*");
Map<String, String> initParameters = new HashMap<String, String>(); Map<String, String> initParameters = new HashMap<String, String>();
initParameters.put("resetEnable", "false"); initParameters.put("resetEnable", "false");
initParameters.put("allow", ""); initParameters.put("allow", "");
servletRegistrationBean.setInitParameters(initParameters); servletRegistrationBean.setInitParameters(initParameters);
return servletRegistrationBean; return servletRegistrationBean;
} }
@Bean @Bean
public DruidStatInterceptor getDruidStatInterceptor(){ public DruidStatInterceptor getDruidStatInterceptor(){

View File

@ -1,12 +1,12 @@
server: server:
port: 8072 port: 8081
spring: spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306/lenos?useUnicode=true&characterEncoding=UTF-8 url: jdbc:mysql://localhost:3306/lenos?useUnicode=true&characterEncoding=UTF-8
username: root username: root
# password: 123456 # password: 123456
# password: 1234 password: 123456
password: l123456 # password: l123456
# 使用druid数据源 # 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
@ -32,7 +32,6 @@ spring:
prefer-ip: true prefer-ip: true
url: http://localhost:8082 url: http://localhost:8082
mybatis: mybatis:
type-aliases-package: com.len.entity type-aliases-package: com.len.entity
mapper-locations: classpath*:mapper/*.xml mapper-locations: classpath*:mapper/*.xml
@ -51,13 +50,14 @@ pagehelper:
reasonable: true reasonable: true
supportMethodsArguments: true supportMethodsArguments: true
params: count=countSql params: count=countSql
logging:
level:
com.len.mapper: debug
config: classpath:log4j2.yml
lenosp: lenosp:
uploadPath: ./file/ uploadPath: ./file/
isDayType: false isDayType: false
imagePath: ./image/ imagePath: ./image/
logging:
file: ./logs/lenosp-log.log
level:
com.len.mapper: debug

View File

@ -1,48 +0,0 @@
Configuration:
status: warn
Properties: # 定义变量
Property:
- name: log.path
value: ./logs
- name: project.name
value: lenos-log
Appenders:
Console: #输出到控制台
name: CONSOLE
target: SYSTEM_OUT
ThresholdFilter:
level: info
onMatch: ACCEPT
onMismatch: DENY
PatternLayout:
pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n"
# 输出到文件超过128MB归档
RollingFile:
- name: ROLLING_FILE
ignoreExceptions: false
fileName: ${log.path}/${project.name}.log
filePattern: "${log.path}/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz"
PatternLayout:
pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n"
Policies:
SizeBasedTriggeringPolicy:
size: "128 MB"
DefaultRolloverStrategy:
max: 1000
Loggers:
Root:
level: info
AppenderRef:
- ref: CONSOLE
- ref: ROLLING_FILE
Logger: # 为com.xjj包配置特殊的Log级别方便调试
- name: com.test.dao
additivity: false
level: debug
AppenderRef:
- ref: CONSOLE
- ref: ROLLING_FILE

31
pom.xml
View File

@ -79,11 +79,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId> <artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency> </dependency>
@ -103,7 +99,7 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>druid</artifactId>
<version>1.0.24</version> <version>1.1.10</version>
</dependency> </dependency>
<!--mybatis spring整合包--> <!--mybatis spring整合包-->
@ -163,29 +159,6 @@
<version>1.7.25</version> <version>1.7.25</version>
</dependency> </dependency>
<!--log更换为log4j2-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.10.0</version>
</dependency>
<!--<dependency>-->
<!--<groupId>com.fasterxml.jackson.dataformat</groupId>-->
<!--<artifactId>jackson-dataformat-yaml</artifactId>-->
<!--</dependency>-->
<dependency> <dependency>
<groupId>org.apache.shiro</groupId> <groupId>org.apache.shiro</groupId>