AbstractLogger

Package: MachII.logging.loggers
A logger that configures a logging adapter and performs output of the results if necessary. This is abstract and must be extend by a concrete logger implementation.

<!--- License: Copyright 2008 GreatBizTools, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright: GreatBizTools, LLC Author: Peter J. Farrell (peter@mach-ii.com) $Id: AbstractLogger.cfc 1118 2008-10-22 19:46:33Z peterfarrell $ Created version: 1.6.0 Updated version: 1.6.0 Notes: --->

Method Summary
public AbstractLogger init(string loggerId, struct parameters)

Initializes the logger. Do not override.

public void configure()

Override to provide custom configuration logic. Called after init().

public struct getConfigurationData()

Gets pretty configuration data for this logger. Override for better Dashboard integration data.

public AbstractLogAdapter getLogAdapter()

Gets the log adapter for this logger.

public string getLoggerId()

Returns the id of the logger. Used for preRedirect/postRedirect id.

public string getLoggerType()

Returns the dot path type of the logger. Required for Dashboard integration.

public string getLoggerTypeName()

Returns the type name of the logger. Required for Dashboard integration.

public string getLoggingLevel()

Returns the logging level by name.

public any getParameter(string name, [any defaultValue=""])

Gets a configuration parameter value, or a default value if not defined.

public string getParameterNames()

Returns a comma delimited list of parameter names.

public struct getParameters()

Gets the full set of configuration parameters for the component.

public boolean isLoggingEnabled()

Checkes if logging is currently enabled.

private boolean isMethodDefined(string methodName)

Checks if an abstract function was overridden in the concrete class. Does not walk the inheritance tree.

public boolean isOnRequestEndAvailable()

Checks if on request end method is available.

public boolean isParameterDefined(string name)

Checks to see whether or not a configuration parameter is defined.

public boolean isPrePostRedirectAvailable()

Checks if pre/post-redirect methods are available.

public void onRequestEnd()

On request end logic for this logger. Override to provide custom on request end logic.

public void postRedirect(struct data)

Post-redirect logic for this logger. Override to provide custom post-redirect logic. Must be overriden in unison with preRedirect.

public void preRedirect(struct data)

Pre-redirect logic for this logger. Override to provide custom pre-redirect logic. Must be overriden in unison with postRedirect.

private void setLogAdapter(AbstractLogAdapter logAdapter)

Sets the log adapter for this logger.

private void setLoggerId(string loggerId)

Sets the id of the logger.

public void setLoggingEnabled(boolean loggingEnabled)

Sets logging. Convenience method for dashboard.

public string setLoggingLevel(string loggingLevelName)

Sets the logging level by name.

public void setParameter(string name, any value)

Sets a configuration parameter.

public void setParameters(struct parameters)

Sets the full set of configuration parameters for the component.

Method Detail
configure

public void configure( )

Override to provide custom configuration logic. Called after init().

Parameters:

Code:

	<cffunction name="configure" access="public" returntype="void" output="false"
		hint="Override to provide custom configuration logic. Called after init().">
		
	</cffunction> 

getConfigurationData

public struct getConfigurationData( )

Gets pretty configuration data for this logger. Override for better Dashboard integration data.

Parameters:

Code:

	<cffunction name="getConfigurationData" access="public" returntype="struct" output="false"
		hint="Gets pretty configuration data for this logger. Override for better Dashboard integration data.">
		
		<cfset var data = variables.instance />
		
		<cfset data.adapter = getLogAdapter().getConfigurationData() />
		
		<cfreturn data />
	</cffunction> 

getLogAdapter

public AbstractLogAdapter getLogAdapter( )

Gets the log adapter for this logger.

Parameters:

Code:

	<cffunction name="getLogAdapter" access="public" returntype="MachII.logging.adapters.AbstractLogAdapter" output="false"
		hint="Gets the log adapter for this logger.">
		<cfreturn variables.logAdapter />
	</cffunction> 

getLoggerId

public string getLoggerId( )

Returns the id of the logger. Used for preRedirect/postRedirect id.

Parameters:

Code:

	<cffunction name="getLoggerId" access="public" returntype="string" output="false"
		hint="Returns the id of the logger. Used for preRedirect/postRedirect id.">
		<cfreturn variables.instance.loggerId />
	</cffunction> 

getLoggerType

public string getLoggerType( )

Returns the dot path type of the logger. Required for Dashboard integration.

Parameters:

Code:

	<cffunction name="getLoggerType" access="public" returntype="string" output="false"
		hint="Returns the dot path type of the logger. Required for Dashboard integration.">
		<cfreturn GetMetadata(this).name />
	</cffunction> 

getLoggerTypeName

public string getLoggerTypeName( )

Returns the type name of the logger. Required for Dashboard integration.

Parameters:

Code:

	<cffunction name="getLoggerTypeName" access="public" returntype="string" output="false"
		hint="Returns the type name of the logger. Required for Dashboard integration.">
		<cfreturn variables.instance.loggerTypeName />
	</cffunction> 

getLoggingLevel

public string getLoggingLevel( )

Returns the logging level by name.

Parameters:

Code:

	<cffunction name="getLoggingLevel" access="public" returntype="string" output="false"
		hint="Returns the logging level by name.">
		<cfreturn getLogAdapter().getLoggingLevel() />
	</cffunction> 

getParameter

public any getParameter( string name, [any defaultValue=""] )

Gets a configuration parameter value, or a default value if not defined.

Parameters:
string name
[any defaultValue=""]

Code:

	<cffunction name="getParameter" access="public" returntype="any" output="false"
		hint="Gets a configuration parameter value, or a default value if not defined.">
		<cfargument name="name" type="string" required="true"
			hint="The parameter name." />
		<cfargument name="defaultValue" type="any" required="false" default=""
			hint="The default value to return if the parameter is not defined. Defaults to a blank string." />
		<cfif isParameterDefined(arguments.name)>
			<cfreturn variables.parameters[arguments.name] />
		<cfelse>
			<cfreturn arguments.defaultValue />
		</cfif>
	</cffunction> 

getParameterNames

public string getParameterNames( )

Returns a comma delimited list of parameter names.

Parameters:

Code:

	<cffunction name="getParameterNames" access="public" returntype="string" output="false"
		hint="Returns a comma delimited list of parameter names.">
		<cfreturn StructKeyList(variables.parameters) />
	</cffunction> 

getParameters

public struct getParameters( )

Gets the full set of configuration parameters for the component.

Parameters:

Code:

	<cffunction name="getParameters" access="public" returntype="struct" output="false"
		hint="Gets the full set of configuration parameters for the component.">
		<cfreturn variables.parameters />
	</cffunction> 

init

public AbstractLogger init( string loggerId, struct parameters )

Initializes the logger. Do not override.

Parameters:
string loggerId
struct parameters

Code:

	<cffunction name="init" access="public" returntype="AbstractLogger" output="false"
		hint="Initializes the logger. Do not override.">
		<cfargument name="loggerId" type="string" required="true" />
		<cfargument name="parameters" type="struct" required="true" />
		
		<cfset setLoggerId(arguments.loggerId) />
		<cfset setParameters(arguments.parameters) />
		
		<cfreturn this />
	</cffunction> 

isLoggingEnabled

public boolean isLoggingEnabled( )

Checkes if logging is currently enabled.

Parameters:

Code:

	<cffunction name="isLoggingEnabled" access="public" returntype="boolean" output="false"
		hint="Checkes if logging is currently enabled.">
		<cfreturn getLogAdapter().getLoggingEnabled() />
	</cffunction> 

isMethodDefined

private boolean isMethodDefined( string methodName )

Checks if an abstract function was overridden in the concrete class. Does not walk the inheritance tree.

Parameters:
string methodName

Code:

	<cffunction name="isMethodDefined" access="private" returntype="boolean" output="false"
		hint="Checks if an abstract function was overridden in the concrete class. Does not walk the inheritance tree.">
		<cfargument name="methodName" type="string" required="true" />

		<cfset var md = GetMetadata(this) />
		<cfset var methods = ArrayNew(1) />
		<cfset var i = 0 />
		<cfset var result = false />
		
		
		<cfif StructKeyExists(md, "functions")>
			<cfset methods = md.functions />
			
			
			<cfloop from="1" to="#ArrayLen(methods)#" index="i">
				<cfif methods[i].name EQ arguments.methodName>
					<cfset result = true />
					<cfbreak />
				</cfif>
			</cfloop>
		</cfif>
		
		<cfreturn result />		
	</cffunction> 

isOnRequestEndAvailable

public boolean isOnRequestEndAvailable( )

Checks if on request end method is available.

Parameters:

Code:

	<cffunction name="isOnRequestEndAvailable" access="public" returntype="boolean" output="false"
		hint="Checks if on request end method is available.">
		<cfreturn isMethodDefined("onRequestEnd") />
	</cffunction> 

isParameterDefined

public boolean isParameterDefined( string name )

Checks to see whether or not a configuration parameter is defined.

Parameters:
string name

Code:

	<cffunction name="isParameterDefined" access="public" returntype="boolean" output="false"
		hint="Checks to see whether or not a configuration parameter is defined.">
		<cfargument name="name" type="string" required="true"
			hint="The parameter name." />
		<cfreturn StructKeyExists(variables.parameters, arguments.name) />
	</cffunction> 

isPrePostRedirectAvailable

public boolean isPrePostRedirectAvailable( )

Checks if pre/post-redirect methods are available.

Parameters:

Code:

	<cffunction name="isPrePostRedirectAvailable" access="public" returntype="boolean" output="false"
		hint="Checks if pre/post-redirect methods are available.">
		
		<cfset var preRedirectResult = isMethodDefined("preRedirect") />
		<cfset var postRedirectResult = isMethodDefined("postRedirect") />
		<cfset var result = false />
		
		<cfif preRedirectResult AND postRedirectResult>
			<cfset result = true />
		<cfelseif preRedirectResult + postRedirectResult EQ 1>
			<cfthrow type="MachII.logging.loggers.bothPrePostRedirectMethodsRequired" 
				message="Both PreRedirect and PostRedirect methods must be implemented in '#getLoggerId()#'." 
				detail="Available Methods: preRedirectResult=#preRedirectResult#, postRedirectResult=#postRedirectResult#" />
		</cfif>
		
		<cfreturn result />
	</cffunction> 

onRequestEnd

public void onRequestEnd( )

On request end logic for this logger. Override to provide custom on request end logic.

Parameters:

Code:

	<cffunction name="onRequestEnd" access="public" returntype="void" 
		hint="On request end logic for this logger. Override to provide custom on request end logic.">
		
		<cfabort showerror="This method is abstract and must be overrided if onRequestEnd functionality is required." />
	</cffunction> 

postRedirect

public void postRedirect( struct data )

Post-redirect logic for this logger. Override to provide custom post-redirect logic. Must be overriden in unison with preRedirect.

Parameters:
struct data

Code:

	<cffunction name="postRedirect" access="public" returntype="void" output="false"
		hint="Post-redirect logic for this logger. Override to provide custom post-redirect logic. Must be overriden in unison with preRedirect.">
		<cfargument name="data" type="struct" required="true"
			hint="Redirect persist data struct." />
		<cfabort showerror="This method is abstract and must be overrided if postRedirect functionality is required." />
	</cffunction> 

preRedirect

public void preRedirect( struct data )

Pre-redirect logic for this logger. Override to provide custom pre-redirect logic. Must be overriden in unison with postRedirect.

Parameters:
struct data

Code:

	<cffunction name="preRedirect" access="public" returntype="void" output="false"
		hint="Pre-redirect logic for this logger. Override to provide custom pre-redirect logic. Must be overriden in unison with postRedirect.">
		<cfargument name="data" type="struct" required="true"
			hint="Redirect persist data struct." />
		<cfabort showerror="This method is abstract and must be overrided if preRedirect functionality is required." />
	</cffunction> 

setLogAdapter

private void setLogAdapter( AbstractLogAdapter logAdapter )

Sets the log adapter for this logger.

Parameters:
AbstractLogAdapter logAdapter

Code:

	<cffunction name="setLogAdapter" access="private" returntype="void" output="false"
		hint="Sets the log adapter for this logger.">
		<cfargument name="logAdapter" type="MachII.logging.adapters.AbstractLogAdapter" required="true" />
		<cfset variables.logAdapter = arguments.logAdapter />
	</cffunction> 

setLoggerId

private void setLoggerId( string loggerId )

Sets the id of the logger.

Parameters:
string loggerId

Code:

	<cffunction name="setLoggerId" access="private" returntype="void" output="false"
		hint="Sets the id of the logger.">
		<cfargument name="loggerId" type="string" required="true" />
		<cfset variables.instance.loggerId = arguments.loggerId />
	</cffunction> 

setLoggingEnabled

public void setLoggingEnabled( boolean loggingEnabled )

Sets logging. Convenience method for dashboard.

Parameters:
boolean loggingEnabled

Code:

	<cffunction name="setLoggingEnabled" access="public" returntype="void" output="false"
		hint="Sets logging. Convenience method for dashboard.">
		<cfargument name="loggingEnabled" type="boolean" required="true" />
		<cfset getLogAdapter().setLoggingEnabled(arguments.loggingEnabled) />
	</cffunction> 

setLoggingLevel

public string setLoggingLevel( string loggingLevelName )

Sets the logging level by name.

Parameters:
string loggingLevelName

Code:

	<cffunction name="setLoggingLevel" access="public" returntype="string" output="false"
		hint="Sets the logging level by name.">
		<cfargument name="loggingLevelName" type="string" required="true"
			hint="Accepts 'trace', 'debug', 'info', 'warn', 'error', 'fatal', 'all' or 'off'." />
		<cfset getLogAdapter().setLoggingLevel(arguments.loggingLevelName) />
	</cffunction> 

setParameter

public void setParameter( string name, any value )

Sets a configuration parameter.

Parameters:
string name
any value

Code:

	<cffunction name="setParameter" access="public" returntype="void" output="false"
		hint="Sets a configuration parameter.">
		<cfargument name="name" type="string" required="true"
			hint="The parameter name." />
		<cfargument name="value" type="any" required="true"
			hint="The parameter value." />
		<cfset variables.parameters[arguments.name] = arguments.value />
	</cffunction> 

setParameters

public void setParameters( struct parameters )

Sets the full set of configuration parameters for the component.

Parameters:
struct parameters

Code:

	<cffunction name="setParameters" access="public" returntype="void" output="false"
		hint="Sets the full set of configuration parameters for the component.">
		<cfargument name="parameters" type="struct" required="true" />
		
		<cfset var key = "" />
		
		<cfloop collection="#arguments.parameters#" item="key">
			<cfset setParameter(key, arguments.parameters[key]) />
		</cfloop>
	</cffunction>