Changeset 2363

Show
Ignore:
Timestamp:
07/04/09 02:06:52 (4 years ago)
Author:
lmajano
Message:

tons of updates for all appenders and category support for logBox

Location:
coldbox/trunk
Files:
3 added
16 modified

Legend:

Unmodified
Added
Removed
  • coldbox/trunk/system/logging/AbstractAppender.cfc

    r2362 r2363  
    5858<!------------------------------------------- INTERNAL OBSERVERS ------------------------------------------> 
    5959 
    60          
    6160        <cffunction name="onRegistration" access="public" hint="Runs after the appender has been created and registered. Implemented by Concrete appender" output="false" returntype="void"> 
    6261        </cffunction> 
     
    6665 
    6766<!------------------------------------------- PUBLIC -------------------------------------------> 
     67         
     68        <!--- severityToString ---> 
     69        <cffunction name="severityToString" output="false" access="public" returntype="string" hint="convert a severity to a string"> 
     70                <cfargument name="severity" type="numeric" required="true" hint="The severity to convert"/> 
     71                <cfreturn this.logLevels.lookup(arguments.severity)> 
     72        </cffunction> 
    6873         
    6974        <!--- getHash ---> 
  • coldbox/trunk/system/logging/LogBox.cfc

    r2362 r2363  
    2727                // LogBox Unique ID */ 
    2828                instance._hash = hash(createUUID());     
    29                 // LoggersList 
    30                 instance.appenderRegistry = "";  
     29                // Appenders 
     30                instance.appenderRegistry = ""; 
     31                // Category Appenders 
     32                instance.categoryAppenders = "";         
    3133                // Version 
    32                 instance.version = "1.0";                
     34                instance.version = "1.0";         
     35                // Configuration object 
     36                instance.config = "";    
    3337        </cfscript> 
    3438         
    3539        <!--- Init ---> 
    3640        <cffunction name="init" access="public" returntype="LogBox" hint="Constructor" output="false" > 
    37                 <cfargument name="logBoxConfig" type="coldbox.system.logging.config.LogBoxConfig" required="false" hint="If passed, this LogBox instance will be configured with this configuration object."/> 
     41                <cfargument name="logBoxConfig" type="coldbox.system.logging.config.LogBoxConfig" required="true" hint="The LogBoxConfig object to use to configure this instance of LogBox"/> 
    3842                <cfscript> 
    3943                        var Collections = createObject("java", "java.util.Collections"); 
    4044                         
    41                         // Prepare Logger Object Registry 
     45                        // Prepare Appender Object Registries 
    4246                        instance.appenderRegistry = Collections.synchronizedMap(CreateObject("java","java.util.LinkedHashMap").init(3)); 
    43                          
    44                         // Check if using configuration object 
    45                         if( structKeyExists(arguments,"logBoxConfig") ){ 
    46                                 registerConfig(arguments.logBoxConfig); 
    47                         } 
    48                          
    49                         /* Return Factory */ 
     47                        instance.categoryAppenders = structnew(); 
     48                         
     49                        // Store config object 
     50                        instance.config = arguments.logBoxConfig; 
     51                         
     52                        // Configure LogBox 
     53                        configure(); 
     54                         
     55                        // Return LogBox 
    5056                        return this; 
    5157                </cfscript> 
     
    5662                <cfreturn instance.Version> 
    5763        </cffunction> 
     64         
     65        <!--- Get the config object ---> 
     66        <cffunction name="getConfig" access="public" returntype="coldbox.system.logging.config.LogBoxConfig" output="false" hint="Get this LogBox's configuration object."> 
     67                <cfreturn instance.config> 
     68        </cffunction> 
    5869 
    5970<!------------------------------------------- PUBLIC -------------------------------------------> 
    60          
    61         <!--- getHash ---> 
    62         <cffunction name="getHash" output="false" access="public" returntype="string" hint="Get this Log Box's unique ID"> 
    63                 <cfreturn instance._hash> 
    64         </cffunction> 
    6571                 
    6672        <!--- clearAppenders ---> 
     
    7480        </cffunction> 
    7581         
     82        <!--- Get the appender Registry ---> 
     83        <cffunction name="getAppenders" access="public" returntype="struct" output="false" hint="Get the map of registered appenders."> 
     84                <cfreturn instance.appenderRegistry> 
     85        </cffunction> 
     86         
     87        <!--- Get the category Appenders Registry ---> 
     88        <cffunction name="getCategoryAppenders" access="public" returntype="struct" output="false" hint="Get the map of registered category appenders."> 
     89                <cfreturn instance.categoryAppenders> 
     90        </cffunction> 
     91         
     92        <!--- getAppender ---> 
     93        <cffunction name="getAppender" output="false" access="public" returntype="any" hint="Get a named appender"> 
     94                <cfargument name="name" type="string" required="true" hint="The appender's name"/> 
     95                <cfscript> 
     96                        if( appenderExists(arguments.name) ){ 
     97                                return structFind(getAppenders(),arguments.name); 
     98                        } 
     99                        else{ 
     100                                getutil().throwit(message="Appender #arguments.name# does not exist.",type="LogBox.AppenderNotFound"); 
     101                        } 
     102                </cfscript> 
     103        </cffunction> 
     104         
    76105        <!--- appenderExists ---> 
    77106        <cffunction name="appenderExists" output="false" access="public" returntype="boolean" hint="Checks to see if a specified appender exists by name."> 
    78107                <cfargument name="name" type="string" required="true" hint="The name of the appender to check if it is registered"/> 
    79108                <cfreturn structKeyExists(getAppenders(), arguments.name)> 
    80         </cffunction> 
    81  
    82         <!--- register ---> 
    83         <cffunction name="registerConfig" output="false" access="public" returntype="void" hint="Registers all the appenders in a LogBoxConfig object"> 
    84                 <!--- ************************************************************* ---> 
    85                 <cfargument name="logBoxConfig" type="coldbox.system.logging.config.LogBoxConfig" required="true"/> 
    86                 <!--- ************************************************************* ---> 
    87                 <cfscript> 
    88                         var appendersArray = arguments.logBoxConfig.getAppenders(); 
    89                         var x =1; 
    90                          
    91                         for(x=1; x lte arrayLen(appendersArray); x=x+1){ 
    92                                 // Register configurations. 
    93                                 registerNew(argumentCollection=appendersArray[x]);       
    94                         } 
    95                 </cfscript> 
    96109        </cffunction> 
    97110         
     
    111124                <!--- Verify Registration ---> 
    112125                <cfif NOT appenderExists(name)> 
    113                         <cflock name="#getHash()#.#name#" type="exclusive" throwontimeout="true" timeout="30"> 
     126                        <cflock name="#instance._hash#.#name#" type="exclusive" throwontimeout="true" timeout="30"> 
    114127                                <cfscript> 
    115128                                        if( NOT appenderExists(name) ){ 
     
    124137                        </cflock> 
    125138                <cfelse> 
    126                         <cflog type="warning" file="LogBox" text="LogBoxID: #getHash()# - Cannot register appender #name# as it is already registered. Skipping."> 
     139                        <cflog type="warning" file="LogBox" text="LogBoxID: #instance._hash# - Cannot register appender #name# as it is already registered. Skipping."> 
    127140                </cfif>          
    128141        </cffunction> 
     
    176189                <cfscript> 
    177190                        var logger = createObject("component","coldbox.system.logging.Logger"); 
     191                        var args = structnew(); 
     192                        var config = getConfig(); 
     193                        var appenders = getCategoryAppenders(); 
     194                        var categoryConfig = "";         
     195                                         
     196                        // Set category name in config 
     197                        args.category = arguments.category; 
     198                         
     199                        // Verify if category exists to get appenders and data info. 
     200                        if( config.categoryExists(arguments.category) ){ 
     201                                categoryConfig = config.getCategory(arguments.category); 
     202                                args.levelMin = categoryConfig.levelMin; 
     203                                args.levelMax = categoryConfig.levelMax; 
     204                                // Get Appenders from storage map 
     205                                args.appenders = appenders[arguments.category]; 
     206                        } 
    178207                         
    179208                        // Dependencies 
     
    182211                         
    183212                        // Init it 
    184                         return logger.init(arguments.category);                  
     213                        return logger.init(argumentCollection=args);                     
    185214                </cfscript> 
    186215        </cffunction> 
     
    256285<!------------------------------------------- PRIVATE ------------------------------------------> 
    257286         
    258         <!--- Get the appender Registry ---> 
    259         <cffunction name="getAppenders" access="private" returntype="struct" output="false" hint="Get the map of registered loggers."> 
    260                 <cfreturn instance.appenderRegistry> 
     287        <!--- configure ---> 
     288        <cffunction name="configure" output="false" access="private" returntype="void" hint="Configure logbox for operation"> 
     289                <cfscript> 
     290                        var config = getConfig(); 
     291                        var appenders = config.getAppenders(); 
     292                        var key = ""; 
     293                        var categories = config.getCategories(); 
     294                         
     295                        // Register All Appenders configured 
     296                        for( key in appenders ){ 
     297                                registerNew(argumentCollection=appenders[key]); 
     298                        } 
     299                        // Clean just in case 
     300                        key = ""; 
     301                        // Register All Category Appenders defined in the configuration object. 
     302                        for( key in categories ){ 
     303                                instance.categoryAppenders[key] = getAppendersMap(categories[key].appenders); 
     304                        } 
     305                </cfscript> 
     306        </cffunction> 
     307         
     308        <!--- getAppendersMap ---> 
     309        <cffunction name="getAppendersMap" output="false" access="private" returntype="struct" hint="Get a map of appenders by list"> 
     310                <cfargument name="appenders" type="string" required="true" hint="The list of appenders to get"/> 
     311                <cfscript> 
     312                        var x =1; 
     313                        var appenders = getAppenders(); 
     314                        var Collections = createObject("java", "java.util.Collections"); 
     315                        var map = Collections.synchronizedMap(CreateObject("java","java.util.LinkedHashMap").init(listlen(arguments.appenders))); 
     316                         
     317                        for(x=1; x lte listlen(arguments.appenders); x=x+1){ 
     318                                thisAppender = listGetAt(arguments.appenders,x); 
     319                                map[thisAppender] = appenders[thisAppender];     
     320                        } 
     321                         
     322                        return map; 
     323                </cfscript> 
    261324        </cffunction> 
    262325         
     
    274337                        var key = ""; 
    275338                        var thisAppender = ""; 
     339                        var logEvent = ""; 
     340                         
     341                        // Do we have appenders? 
     342                        if( NOT hasAppenders() ){ return; } 
    276343                         
    277344                        // If message empty, just exit 
     
    284351                        // Delegate Calls 
    285352                        for(key in appenders){ 
    286                                 // Get logger 
     353                                // Get Appender 
    287354                                thisAppender = appenders[key]; 
    288355                                // Log Check 
    289356                                if( thisAppender.canLog(arguments.severity) ){ 
    290                                          
     357                                        // Log the message in the appender 
    291358                                        thisAppender.logMessage(logEvent); 
    292359                                } 
  • coldbox/trunk/system/logging/LogEvent.cfc

    r2362 r2363  
    3232                                instance[key] = arguments[key]; 
    3333                        } 
     34                        return this; 
    3435                </cfscript> 
    3536        </cffunction> 
  • coldbox/trunk/system/logging/Logger.cfc

    r2362 r2363  
    2020         
    2121                // private instance scope 
    22                 instance = structnew();                          
     22                instance = structnew(); 
     23                instance.category = ""; 
     24                instance.levelMin = ""; 
     25                instance.levelMax = ""; 
     26                instance.appenders = "";                                 
    2327        </cfscript> 
    2428         
    2529        <!--- Init ---> 
    2630        <cffunction name="init" access="public" returntype="Logger" hint="Constructor" output="false" > 
    27                 <cfargument name="category" type="string" required="true" hint="The category name to use this logger with"/> 
    28                 <cfscript> 
    29                         // Setup the category 
     31                <cfargument name="category" type="string"  required="true" hint="The category name to use this logger with"/> 
     32                <cfargument name="levelMin" type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
     33                <cfargument name="levelMax" type="numeric" required="false" default="5" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
     34                <cfargument name="appenders" type="struct" required="false" default="#structnew()#" hint="A map of appenders for this category"/> 
     35                <cfscript> 
    3036                        instance.category = arguments.category; 
    31                          
     37                        instance.levelMin = arguments.levelMin; 
     38                        instance.levelMax = arguments.levelMax; 
     39                        instance.appenders = arguments.appenders;                        
    3240                        return this; 
    3341                </cfscript> 
    3442        </cffunction> 
     43         
     44        <!--- hasAppenders ---> 
     45        <cffunction name="hasAppenders" output="false" access="public" returntype="boolean" hint="Checks to see if we have registered any appenders yet"> 
     46                <cfreturn NOT getAppenders().isEmpty()> 
     47        </cffunction> 
    3548 
    3649<!------------------------------------------- FACADE Methods -------------------------------------------> 
     50         
     51        <!--- Get the Appenders ---> 
     52        <cffunction name="getappenders" access="public" returntype="struct" output="false" hint="Get the appenders for this logger"> 
     53                <cfreturn instance.appenders> 
     54        </cffunction> 
     55         
     56        <!--- Level Min ---> 
     57        <cffunction name="getlevelMin" access="public" returntype="numeric" output="false" hint="Get the level min setting"> 
     58                <cfreturn instance.levelMin> 
     59        </cffunction> 
     60        <cffunction name="setLevelMin" access="public" output="false" returntype="void" hint="Set the appender's default levelMin"> 
     61                <cfargument name="levelMin" type="numeric" required="true"/> 
     62                <cfscript> 
     63                        // Verify level 
     64                        if( this.logLevels.isLevelValid(arguments.levelMin) AND 
     65                            arguments.levelMin lte getLevelMax() ){ 
     66                                instance.levelMin = arguments.levelMin; 
     67                        } 
     68                        else{ 
     69                                $throw("Invalid Log Level","The log level #arguments.levelMin# is invalid or greater than the levelMax (#getLevelMax()#). Valid log levels are from 0 to 5","Logger.InvalidLogLevelException"); 
     70                        } 
     71                </cfscript> 
     72        </cffunction> 
     73         
     74        <!--- GetSet level Max ---> 
     75        <cffunction name="getlevelMax" access="public" returntype="numeric" output="false" hint="Get the level Max setting"> 
     76                <cfreturn instance.levelMax> 
     77        </cffunction> 
     78        <cffunction name="setLevelMax" access="public" output="false" returntype="void" hint="Set the appender's default levelMax"> 
     79                <cfargument name="levelMax" type="numeric" required="true"/> 
     80                <cfscript> 
     81                        // Verify level 
     82                        if( this.logLevels.isLevelValid(arguments.levelMax) AND 
     83                            arguments.levelMax gte getLevelMin() ){ 
     84                                instance.levelMax = arguments.levelMax; 
     85                        } 
     86                        else{ 
     87                                $throw("Invalid Log Level","The log level #arguments.levelMax# is invalid or less than the levelMin (#getLevelMin()#). Valid log levels are from 0 to 5","Logger.InvalidLogLevelException"); 
     88                        } 
     89                </cfscript> 
     90        </cffunction> 
    3791         
    3892        <!--- get/set category object. ---> 
     
    52106                <cfargument name="category" type="string"  required="false" default="" hint="The category to log this message under.  By default it is blank."/> 
    53107                <!--- ************************************************************* ---> 
    54                 <cfset arguments.category = getCategory()> 
    55                 <cfset this.logBox.debug(argumentCollection=arguments)> 
     108                <cfscript> 
     109                        arguments.category = getCategory(); 
     110                        if( hasAppenders() ){ 
     111                                arguments.severity = this.logLevels.DEBUG; 
     112                                logMessage(argumentCollection=arguments); 
     113                        } 
     114                        else{ 
     115                                this.logBox.debug(argumentCollection=arguments); 
     116                        } 
     117                </cfscript> 
    56118        </cffunction> 
    57119         
     
    63125                <cfargument name="category"  type="string"  required="false" default="" hint="The category to log this message under.  By default it is blank."/> 
    64126                <!--- ************************************************************* ---> 
    65                 <cfset arguments.category = getCategory()> 
    66                 <cfset this.logBox.info(argumentCollection=arguments)> 
     127                <cfscript> 
     128                        arguments.category = getCategory(); 
     129                        if( hasAppenders() ){ 
     130                                arguments.severity = this.logLevels.INFO; 
     131                                logMessage(argumentCollection=arguments); 
     132                        } 
     133                        else{ 
     134                                this.logBox.info(argumentCollection=arguments); 
     135                        } 
     136                </cfscript> 
    67137        </cffunction> 
    68138         
     
    74144                <cfargument name="category"  type="string"  required="false" default="" hint="The category to log this message under.  By default it is blank."/> 
    75145                <!--- ************************************************************* ---> 
    76                 <cfset arguments.category = getCategory()> 
    77                 <cfset this.logBox.trace(argumentCollection=arguments)> 
     146                <cfscript> 
     147                        arguments.category = getCategory(); 
     148                        if( hasAppenders() ){ 
     149                                arguments.severity = this.logLevels.TRACE; 
     150                                logMessage(argumentCollection=arguments); 
     151                        } 
     152                        else{ 
     153                                this.logBox.trace(argumentCollection=arguments); 
     154                        } 
     155                </cfscript> 
    78156        </cffunction> 
    79157         
     
    85163                <cfargument name="category"  type="string"  required="false" default="" hint="The category to log this message under.  By default it is blank."/> 
    86164                <!--- ************************************************************* ---> 
    87                 <cfset arguments.category = getCategory()> 
    88                 <cfset this.logBox.warn(argumentCollection=arguments)> 
     165                <cfscript> 
     166                        arguments.category = getCategory(); 
     167                        if( hasAppenders() ){ 
     168                                arguments.severity = this.logLevels.WARN; 
     169                                logMessage(argumentCollection=arguments); 
     170                        } 
     171                        else{ 
     172                                this.logBox.warn(argumentCollection=arguments); 
     173                        } 
     174                </cfscript> 
    89175        </cffunction> 
    90176         
     
    96182                <cfargument name="category"  type="string"  required="false" default="" hint="The category to log this message under.  By default it is blank."/> 
    97183                <!--- ************************************************************* ---> 
    98                 <cfset arguments.category = getCategory()> 
    99                 <cfset this.logBox.error(argumentCollection=arguments)> 
     184                <cfscript> 
     185                        arguments.category = getCategory(); 
     186                        if( hasAppenders() ){ 
     187                                arguments.severity = this.logLevels.ERROR; 
     188                                logMessage(argumentCollection=arguments); 
     189                        } 
     190                        else{ 
     191                                this.logBox.error(argumentCollection=arguments); 
     192                        } 
     193                </cfscript> 
    100194        </cffunction> 
    101195         
     
    107201                <cfargument name="category"  type="string"  required="false" default="" hint="The category to log this message under.  By default it is blank."/> 
    108202                <!--- ************************************************************* ---> 
    109                 <cfset arguments.category = getCategory()> 
    110                 <cfset this.logBox.fatal(argumentCollection=arguments)> 
    111         </cffunction> 
    112                  
     203                <cfscript> 
     204                        arguments.category = getCategory(); 
     205                        if( hasAppenders() ){ 
     206                                arguments.severity = this.logLevels.fatal; 
     207                                logMessage(argumentCollection=arguments); 
     208                        } 
     209                        else{ 
     210                                this.logBox.fatal(argumentCollection=arguments); 
     211                        } 
     212                </cfscript> 
     213        </cffunction> 
     214         
     215        <!--- canLog ---> 
     216        <cffunction name="canLog" output="false" access="public" returntype="boolean" hint="Checks wether a log can be made on this appender using a passed in level"> 
     217                <cfargument name="level" type="numeric" required="true" default="" hint="The level to check"/> 
     218                <cfscript> 
     219                        return (arguments.level GTE getLevelMin() AND arguments.level LTE getLevelMax() ); 
     220                </cfscript> 
     221        </cffunction> 
     222         
    113223<!------------------------------------------- PRIVATE ------------------------------------------> 
    114224 
    115  
     225        <!--- logMessage ---> 
     226        <cffunction name="logMessage" output="false" access="private" returntype="void" hint="Write an entry into the loggers registered with this LogBox instance."> 
     227                <!--- ************************************************************* ---> 
     228                <cfargument name="message"       type="string"  required="true"   hint="The message to log."> 
     229                <cfargument name="severity"  type="numeric" required="true"   hint="The severity level to log."> 
     230                <cfargument name="extraInfo" type="any"     required="false" default="" hint="Extra information to send to the loggers."> 
     231                <cfargument name="category"  type="string"  required="false" default="" hint="The category to log this message under.  By default it is blank."/> 
     232                <!--- ************************************************************* ---> 
     233                <cfscript> 
     234                        // Loop over loggers 
     235                        var appenders = getAppenders(); 
     236                        var key = ""; 
     237                        var thisAppender = ""; 
     238                        var logEvent = ""; 
     239                         
     240                        // If message empty, just exit 
     241                        arguments.message = trim(arguments.message); 
     242                        if( NOT len(arguments.message) ){ return; } 
     243                         
     244                        // Check if category can log? 
     245                        if( canLog(arguments.severity) ){ 
     246                                // Create Logging Event 
     247                                logEvent = createobject("component","coldbox.system.logging.LogEvent").init(argumentCollection=arguments);               
     248                                         
     249                                // Delegate Calls 
     250                                for(key in appenders){ 
     251                                        // Get Appender 
     252                                        thisAppender = appenders[key]; 
     253                                        // Log the message in the appender 
     254                                        thisAppender.logMessage(logEvent); 
     255                                } 
     256                        } 
     257                </cfscript>      
     258        </cffunction> 
     259         
     260        <!--- Throw Facade ---> 
     261        <cffunction name="$throw" access="private" hint="Facade for cfthrow" output="false"> 
     262                <!--- ************************************************************* ---> 
     263                <cfargument name="message"      type="string"   required="yes"> 
     264                <cfargument name="detail"       type="string"   required="no" default=""> 
     265                <cfargument name="type"         type="string"   required="no" default="Framework"> 
     266                <!--- ************************************************************* ---> 
     267                <cfthrow type="#arguments.type#" message="#arguments.message#"  detail="#arguments.detail#"> 
     268        </cffunction> 
    116269</cfcomponent> 
  • coldbox/trunk/system/logging/appenders/CFAppender.cfc

    r2362 r2363  
    88Date        :   04/12/2009 
    99Description : 
    10         A simple CF Logger 
     10        A simple CF appender 
    1111         
    1212Properties: 
     
    1414- logType : file or application 
    1515-----------------------------------------------------------------------> 
    16 <cfcomponent name="CFLogger"  
     16<cfcomponent name="CFAppender"  
    1717                         extends="coldbox.system.logging.AbstractAppender"  
    1818                         output="false" 
    19                          hint="A simple CF Logger"> 
     19                         hint="A simple CF Appender"> 
    2020         
    2121        <!--- Init ---> 
    22         <cffunction name="init" access="public" returntype="CFLogger" hint="Constructor called by a Concrete Logger" output="false" > 
     22        <cffunction name="init" access="public" returntype="CFAppender" hint="Constructor" output="false" > 
    2323                <!--- ************************************************************* ---> 
    24                 <cfargument name="name"                 type="string"  required="true" hint="The unique name for this logger."/> 
    25                 <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this logger, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
    26                 <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this logger, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
    27                 <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the logger"/> 
     24                <cfargument name="name"                 type="string"  required="true" hint="The unique name for this appender."/> 
     25                <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
     26                <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
     27                <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the appender"/> 
    2828                <!--- ************************************************************* ---> 
    2929                <cfscript> 
     
    4040                                        $throw(message="Invalid logtype choosen #getProperty("logType")#", 
    4141                                                   detail="Valid types are file or application", 
    42                                                    type="CFLogger.InvalidLogTypeException"); 
     42                                                   type="CFAppender.InvalidLogTypeException"); 
    4343                                } 
    4444                        } 
     
    4949         
    5050        <!--- Log Message ---> 
    51         <cffunction name="logMessage" access="public" output="false" returntype="void" hint="Write an entry into the logger."> 
     51        <cffunction name="logMessage" access="public" output="false" returntype="void" hint="Write an entry into the appender."> 
    5252                <!--- ************************************************************* ---> 
    53                 <cfargument name="message"       type="string"   required="true"   hint="The message to log."> 
    54                 <cfargument name="severity"  type="numeric"  required="true"   hint="The severity level to log."> 
    55                 <cfargument name="extraInfo" type="any"      required="no" default="" hint="Extra information to send to the loggers."> 
     53                <cfargument name="logEvent" type="coldbox.system.logging.LogEvent" required="true" hint="The logging event"/> 
    5654                <!--- ************************************************************* ---> 
     55                <cfset var loge = arguments.logEvent> 
    5756                 
    5857                <cfif getProperty("logType") eq "file"> 
    5958                        <cflog file="#getName()#"  
    60                                    type="#this.logLevels.lookup(arguments.severity)#" 
    61                                    text="#arguments.message#"> 
     59                                   type="#severityToString(loge.getSeverity())#" 
     60                                   text="#loge.getCategory()# #loge.getMessage()#"> 
    6261                <cfelse> 
    6362                        <cflog log="Application" 
    64                                    type="#this.logLevels.lookup(arguments.severity)#" 
    65                                    text="#arguments.message#"> 
     63                                   type="#severityToString(loge.getSeverity())#" 
     64                                   text="#loge.getCategory()# #loge.getMessage()#"> 
    6665                </cfif> 
    6766                            
  • coldbox/trunk/system/logging/appenders/ConsoleAppender.cfc

    r2362 r2363  
    88Date        :   04/12/2009 
    99Description : 
    10         A simple ConsoleLogger 
     10        A simple ConsoleAppender 
    1111         
    1212Properties: 
    1313- none 
    1414-----------------------------------------------------------------------> 
    15 <cfcomponent name="ConsoleLogger"  
     15<cfcomponent name="ConsoleAppender"  
    1616                         extends="coldbox.system.logging.AbstractAppender"  
    1717                         output="false" 
    18                          hint="A simple Console Logger"> 
     18                         hint="A simple Console Appender"> 
    1919         
    2020        <!--- Init ---> 
    21         <cffunction name="init" access="public" returntype="CFLogger" hint="Constructor called by a Concrete Logger" output="false" > 
     21        <cffunction name="init" access="public" returntype="ConsoleAppender" hint="Constructor" output="false" > 
    2222                <!--- ************************************************************* ---> 
    23                 <cfargument name="name"                 type="string"  required="true" hint="The unique name for this logger."/> 
    24                 <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this logger, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
    25                 <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this logger, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
    26                 <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the logger"/> 
     23                <cfargument name="name"                 type="string"  required="true" hint="The unique name for this appender."/> 
     24                <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
     25                <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
     26                <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the appender"/> 
    2727                <!--- ************************************************************* ---> 
    2828                <cfscript> 
     
    3737         
    3838        <!--- Log Message ---> 
    39         <cffunction name="logMessage" access="public" output="false" returntype="void" hint="Write an entry into the logger."> 
     39        <cffunction name="logMessage" access="public" output="false" returntype="void" hint="Write an entry into the appender."> 
    4040                <!--- ************************************************************* ---> 
    41                 <cfargument name="message"       type="string"   required="true"   hint="The message to log."> 
    42                 <cfargument name="severity"  type="numeric"  required="true"   hint="The severity level to log."> 
    43                 <cfargument name="extraInfo" type="any"      required="no" default="" hint="Extra information to send to the loggers."> 
     41                <cfargument name="logEvent" type="coldbox.system.logging.LogEvent" required="true" hint="The logging event"/> 
    4442                <!--- ************************************************************* ---> 
    4543                <cfscript> 
    4644                        var extra = ""; 
     45                        var loge = arguments.logEvent; 
     46                         
    4747                        try{ 
    48                                 extra = arguments.extraInfo.toString(); 
     48                                extra = loge.extraInfo.toString(); 
    4949                        } 
    5050                        catch(Any e){ 
    51                                 $log("ERROR","Extrainfo toString() failed on #getName()# logger. #e.message# #e.detail#"); 
     51                                $log("ERROR","Extrainfo toString() failed on #getName()# appender. #e.message# #e.detail#"); 
    5252                        } 
    53                         instance.out.println(" #this.logLevels.lookup(arguments.severity)# #arguments.message# #chr(13)# #extra#"); 
     53                         
     54                        // Log message 
     55                        instance.out.println("#severityToString(loge.getseverity())# #loge.getCategory()# #loge.getmessage()# #chr(13)# #extra#"); 
    5456                </cfscript>                         
    5557        </cffunction> 
  • coldbox/trunk/system/logging/appenders/DBAppender.cfc

    r2362 r2363  
    88Date        :   04/12/2009 
    99Description : 
    10  A simple DB logger for MySQL, MSSQL, Oracle, PostgreSQL 
     10 A simple DB appender for MySQL, MSSQL, Oracle, PostgreSQL 
    1111 
    1212Inspiration from Tim Blair <tim@bla.ir> cflogger project. 
     
    2424 - category : string 
    2525 - logdate : timestamp 
    26  - loggername : string 
     26 - appendername : string 
    2727 - message : string 
    2828 
     
    3030 
    3131-----------------------------------------------------------------------> 
    32 <cfcomponent name="DBLogger"  
     32<cfcomponent name="DBAppender"  
    3333                         extends="coldbox.system.logging.AbstractAppender"  
    3434                         output="false" 
    35                          hint="This is a simple implementation of a logger that is db based."> 
     35                         hint="This is a simple implementation of a appender that is db based."> 
    3636         
    3737        <!--- Init ---> 
    38         <cffunction name="init" access="public" returntype="DBLogger" hint="Constructor called by a Concrete Logger" output="false" > 
     38        <cffunction name="init" access="public" returntype="DBAppender" hint="Constructor" output="false" > 
    3939                <!--- ************************************************************* ---> 
    40                 <cfargument name="name"                 type="string"  required="true" hint="The unique name for this logger."/> 
    41                 <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this logger, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
    42                 <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this logger, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
    43                 <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the logger"/> 
     40                <cfargument name="name"                 type="string"  required="true" hint="The unique name for this appender."/> 
     41                <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
     42                <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
     43                <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the appender"/> 
    4444                <!--- ************************************************************* ---> 
    4545                <cfscript> 
     
    4949                        // Verify properties 
    5050                        if( NOT propertyExists('dsn') ){  
    51                                 $throw(message="No dsn property defined",type="DBLogger.InvalidProperty");  
     51                                $throw(message="No dsn property defined",type="DBAppender.InvalidProperty");  
    5252                        } 
    5353                        if( NOT propertyExists('table') ){  
    54                                 $throw(message="No table property defined",type="DBLogger.InvalidProperty");  
     54                                $throw(message="No table property defined",type="DBAppender.InvalidProperty");  
    5555                        } 
    5656                        if( NOT propertyExists('autoCreate') OR NOT isBoolean(getProperty('autoCreate')) ){  
     
    6565                         
    6666                        // columns 
    67                         instance.columns = "id,severity,category,logdate,loggername,message"; 
     67                        instance.columns = "id,severity,category,logdate,appendername,message"; 
    6868                                                 
    6969                        return this; 
     
    8282         
    8383        <!--- Log Message ---> 
    84         <cffunction name="logMessage" access="public" output="false" returntype="void" hint="Write an entry into the logger."> 
     84        <cffunction name="logMessage" access="public" output="false" returntype="void" hint="Write an entry into the appender."> 
    8585                <!--- ************************************************************* ---> 
    86                 <cfargument name="message"       type="string"   required="true"   hint="The message to log."> 
    87                 <cfargument name="severity"  type="numeric"  required="true"   hint="The severity level to log."> 
    88                 <cfargument name="extraInfo" type="any"      required="no" default="" hint="Extra information to send to the loggers."> 
     86                <cfargument name="logEvent" type="coldbox.system.logging.LogEvent" required="true" hint="The logging event"/> 
    8987                <!--- ************************************************************* ---> 
    9088                <cfscript> 
     
    9391                        var cmap = ""; 
    9492                        var cols = ""; 
     93                        var loge = arguments.logEvent; 
    9594                         
    9695                        // Check Category Sent? 
    97                         if ( isStruct(arguments.extraInfo) and structKeyExists(arguments.extraInfo,"Category") ){ 
    98                                 category = arguments.extraInfo.category; 
     96                        if( NOT loge.getCategory() eq "" ){ 
     97                                category = loge.getCategory(); 
    9998                        } 
     99                         
    100100                        // Column Maps 
    101101                        if( propertyExists('columnMap') ){ 
    102102                                cmap = getProperty('columnMap'); 
    103                                 cols = "#cmap.id#,#cmap.severity#,#cmap.category#,#cmap.logdate#,#cmap.loggername#,#cmap.message#"; 
     103                                cols = "#cmap.id#,#cmap.severity#,#cmap.category#,#cmap.logdate#,#cmap.appendername#,#cmap.message#"; 
    104104                        } 
    105105                        else{ 
     
    112112                        INSERT INTO #getProperty('table')# (#cols#) VALUES ( 
    113113                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#createUUID()#">, 
    114                                 <cfqueryparam cfsqltype="cf_sql_varchar" value="#this.logLevels.lookup(arguments.severity)#">, 
     114                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#severityToString(loge.getseverity())#">, 
    115115                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#category#">, 
    116                                 <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">, 
     116                                <cfqueryparam cfsqltype="cf_sql_timestamp" value="#loge.getTimestamp()#">, 
    117117                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#left(getName(),100)#">, 
    118                                 <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.message#"> 
     118                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#loge.getmessage()#"> 
    119119                        ) 
    120120                </cfquery> 
     
    129129                         
    130130                        if( NOT structKeyExists(datasources, getProperty('dsn')) ){ 
    131                                 $throw(message="The dsn #getProperty("dsn")# does not exist. Please create it before using this DBLogger",type="DBLogger.DSNException"); 
     131                                $throw(message="The dsn #getProperty("dsn")# does not exist. Please create it before using this DBAppender",type="DBAppender.DSNException"); 
    132132                        }                        
    133133                </cfscript> 
     
    170170                        <!--- Throw Error ---> 
    171171                        <cfthrow message="Table #getProperty('table')# was not found in the defined datasource: #dsn#. Please create the appropriate logging table." 
    172                                          detail="The autocreate property for this logger is set to false." 
    173                                          type="DBLogger.TableNotFoundException"> 
     172                                         detail="The autocreate property for this appender is set to false." 
     173                                         type="DBAppender.TableNotFoundException"> 
    174174                </cfif> 
    175175        </cffunction> 
     
    182182                        for(key in map){ 
    183183                                if( NOT listFindNoCase(instance.columns,key) ){ 
    184                                         $throw(message="Invalid column map key: #key#",detail="The available keys are #instance.columns#",type="DBLogger.InvalidColumnMapException"); 
     184                                        $throw(message="Invalid column map key: #key#",detail="The available keys are #instance.columns#",type="DBAppender.InvalidColumnMapException"); 
    185185                                } 
    186186                        } 
  • coldbox/trunk/system/logging/appenders/FileAppender.cfc

    r2362 r2363  
    2020        <cffunction name="init" access="public" returntype="SimpleLogger" hint="Constructor" output="false"> 
    2121                <!--- ************************************************************* ---> 
    22                 <cfargument name="name"                 type="string"  required="true" hint="The unique name for this logger."/> 
    23                 <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this logger, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
    24                 <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this logger, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
    25                 <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the logger"/> 
     22                <cfargument name="logEvent" type="coldbox.system.logging.LogEvent" required="true" hint="The logging event"/> 
    2623                <!--- ************************************************************* ---> 
    2724                <cfscript> 
  • coldbox/trunk/system/logging/appenders/ScopeAppender.cfc

    r2362 r2363  
    88Date        :   04/12/2009 
    99Description : 
    10         A simple Scope Logger that logs to a specified scope. 
     10        A simple Scope Appender that logs to a specified scope. 
    1111 
    1212Inspiration from Tim Blair <tim@bla.ir> by the cflogger project 
     
    1414Properties: 
    1515- scope : the scope to persist to, defaults to request (optional) 
    16 - key   : the key to use in the scope, it defaults to the name of the logger (optional) 
     16- key   : the key to use in the scope, it defaults to the name of the Appender (optional) 
    1717- limit : a limit to the amount of logs to rotate. Defaults to 0, unlimited (optional) 
    1818 
    1919-----------------------------------------------------------------------> 
    20 <cfcomponent name="ScopeLogger"  
     20<cfcomponent name="ScopeAppender"  
    2121                         extends="coldbox.system.logging.AbstractAppender"  
    2222                         output="false" 
    23                          hint="A simple CF Logger"> 
     23                         hint="A scope appender"> 
    2424         
    2525        <!--- Init ---> 
    26         <cffunction name="init" access="public" returntype="ScopeLogger" hint="Constructor" output="false" > 
     26        <cffunction name="init" access="public" returntype="ScopeAppender" hint="Constructor" output="false" > 
    2727                <!--- ************************************************************* ---> 
    28                 <cfargument name="name"                 type="string"  required="true" hint="The unique name for this logger."/> 
    29                 <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this logger, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
    30                 <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this logger, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
    31                 <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the logger"/> 
     28                <cfargument name="name"                 type="string"  required="true" hint="The unique name for this appender."/> 
     29                <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
     30                <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
     31                <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the appender"/> 
    3232                <!--- ************************************************************* ---> 
    3333                <cfscript> 
     
    5656         
    5757        <!--- Log Message ---> 
    58         <cffunction name="logMessage" access="public" output="true" returntype="void" hint="Write an entry into the logger."> 
     58        <cffunction name="logMessage" access="public" output="true" returntype="void" hint="Write an entry into the appender."> 
    5959                <!--- ************************************************************* ---> 
    60                 <cfargument name="message"       type="string"   required="true"   hint="The message to log."> 
    61                 <cfargument name="severity"  type="numeric"  required="true"   hint="The severity level to log."> 
    62                 <cfargument name="extraInfo" type="any"      required="no" default="" hint="Extra information to send to the loggers."> 
     60                <cfargument name="logEvent" type="coldbox.system.logging.LogEvent" required="true" hint="The logging event"/> 
    6361                <!--- ************************************************************* ---> 
    6462                <cfscript> 
     
    6664                        var entry = structnew(); 
    6765                        var limit = getProperty('limit'); 
     66                        var loge = arguments.logEvent; 
    6867                         
    6968                        // Verify storage 
     
    8079                        // Log Away 
    8180                        entry.id = createUUID(); 
    82                         entry.logDate = now(); 
    83                         entry.loggerName = getName(); 
    84                         entry.severity = this.logLevels.lookup(arguments.severity); 
    85                         entry.message = arguments.message; 
    86                         entry.extraInfo = arguments.extraInfo.toString(); 
     81                        entry.logDate = loge.getTimeStamp(); 
     82                        entry.appenderName = getName(); 
     83                        entry.severity = severityToString(loge.getseverity()); 
     84                        entry.message = loge.getMessage(); 
     85                        entry.extraInfo = loge.getextraInfo().toString(); 
     86                        entry.category = loge.getCategory(); 
    8787                         
    8888                        // Save Storage 
  • coldbox/trunk/system/logging/config/LogBoxConfig.cfc

    r2362 r2363  
    1919                // Instance private scope 
    2020                instance = structnew(); 
    21                 instance.appenders = arraynew(1); 
     21                instance.appenders = createObject("java", "java.util.Collections").synchronizedMap(CreateObject("java","java.util.LinkedHashMap").init(3)); 
     22                instance.categories = structnew(); 
    2223        </cfscript> 
    2324 
     
    2728        </cffunction> 
    2829 
    29         <!--- addLogger ---> 
    30         <cffunction name="add" output="false" access="public" returntype="void" hint="Add an appender configuration"> 
     30        <!--- addAppender ---> 
     31        <cffunction name="addAppender" output="false" access="public" returntype="void" hint="Add an appender configuration"> 
    3132                <cfargument name="name"                 type="string"  required="true"  hint="A unique name for the appender to register. Only unique names can be registered per instance."/> 
    3233                <cfargument name="class"                type="string"  required="true"  hint="The appender's class to register. We will create, init it and register it for you."/> 
     
    3435                <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
    3536                <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="The structure of properties to configure this appender with."/> 
    36                 <cfset arrayAppend(getAppenders(),arguments)> 
     37                <cfset instance.appenders[arguments.name] = arguments> 
     38        </cffunction> 
     39         
     40        <!--- addCategory ---> 
     41        <cffunction name="addCategory" output="false" access="public" returntype="void" hint="Add a new category configuration with appender(s).  Appenders MUST be defined first, else this method will throw an exception"> 
     42                <cfargument name="name"                 type="string"  required="true"  hint="A unique name for the appender to register. Only unique names can be registered per instance."/> 
     43                <cfargument name="levelMin"     type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARNING"/> 
     44                <cfargument name="levelMax"     type="numeric" required="false" default="5" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARNING"/> 
     45                <cfargument name="appenders"    type="string"  required="true"  hint="A list of appender names to configure this category with."/> 
     46                <cfscript> 
     47                        var x = 1; 
     48                         
     49                        // Verify Appenders first 
     50                        for(x=1; x lte listlen(arguments.appenders); x=x+1){ 
     51                                if( NOT structKeyExists(instance.appenders, listGetAt(arguments.appenders,x)) ){ 
     52                                        $throw(message="Invalid appender", 
     53                                                   detail="The appender #listGetAt(arguments.appenders,x)# has not been defined yet. Please define it first.", 
     54                                                   type="LogBoxConfig.AppenderNotFound"); 
     55                                } 
     56                        } 
     57                        // Add category registration 
     58                        instance.categories[arguments.name] = arguments; 
     59                </cfscript> 
     60        </cffunction> 
     61         
     62        <!--- getCategory ---> 
     63        <cffunction name="getCategory" output="false" access="public" returntype="struct" hint="Get a specifed category definition"> 
     64                <cfargument name="name" type="string" required="true" hint="The category to retrieve"/> 
     65                <cfreturn instance.categories[arguments.name]> 
     66        </cffunction> 
     67         
     68        <!--- categoryExists ---> 
     69        <cffunction name="categoryExists" output="false" access="public" returntype="boolean" hint="Check if a category definition exists"> 
     70                <cfargument name="name" type="string" required="true" hint="The category to retrieve"/> 
     71                <cfreturn structKeyExists(instance.categories, arguments.name)> 
     72        </cffunction> 
     73         
     74        <!--- getCategories ---> 
     75        <cffunction name="getCategories" output="false" access="public" returntype="struct" hint="Get the configured categories"> 
     76                <cfreturn instance.categories> 
    3777        </cffunction> 
    3878         
    3979        <!--- getappenders ---> 
    40         <cffunction name="getAppenders" output="false" access="public" returntype="array" hint="Get all the appenders defined"> 
     80        <cffunction name="getAppenders" output="false" access="public" returntype="struct" hint="Get all the appenders defined"> 
    4181                <cfreturn instance.appenders> 
    4282        </cffunction> 
    4383 
     84<!------------------------------------------- PRIVATE ------------------------------------------> 
     85 
     86 
     87        <!--- Throw Facade ---> 
     88        <cffunction name="$throw" access="private" hint="Facade for cfthrow" output="false"> 
     89                <!--- ************************************************************* ---> 
     90                <cfargument name="message"      type="string"   required="yes"> 
     91                <cfargument name="detail"       type="string"   required="no" default=""> 
     92                <cfargument name="type"         type="string"   required="no" default="Framework"> 
     93                <!--- ************************************************************* ---> 
     94                <cfthrow type="#arguments.type#" message="#arguments.message#"  detail="#arguments.detail#"> 
     95        </cffunction> 
     96         
    4497</cfcomponent> 
  • coldbox/trunk/testing/cases/logging/LogBoxTest.cfc

    r2362 r2363  
    5555                logger = logBox.getLogger('MyCat');      
    5656        } 
     57         
    5758</cfscript> 
    5859</cfcomponent> 
  • coldbox/trunk/testing/cases/logging/appenders/CFAppenderTest.cfc

    r2362 r2363  
    44                cf = getMockBox().createMock(className="coldbox.system.logging.appenders.CFAppender"); 
    55                cf.init('MyCFLogger',0,5); 
     6                 
     7                loge = getMockBox().createMock(className="coldbox.system.logging.LogEvent"); 
     8                loge.init("Unit Test Sample",0,structnew(),"UnitTest"); 
    69        } 
    710         
    811        function testLogMessage(){ 
    9                 cf.logMessage("Unit Test Sample",3); 
     12                cf.logMessage(loge); 
    1013                props = {logType="application"}; 
    1114                cf.init('MyCFLogger',0,5,props); 
    12                 cf.logMessage("Application Test Sample",3); 
     15                cf.logMessage(loge); 
    1316        }        
    1417</cfscript> 
  • coldbox/trunk/testing/cases/logging/appenders/ConsoleAppenderTest.cfc

    r2362 r2363  
    44                console = getMockBox().createMock(className="coldbox.system.logging.appenders.ConsoleAppender"); 
    55                console.init('MyConsoleAppender',5); 
     6                 
     7                loge = getMockBox().createMock(className="coldbox.system.logging.LogEvent"); 
     8                loge.init("Unit Test Sample",0,structnew(),"UnitTest"); 
    69        } 
    710        function testLogMessage(){ 
    811                for(x=0; x lte 5; x++){ 
    9                         console.logMessage("I am sending amessage to the console man",x); 
     12                        loge.setSeverity(x); 
     13                        loge.setCategory("coldbox.system.testing"); 
     14                        console.logMessage(loge); 
    1015                } 
    1116        }        
  • coldbox/trunk/testing/cases/logging/appenders/DBAppenderTest.cfc

    r2362 r2363  
    22<cfscript> 
    33        function setup(){ 
    4                 props = {dsn='testmssql',table='logs',autocreate='true'}; 
     4                props = {dsn='test',table='logs',autocreate='true'}; 
    55                db = getMockBox().createMock(className="coldbox.system.logging.appenders.DBAppender"); 
    66                db.init('UnitTest',0,5,props); 
     7                 
     8                loge = getMockBox().createMock(className="coldbox.system.logging.LogEvent"); 
     9                loge.init("Unit Test Sample",0,structnew(),"UnitTest"); 
    710        } 
    811         
     
    1821                        fail('invalid dsn'); 
    1922                } 
    20                 catch("DBLogger.DSNException" e){} 
     23                catch("DBAppender.DSNException" e){} 
    2124                catch(Any e){ fail(e.message & e.detail);} 
    2225        } 
     
    2831         
    2932        function testLogMessage(){ 
    30                 db.logMessage("My First Test",1); 
     33                db.logMessage(loge); 
    3134        } 
    3235        function testLogMessageWithColumnMap(){ 
     
    3740                        category = "category", 
    3841                        logdate = "logdate", 
    39                         loggername = "loggername", 
     42                        appendername = "appendername", 
    4043                        messsage = "message" 
    4144                }; 
     
    4548                        fail('map should have failed'); 
    4649                } 
    47                 catch("DBLogger.InvalidColumnMapException" e){} 
     50                catch("DBAppender.InvalidColumnMapException" e){} 
    4851                catch(any e ){fail(e.message & e.detail);} 
    4952                 
     
    5457                        category = "category", 
    5558                        logdate = "logdate", 
    56                         loggername = "loggername", 
     59                        appendername = "appendername", 
    5760                        message = "message" 
    5861                }; 
     
    6063                db.init('UnitTest',0,5,props); 
    6164                         
    62                 db.logMessage(message="My First Test",severity=1); 
     65                db.logMessage(loge); 
    6366        } 
    6467</cfscript> 
  • coldbox/trunk/testing/cases/logging/appenders/ScopeAppenderTest.cfc

    r2362 r2363  
    55                scope = getMockBox().createMock(className="coldbox.system.logging.appenders.ScopeAppender"); 
    66                scope.init('MyScopeLogger',0,5,prop); 
     7                 
     8                loge = getMockBox().createMock(className="coldbox.system.logging.LogEvent"); 
     9                loge.init("Unit Test Sample",0,structnew(),"UnitTest"); 
    710        } 
    811         
    912        function testLogMessage(){ 
    10                 scope.logMessage("Unit Test Sample",3); 
    11                 scope.logMessage("Application Test Sample",0,3, structnew()); 
    12                 scope.logMessage("Unit Test Sample",3); 
     13                scope.logMessage(loge); 
     14                scope.logMessage(loge); 
     15                scope.logMessage(loge); 
    1316                 
    1417                debug(request); 
  • coldbox/trunk/testing/cases/logging/config/LogBoxConfigTest.cfc

    r2361 r2363  
    44                config = getMockBox().createMock(className="coldbox.system.logging.config.LogBoxConfig").init(); 
    55        } 
    6         function testAdd(){ 
    7                 config.add("luis","coldbox.system.logging.AbstractLogger"); 
    8                 config.add("luis2","coldbox.system.logging.AbstractLogger"); 
     6        function testAddAppender(){ 
     7                config.addAppender("luis","coldbox.system.logging.AbstractLogger"); 
     8                config.addAppender("luis2","coldbox.system.logging.AbstractLogger"); 
    99                 
    10                 assertEquals( arraylen(config.getLoggers()), 2); 
     10                assertEquals( structCount(config.getAppenders()), 2); 
     11        } 
     12        function testAddCategory(){ 
     13                try{ 
     14                        config.addCategory(name="ses",levelMin=0,levelMax=2,appenders="luis,2"); 
     15                        fail("This should have failed."); 
     16                } 
     17                catch("LogBoxConfig.AppenderNotFound" e){} 
     18                catch(Any e){ 
     19                        fail(e.message & e.detail); 
     20                } 
     21                 
     22                config.addAppender("luis","coldbox.system.logging.AbstractLogger"); 
     23                config.addAppender("luis2","coldbox.system.logging.AbstractLogger"); 
     24                config.addCategory(name="ses",levelMin=0,levelMax=2,appenders="luis,luis2"); 
    1125        } 
    1226</cfscript>