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を定義します。
コメントを見る (0)
コメントを投稿