How to Use the koala Service Log System

Source: Internet
Author: User
2. Prerequisites

Create a koala project and check the Integration Service Log subsystem.

Procedure

1. Business Method annotation @ methodalias

Format:

@ Methodalias ("Business Method alias ")

Business Method

Example:

@ Methodalias ("savepersoninfo ")

Public personinfo savepersoninfo (personinfo ){

Personinfo. Save ();

Return personinfo;

}

Requirements:

  1. The alias must comply with the naming rules of the Java method name.
  2. A value is required for adding a name to facilitate the ing between business methods and log templates.
  3. Annotations can only be labeled on interface implementation classes.
2. Create a groovy log Template

Create any file ending with *. Groovy in the businesslogconfig directory of SRC/main/resources of the web module,

Example: XXX. Groovy.

Template:

Package org. openkoala. businesslog. config (optional)

Import org. dayatang. domain. instancefacroty (optional)

Class organizationapplicationimpl {(the class name must comply with the Java name)

// Required

Def Context

Def organizationapplicationimpl_createastoporganization (){

"$ {Getpretemplate ()}: Create a top-level organization: $ {context. _ param0.name }"

}

Def organizationapplicationimpl_createcompany (){

"$ {Getpretemplate ()}: $ {context. _ param0.name}, create branch: $ {context. _ param1.name }"

}

Def organizationapplicationimpl_assignchildorganization (){

"$ {Getpretemplate ()}: allocate a sub-institution to $ {context. _ param0.name} for $ {context. _ param1.name}. The duration is $ {context. _ param2 }"

}

Def organizationapplicationimpl_createdepartment (){

"$ {Getpretemplate ()}: create a department under $ {context. _ param0.name}: $ {context. _ param1.name }"

}

Def organizationapplicationimpl_terminateemployeeorganizationrelation (){

"$ {Getpretemplate ()}: Termination institution $ {context. _ param0.name }"

}

Def getpretemplate (){

"$ {Context. _ User }-"

}

}

Note:

A log template is actually a groovy class. You can define any method. Only when the alias of a business method (@ methodalias value) is equal to the method name can we regard it as a business LOG method, its return value (return or the variable placed in the last row of the method) will be assigned to Org. openkoala. businesslog. the businesslog object is persistent.

There are two types of LOG method return values:

1. Only one string log text is returned;

2. A map is returned, which includes the log classification and log text with the key as category.

In the class,Def ContextDefines a variable, which is actually a map.

Map stores the return values and parameters of business methods. If needed, you can store any data you need. You can extract the content you need from the context and fill it in your logs. By default, some default keys are stored in the context. See the following table.

Context parameter description

Key

Value

_ Methodreturn

Business Method Return Value

_ Param

Business Method parameters. _ param0 indicates the first parameter _ param1 indicates the second parameter.

_ Executeerror

Abnormal information about failed service method execution

_ Businessmethod

Business Method

_ User

Business Method Operator

_ Time

Business Method operation time

_ IP

IP address

Example 1:

Class personinfoapplicationimpl {def context def savepersoninfo () {"Create personal information"} def pagequerypersoninfo () {"Query personal information list "}}



Example 2:

Package Org. openkoala. businesslog. configclass personinfoapplicationimpl {def context def savepersoninfo () {"$ {getpretemplate ()}: Create personal information, name: $ {context. _ param0.name} "} def pagequerypersoninfo () {[Category:" Query Class ", log:" Query personal information list "]} def getpretemplate () {" $ {context. _ User }-"}}



Example 3:

Package Org. openkoalaimport Org. dayatang. domain. instancefactoryimport Org. openkoala. example. application. personinfoapplicationimport Org. openkoala. example. domain. personinfoclass personinfoapplicationimpl {def context def savepersoninfo () {"$ {getpretemplate ()}: Create personal information, name: $ {context. _ param0.name} "} def pagequerypersoninfo () {[Category:" Query Class ", log:" Query personal information list "]} def removepersoninfo () {personinfoapplication = instancefactory. getinstance (personinfoapplication. class) string name = personinfoapplication. getpersoninfo (577 ). getname () "delete user information: name:" + name} def getpretemplate () {"$ {context. _ User }-"}}

The above sample code is for reference only.


3. Configure the spring entry point

By default, no configuration is required. After a project is created, the package path of the interface implementation class is configured as the entry point. You can modify the extension on your own.
Entry Point configuration in the koala-businesslog.properties under the src/main/Resources Web module, the key is pointcut

Pointcut = Execution (* org. openkoala. example. application. impl .*.*(..))

| Execution (* org. openkoala. example. facade. impl .*.*(..))

Web query page

Run the project. Access address: http: // localhost: 8080/pages/log/index. jsp

How to Use the koala Service Log System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.