LoggingAOP with ColdSpring

今日は、ColdSpringAOPとLog4jを使ったロギングサービスについて、解説します。
Chris ScottのColdSpringAOPのチュートリアルから引用してみます。

1.最初に、LoggingServiceを定義します。javaのlog4jからloggerクラスを生成しています。

<cfcomponent name="LoggingService" output="false">

  <cffunction name="init" returntype="net.klondike.service.LoggingService" access="public" output="false">
    <cfset var category = CreateObject("java", "org.apache.log4j.Category") />
    <cfset variables.logger = category.getInstance('net.klondike') />
    <cfreturn this />
  </cffunction>
 
  <cffunction name="info" access="public" returntype="void" output="false">
    <cfargument name=message" type="string" required="true" />
    <cfif variables.logger.isInfoEnabled()>
    <cfset variables.logger.info(arguments.message) />
    </cfif>
  </cffunction>
 
</cfcomponent>

2.次に、AOPパートです。loggingBeforeAdviceを定義します。

CFMX開発 | ColdSpring | ModelGlue
2005/11/03 21:00



コメント

コメントを見る (0)

コメントを投稿

* コメントは記事の投稿者が承認するまで表示されません。