4 手动集成
1. 添加依赖
application层添加业务日志接口模块依赖
<dependency>
<groupId>org.openkoala.businesslog</groupId>
<artifactId>koala-businesslog-api</artifactId>
<version>4.0.0</version>
</dependency>
web层添加业务日志实现模块依赖
<dependency>
<groupId>org.openkoala.businesslog</groupId>
<artifactId>koala-businesslog-impl</artifactId>
<version>4.0.0</version>
</dependency>
2. 创建LogFilter类
例如com.xiaokaceng.demo.web.controller.businesslog.LogFilter.java
package com.xiaokaceng.demo.web.controller.businesslog;
import org.openkoala.businesslog.utils.BusinessLogServletFilter;
import javax.servlet.*;
public class LogFilter extends BusinessLogServletFilter {
/**
* 将需要用到的信息放入日志上下文
* @param req
* @param resp
* @param chain
*/
@Override
public void beforeFilter(ServletRequest req, ServletResponse resp, FilterChain chain) {
addIpContext(getIp(req));
// TODO 需要自己实现获取用户名
addUserContext("xxx");
}
public void init(FilterConfig filterConfig) throws ServletException {
//To change body of implemented methods use File | Settings | File Templates.
}
public void destroy() {
//To change body of implemented methods use File | Settings | File Templates.
}
}
注意:当前用户需根据系统实现来获取
3. 创建DefaultBusinessLogController类
|
4. 配置web.xml
<filter>
<filter-name>LogFilter</filter-name>
<filter-class>com.xiaokaceng.demo.web.controller.businesslog.LogFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LogFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
5. 类路径下创建koala-businesslog.properties
pointcut=execution(* org.openkoala.example.application.impl.*.*(..)) #日志开关 kaola.businesslog.enable=true #日志导出器 businessLogExporter=org.openkoala.businesslog.utils.BusinessLogExporterImpl #数据库设置 log.db.jdbc.driver=${db.jdbcDriver} log.db.jdbc.connection.url=${db.connectionURL} log.db.jdbc.username=${db.username} log.db.jdbc.password=${db.password} log.db.jdbc.dialect=${hibernate.dialect} log.hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto} log.hibernate.show_sql=${hibernate.show_sql} log.db.Type=${db.Type} db.generateDdl=${generateDdl} log.maximumConnectionCount=3000 log.minimumConnectionCount=100 #线程池配置 #核心线程数 log.threadPool.corePoolSize=100 #最大线程数 log.threadPool.maxPoolSize=3000 #队列最大长度 log.threadPool.queueCapacity=2000 #线程池维护线程所允许的空闲时间 log.threadPool.keepAliveSeconds=300 #线程池对拒绝任务(无线程可用)的处理策略 log.threadPool.rejectedExecutionHandler=java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy |
6. 添加扫描包路径
persistence-context.xml的packagesToScan节点添加:
<value>org.openkoala.businesslog.model</value>
7. 引入Spring配置
db-context.xml添加配置:
<import resource="classpath*:koala-businesslog-shared-persistence.xml"></import>
root.xml添加配置:
<import resource="classpath*:koala-businesslog-aop.xml"></import>
8. 剩余集成请参考使用教程
说明:
- 以后插件会提供一键集成功能,无需手动集成
- 第三方项目集成较为复杂,有较多技术约束