| Package: MachII.logging.filters |
| Inherits from: logging.filters.AbstractFilter |
<!--- 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: CFLogAdapter.cfc 584 2007-12-15 08:44:43Z 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 | ----------------------------------------------------------------------------------------- | !* | 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 ! = Indicates that you should match * = 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. |
| private array | getFilterChannels() |
| private void |
loadFilterCriteria([any filterCriteria])
Loads filter criteria. |
| private void | setFilterChannels(array filterChannels) |
| 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 |
|---|
private array getFilterChannels( )
Parameters:
Code:
<cffunction name="getFilterChannels" access="private" returntype="array" output="false"> <cfreturn variables.filterChannels /> </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 /> <cfset channel = Right(channel, Len(channel) -1) /> <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>