The Business Log subsystem of the koala platform is a Maven-based project module. The most convenient integration is that Maven is also used for projects. For War Project Integration, please download the jar package by yourself.
Prerequisites
Dependent on Spring
Add Repository
<repositories><repository><id>koala-releases</id><url>http://nexus.openkoala.org/content/repositories/public-releases/</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></repository><repository><id>koala-snapshots</id><url>http://nexus.openkoala.org/content/repositories/public-snapshots/</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories>
Add dependency
<dependency><groupId>org.openkoala.businesslog</groupId><artifactId>koala-businesslog-api</artifactId><version>3.0.0</version></dependency><dependency><groupId>org.openkoala.businesslog</groupId><artifactId>koala-businesslog-impl</artifactId><version>3.0.0</version></dependency>
Add the dependency to the corresponding Pom. XML according to the actual project hierarchy. The Koala project adds the dependency to the application-impl layer.
Create a logfilter class
For example, 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 {/*** put the required information into the log context ** @ Param req * @ Param resp * @ Param chain */@ override public void beforefilter (servletrequest req, servletresponse resp, filterchain chain) {addipcontext (getip (req); // todo needs to obtain the username addusercontext ("XXX") by yourself;} public void Init (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 .}}
Note: The current user needs to obtain the information based on the system implementation.
Configure 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>
Create koala-businesslog.properties under the class path
Pointcut = Execution (* Org. openkoala. example. application. impl. *. *(..)) # log switch kaola. businesslog. enable = true # log export tool businesslogexporter = org. openkoala. businesslog. utils. businesslogexporterimpl # Database setting 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 = 3000log. minimumconnectioncount = 100 # thread pool configuration # Core Thread Count log. threadpool. corepoolsize = 100 # maximum number of threads log. threadpool. maxpoolsize = 3000 # maximum queue length log. threadpool. queuecapacity = 2000 # the idle time log allowed by the thread pool maintenance thread. threadpool. keepaliveseconds = 300 # The processing policy log of the thread pool to reject tasks (available in wireless. threadpool. rejectedexecutionhandler = Java. util. concurrent. threadpoolexecutor $ callerrunspolicy
Pointcut: Business logs are recorded through the cut surface.
Businesslogexporter (Business Log output): Specify the output method. The default output is recorded in the database, and the businesslogexporter interface can be extended for custom output.
Integrate business functions
For example, if an interface implementation class is personinfoapplicationimpl. Java, You need to record the service logs for the newly added or deleted methods. The Code is as follows:
@MethodAlias("save")public PersonInfoDTO savePersonInfo(PersonInfoDTO personInfoDTO) {PersonInfo personInfo = new PersonInfo();try { BeanUtils.copyProperties(personInfo, personInfoDTO); } catch (Exception e) { e.printStackTrace(); }personInfo.save();personInfoDTO.setId((java.lang.Long)personInfo.getId());return personInfoDTO;} @MethodAlias("remove")public void removePersonInfo(Long id) {this.removePersonInfos(new Long[] { id });}
Add the @ methodalias annotation to the method of the Business Log to be recorded. The value must be unique and the naming rules must comply with the Java method naming rules.
- Create the businesslogconfig folder under the class path
Groovy files used to store business logs
- Create a groovy file in the businesslogconfig folder
The file name can be arbitrary, as long as it complies with the Java class naming rules. For example, personinfoapplicationimpl. Groovy
Package VM. other. businesslog_resources.businesslogconfigclass personinfoapplicationimpl {def context def save () {"$ {getpretemplate ()}: Create personal information, name: $ {context. _ param0.name} "} def remove () {" $ {getpretemplate ()}: delete personal information "} def getpretemplate () {" $ {context. _ User }-"}}
The method name must correspond to the value of @ methodalias one by one.
- Introduce spring Configuration
<Import resource = "classpath *: koala-businesslog-aop.xml"> </import>
<Import resource = "classpath *: koala-businesslog-shared-persistence.xml"> </import>
<Value> org. openkoala. businesslog. Model </value>
Demo
Business function access address: http: // localhost: 8080/pages/example/PersonInfo-list.jsp
Service Log function access address: http: // localhost: 8080/pages/log/index. jsp
Demo: http://pan.baidu.com/s/1qWufvkC