| Package: MachII.logging.filters |
| Inherits from: logging.filters.AbstractFilter |
| Makes decisions on whether to log or not based on channel name and known criteria. |
<!--- 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: GenericChannelFilter.cfc 1299 2009-01-25 22:19:23Z peterfarrell $ Created version: 1.6.0 Updated version: 1.6.0 Notes: FilterCriteria can be an comma delimited list or an array. ----------------------------------------------------------------------------------------- | Pattern | Matches Channels | ----------------------------------------------------------------------------------------- | * | Matches everything (unless you have another pattern that | | | specifies not to match a channel name) | | !* | Nothing (unless you have another pattern that matches) | | MachII.* | Matches all channels that start with 'MachII.' | | !myApp.model.* | Does not match any channels that start with 'myApp.model.' | | MachII | Matches only 'MachII' literal not 'MachII.framework.etc' | ----------------------------------------------------------------------------------------| ! = Do not match (can only occur at the beginning of a pattern string) no ! or * = Indicates that you should match exact channel name * = Wildcard (can only occur at the end of a pattern string) Pattern matches are not case sensitive. ---> |
| Method Summary | |
|---|---|
| public GenericChannelFilter |
init([any filterCriteria=""])
Initalizes the filter. |
| public boolean |
decide(struct logMessageElements)
Decides whether or not the passed channel should be logged. |
| public array | getFilterChannels() |
| public array |
getFilterCriteria()
Gets a struct of filter criteria. |
| private void |
loadFilterCriteria([any filterCriteria])
Loads filter criteria. |
| private void | setFilterChannels(array filterChannels) |
| Methods inherited from logging.filters.AbstractFilter: getFilterType , getFilterTypeName , getFilterCriteriaData |
|---|
| Method Detail |
|---|
| decide |
|---|
public boolean decide( struct logMessageElements )
Decides whether or not the passed channel should be logged.
Parameters:
| struct logMessageElements |
Code:
<cffunction name="decide" access="public" returntype="boolean" output="false" hint="Decides whether or not the passed channel should be logged."> <cfargument name="logMessageElements" type="struct" required="true" /> <cfset var channel = arguments.logMessageElements.channel /> <cfset var result = true /> <cfset var filterChannels = getFilterChannels() /> <cfset var i = 0 /> <cfloop from="1" to="#ArrayLen(filterChannels)#" index="i"> <cfif filterChannels[i].restrict> <cfif filterChannels[i].wildcard AND FindNoCase(filterChannels[i].channel, channel) EQ 1> <cfset result = false /> <cfelseif filterChannels[i].channel IS channel> <cfset result = false /> </cfif> <cfelse> <cfif filterChannels[i].wildcard AND FindNoCase(filterChannels[i].channel, channel) EQ 1> <cfset result = true /> <cfelseif filterChannels[i].channel IS channel> <cfset result = true /> </cfif> </cfif> </cfloop> <cfreturn result /> </cffunction>
| getFilterChannels |
|---|
public array getFilterChannels( )
Parameters:
Code:
<cffunction name="getFilterChannels" access="public" returntype="array" output="false"> <cfreturn variables.filterChannels /> </cffunction>
| getFilterCriteria |
|---|
public array getFilterCriteria( )
Gets a struct of filter criteria.
Parameters:
Code:
<cffunction name="getFilterCriteria" access="public" returntype="array" output="false" hint="Gets a struct of filter criteria."> <cfset var criteria = getFilterChannels() /> <cfset var result = ArrayNew(1) /> <cfset var temp = "" /> <cfset var i = 0 /> <cfloop from="1" to="#ArrayLen(criteria)#" index="i"> <cfset temp = "" /> <cfif criteria[i].restrict> <cfset temp = temp & "!" /> </cfif> <cfset temp = temp & criteria[i].channel /> <cfif criteria[i].wildcard> <cfset temp = temp & "*" /> </cfif> <cfset ArrayAppend(result, temp) /> </cfloop> <cfreturn result /> </cffunction>
| init |
|---|
public GenericChannelFilter init( [any filterCriteria=""] )
Initalizes the filter.
Parameters:
| [any filterCriteria=""] |
Code:
<cffunction name="init" access="public" returntype="GenericChannelFilter" output="false" hint="Initalizes the filter."> <cfargument name="filterCriteria" type="any" required="false" default="" hint="Criteria to filter on. Accepts an array or list." /> <cfset loadFilterCriteria(arguments.filterCriteria) /> <cfreturn this /> </cffunction>
| loadFilterCriteria |
|---|
private void loadFilterCriteria( [any filterCriteria] )
Loads filter criteria.
Parameters:
| [any filterCriteria] |
Code:
<cffunction name="loadFilterCriteria" access="private" returntype="void" output="false" hint="Loads filter criteria."> <cfargument name="filterCriteria" type="any" required="false" /> <cfset var filterChannels = ArrayNew(1) /> <cfset var temp = "" /> <cfset var channel = "" /> <cfset var i = 0 /> <cfif IsSimpleValue(arguments.filterCriteria)> <cfset arguments.filterCriteria = ListToArray(arguments.filterCriteria, ",") /> </cfif> <cfif ArrayLen(arguments.filterCriteria)> <cfloop from="1" to="#ArrayLen(arguments.filterCriteria)#" index="i"> <cfset temp = StructNew() /> <cfset channel = arguments.filterCriteria[i] /> <cfif Left(channel, 1) EQ "!"> <cfset temp.restrict = true /> <cfif Len(channel) GT 1> <cfset channel = Right(channel, Len(channel) -1) /> <cfelse> <cfset channel = "" /> </cfif> <cfelse> <cfset temp.restrict = false /> </cfif> <cfif Right(channel, 1) EQ "*"> <cfset temp.wildcard = true /> <cfif Len(channel) GT 1> <cfset channel = Left(channel, Len(channel) -1) /> <cfelse> <cfset channel = "" /> </cfif> <cfelse> <cfset temp.wildcard = false /> </cfif> <cfset temp.channel = channel /> <cfset ArrayAppend(filterChannels, temp) /> </cfloop> </cfif> <cfset setFilterChannels(filterChannels) /> </cffunction>
| setFilterChannels |
|---|
private void setFilterChannels( array filterChannels )
Parameters:
| array filterChannels |
Code:
<cffunction name="setFilterChannels" access="private" returntype="void" output="false"> <cfargument name="filterChannels" type="array" required="true" /> <cfset variables.filterChannels = arguments.filterChannels /> </cffunction>