Changeset 2365

Show
Ignore:
Timestamp:
07/05/09 08:12:37 (4 years ago)
Author:
lmajano
Message:

LogBox? all appenders finalzied and tested.

Location:
coldbox/trunk
Files:
11 added
10 modified

Legend:

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

    r2364 r2365  
    1717                // The log levels enum as a public property 
    1818                this.logLevels = createObject("component","coldbox.system.logging.LogLevels"); 
     19                // Populated when appender is created, public by default 
     20                this.logBox = ""; 
    1921                 
    2022                // private instance scope 
     
    7274        </cffunction> 
    7375         
     76        <!--- Get a reference to the main log box instance used. ---> 
     77        <cffunction name="getlogBox" access="public" returntype="coldbox.system.logging.LogBox" output="false"> 
     78                <cfreturn this.logBox> 
     79        </cffunction> 
     80         
    7481        <!--- getHash ---> 
    7582        <cffunction name="getHash" output="false" access="public" returntype="string" hint="Get this appender's unique ID"> 
     
    179186         
    180187        <!--- $log ---> 
    181         <cffunction name="$log" output="false" access="private" returntype="void" hint="Log an internal message to the ColdFusion facilities.  Used when errors ocurrs or diagnostics"> 
     188        <cffunction name="$log" output="false" access="public" returntype="void" hint="Log an internal message to the ColdFusion facilities.  Used when errors ocurrs or diagnostics"> 
    182189                <cfargument name="severity" type="string" required="true" default="INFO" hint="The severity to use."/> 
    183190                <cfargument name="message" type="string" required="true" default="" hint="The message to log"/> 
  • coldbox/trunk/system/logging/LogBox.cfc

    r2364 r2365  
    5959         
    6060        <!--- configure ---> 
    61         <cffunction name="configure" output="false" access="public." returntype="void" hint="Configure logbox for operation. You can also re-configure LogBox programmatically. Basically we register all appenders here and all categories"> 
     61        <cffunction name="configure" output="false" access="public" returntype="void" hint="Configure logbox for operation. You can also re-configure LogBox programmatically. Basically we register all appenders here and all categories"> 
    6262                <cfargument name="logBoxConfig" type="coldbox.system.logging.config.LogBoxConfig" required="true" hint="The LogBoxConfig object to use to configure this instance of LogBox"/> 
    6363                <cfscript> 
     
    167167                                <cfscript> 
    168168                                        if( NOT appenderExists(name) ){ 
     169                                                // Verify LogBox 
     170                                                if( NOT structKeyExists(arguments.appender,"logBox") OR NOT isObject(arguments.appender.logBox) ){ 
     171                                                        arguments.appender.logBox = this; 
     172                                                } 
    169173                                                // Store Logger 
    170174                                                getAppenders().put(name, arguments.appender) 
     
    192196                <cfscript> 
    193197                        // Create new appender object 
    194                         var appender = createObject("component",arguments.class).init(argumentCollection=arguments); 
    195                          
     198                        var appender = createObject("component",arguments.class); 
     199                        // Inject logBox 
     200                        appender.logBox = this; 
     201                        // init it 
     202                        appender.init(argumentCollection=arguments); 
    196203                        // Register it 
    197204                        register(appender); 
  • coldbox/trunk/system/logging/LogEvent.cfc

    r2363 r2365  
    3030                        var key = ""; 
    3131                        for(key in arguments){ 
     32                                if( isSimpleValue(arguments[key]) ){ 
     33                                        arguments[key] = trim(arguments[key]);   
     34                                } 
    3235                                instance[key] = arguments[key]; 
    3336                        } 
     
    3639        </cffunction> 
    3740         
     41        <cffunction name="getextraInfoAsString" access="public" returntype="string" output="false"> 
     42                <cfset var info = instance.extraInfo> 
     43                <cfif NOT isSimpleValue(info)> 
     44                        <cfreturn info.toString()> 
     45                <cfelse> 
     46                        <cfreturn info> 
     47                </cfif> 
     48        </cffunction> 
    3849        <cffunction name="getextraInfo" access="public" returntype="any" output="false"> 
    3950                <cfreturn instance.extraInfo> 
  • coldbox/trunk/system/logging/appenders/CFAppender.cfc

    r2363 r2365  
    5858                        <cflog file="#getName()#"  
    5959                                   type="#severityToString(loge.getSeverity())#" 
    60                                    text="#loge.getCategory()# #loge.getMessage()#"> 
     60                                   text="#loge.getCategory()# #loge.getMessage()# ExtraInfo: #loge.getextraInfoAsString()#"> 
    6161                <cfelse> 
    6262                        <cflog log="Application" 
    6363                                   type="#severityToString(loge.getSeverity())#" 
    64                                    text="#loge.getCategory()# #loge.getMessage()#"> 
     64                                   text="#loge.getCategory()# #loge.getMessage()# ExtraInfo: #loge.getextraInfoAsString()#"> 
    6565                </cfif> 
    6666                            
  • coldbox/trunk/system/logging/appenders/ConsoleAppender.cfc

    r2363 r2365  
    4545                        var loge = arguments.logEvent; 
    4646                         
    47                         try{ 
    48                                 extra = loge.extraInfo.toString(); 
    49                         } 
    50                         catch(Any e){ 
    51                                 $log("ERROR","Extrainfo toString() failed on #getName()# appender. #e.message# #e.detail#"); 
    52                         } 
    53                          
    5447                        // Log message 
    55                         instance.out.println("#severityToString(loge.getseverity())# #loge.getCategory()# #loge.getmessage()# #chr(13)# #extra#"); 
     48                        instance.out.println("#severityToString(loge.getseverity())# #loge.getCategory()# #loge.getmessage()# ExtraInfo: #loge.getextraInfoAsString()#"); 
    5649                </cfscript>                         
    5750        </cffunction> 
  • coldbox/trunk/system/logging/appenders/DBAppender.cfc

    r2363 r2365  
    2626 - appendername : string 
    2727 - message : string 
     28 - extrainfo : string 
    2829 
    2930If you are building a mapper, the map must have the above keys in it. 
     
    6566                         
    6667                        // columns 
    67                         instance.columns = "id,severity,category,logdate,appendername,message"; 
     68                        instance.columns = "id,severity,category,logdate,appendername,message,extrainfo"; 
    6869                                                 
    6970                        return this; 
     
    9293                        var cols = ""; 
    9394                        var loge = arguments.logEvent; 
     95                        var message = loge.getMessage(); 
    9496                         
    9597                        // Check Category Sent? 
     
    101103                        if( propertyExists('columnMap') ){ 
    102104                                cmap = getProperty('columnMap'); 
    103                                 cols = "#cmap.id#,#cmap.severity#,#cmap.category#,#cmap.logdate#,#cmap.appendername#,#cmap.message#"; 
     105                                cols = "#cmap.id#,#cmap.severity#,#cmap.category#,#cmap.logdate#,#cmap.appendername#,#cmap.message#,#cmap.extrainfo#"; 
    104106                        } 
    105107                        else{ 
     
    116118                                <cfqueryparam cfsqltype="cf_sql_timestamp" value="#loge.getTimestamp()#">, 
    117119                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#left(getName(),100)#">, 
    118                                 <cfqueryparam cfsqltype="cf_sql_varchar" value="#loge.getmessage()#"> 
     120                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#loge.getMessage()#">, 
     121                                <cfqueryparam cfsqltype="cf_sql_varchar" value="#loge.getExtraInfoAsString()#"> 
    119122                        ) 
    120123                </cfquery> 
     
    164167                                        #listgetAt(cols,5)# VARCHAR(100) NOT NULL, 
    165168                                        #listgetAt(cols,6)# TEXT, 
     169                                        #listgetAt(cols,7)# TEXT, 
    166170                                        PRIMARY KEY (id) 
    167171                                ) 
  • coldbox/trunk/system/logging/appenders/FileAppender.cfc

    r2363 r2365  
    88Date        :   3/13/2009 
    99Description : 
    10         Simple File Logger 
     10        Simple File Appender 
     11         
     12Properties: 
     13 
     14- filepath : The location of where to store the log file. 
     15- autoExpand : Whether to expand the file path or not. Defaults to true. 
     16- filename : The name of the file, if not defined, then it will use the name of this appender. 
     17                     Do not append an extension to it. We will append a .log to it. 
     18- fileEncoding : The file encoding to use, by default we use UTF-8; 
    1119-----------------------------------------------------------------------> 
    12 <cfcomponent name="SimpleLogger"  
     20<cfcomponent name="FileAppender"  
    1321                         extends="coldbox.system.logging.AbstractAppender"  
    1422                         output="false" 
    15                          hint="This is a simple implementation of a logger that is file based."> 
     23                         hint="This is a simple implementation of an appender that is file based."> 
    1624                          
    1725<!------------------------------------------- CONSTRUCTOR -------------------------------------------> 
    1826         
    1927        <!--- Constructor ---> 
    20         <cffunction name="init" access="public" returntype="SimpleLogger" hint="Constructor" output="false"> 
     28        <cffunction name="init" access="public" returntype="FileAppender" hint="Constructor" output="false"> 
     29                <!--- ************************************************************* ---> 
     30                <cfargument name="name"                 type="string"  required="true" hint="The unique name for this appender."/> 
     31                <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"/> 
     32                <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"/> 
     33                <cfargument name="properties"   type="struct"  required="false" default="#structnew()#" hint="A map of configuration properties for the appender"/> 
     34                <!--- ************************************************************* ---> 
     35                <cfscript> 
     36                        super.init(argumentCollection=arguments); 
     37                         
     38                        // Setup Properties 
     39                        if( NOT propertyExists("filepath") ){ 
     40                                $throw(message="Filepath property not defined",type="FileAppender.PropertyNotFound"); 
     41                        } 
     42                        if( NOT propertyExists("autoExpand") ){ 
     43                                setProperty("autoExpand",true); 
     44                        } 
     45                        if( NOT propertyExists("filename") ){ 
     46                                setProperty("filename",getName()); 
     47                        } 
     48                        if( NOT propertyExists("fileEncoding") ){ 
     49                                setProperty("fileEncoding","UTF-8"); 
     50                        } 
     51                         
     52                        // Setup the log file full path 
     53                        instance.logFullpath = getProperty("filePath"); 
     54                        // Clean ending slash 
     55                        if( right(instance.logFullpath,1) eq "/" OR right(instance.logFullPath,1) eq "\"){ 
     56                                instance.logFullPath = left(instance.logFullpath, len(instance.logFullPath)-1); 
     57                        } 
     58                        instance.logFullPath = instance.logFullpath & "/" & getProperty("filename") & ".log"; 
     59                         
     60                        // Do we expand the path? 
     61                        if( getProperty("autoExpand") ){ 
     62                                instance.logFullPath = expandPath(instance.logFullpath); 
     63                        } 
     64                         
     65                        //lock information 
     66                        instance.lockName = getname() & "logOperation"; 
     67                        instance.lockTimeout = 25; 
     68                         
     69                        return this; 
     70                </cfscript> 
     71        </cffunction> 
     72         
     73        <!--- Get Lock Name ---> 
     74        <cffunction name="getlockname" access="public" returntype="string" output="false" hint="The file Lock name"> 
     75                <cfreturn instance.lockname> 
     76        </cffunction> 
     77        <cffunction name="getlockTimeout" access="public" returntype="numeric" output="false" hint="The lock timeout"> 
     78                <cfreturn instance.lockTimeout> 
     79        </cffunction> 
     80         
     81        <!--- onRegistration ---> 
     82        <cffunction name="onRegistration" output="false" access="public" returntype="void" hint="Runs on registration"> 
     83                <cfscript> 
     84                        // Default Log Directory 
     85                        ensureDefaultLogDirectory(); 
     86                        // Init the log location 
     87                        initLogLocation(); 
     88                </cfscript> 
     89        </cffunction> 
     90         
     91        <!--- Log Message ---> 
     92        <cffunction name="logMessage" access="public" output="false" returntype="void" hint="Write an entry into the appender."> 
    2193                <!--- ************************************************************* ---> 
    2294                <cfargument name="logEvent" type="coldbox.system.logging.LogEvent" required="true" hint="The logging event"/> 
    2395                <!--- ************************************************************* ---> 
    2496                <cfscript> 
    25                         /* Super init it */ 
    26                         super.init(argumentCollection=arguments); 
    27  
     97                        var loge = arguments.logEvent; 
     98                        var timestamp = loge.getTimestamp(); 
     99                        var message = loge.getMessage(); 
     100                        var extra = ""; 
     101                         
     102                        // Does file still exist? 
     103                        if( NOT fileExists(getLogFullpath()) ){ initLogLocation(); } 
     104                         
     105                        // Cleanup main message 
     106                        message = replace(message,'"','""',"all"); 
     107                        message = replace(message,"#chr(13)##chr(10)#",'  ',"all"); 
     108                        message = replace(message,chr(13),'  ',"all"); 
     109                        if( len(loge.getExtraInfoAsString()) ){ 
     110                                message = message & " " & loge.getExtraInfoAsString(); 
     111                        } 
     112                         
     113                        // Setup the real entry 
     114                        append('"#severityToString(logEvent.getSeverity())#","#getname()#","#dateformat(timestamp,"MM/DD/YYYY")#","#timeformat(timestamp,"HH:MM:SS")#","#loge.getCategory()#","#message#"');             
    28115                </cfscript> 
    29116        </cffunction> 
    30117         
     118        <!--- get/set log full path ---> 
     119        <cffunction name="getlogFullpath" access="public" returntype="string" output="false" hint="Get the full log path used."> 
     120                <cfreturn instance.logFullpath> 
     121        </cffunction> 
     122         
     123        <!--- Remove the log File ---> 
     124        <cffunction name="removeLogFile" access="public" hint="Removes the log file" output="false" returntype="void"> 
     125                <cflock name="#instance.lockName#" type="exclusive" timeout="#instance.lockTimeout#" throwontimeout="true"> 
     126                        <cffile action="delete" file="#getLogFullPath()#"> 
     127                </cflock> 
     128        </cffunction> 
    31129 
     130        <!--- Init Log Location ---> 
     131        <cffunction name="initLogLocation" access="public" hint="Initialize the file log location if it does not exist." output="false" returntype="void"> 
     132                <cfset var fileObj = ""> 
     133                 
     134                <!--- Create Log File if It does not exist and initialize it. ---> 
     135                <cfif not fileExists(getLogFullPath())> 
     136                        <!--- Log File Setup ---> 
     137                        <cflock name="#instance.lockName#" type="exclusive" timeout="#instance.lockTimeout#" throwontimeout="true"> 
     138                        <cfscript> 
     139                                // Double Lock 
     140                                if( not fileExists(getLogFullpath()) ){ 
     141                                        // Create empty log file 
     142                                        try{ 
     143                                                fileObj = createObject("java","java.io.File").init(JavaCast("string",getLogFullPath())).createNewFile(); 
     144                                        } 
     145                                        catch(Any e){ 
     146                                                $log("ERROR","Cannot create appender's: #getName()# log file. File #getLogFullPath()#. #e.message# #e.detail#"); 
     147                                                getLogBox().unregister(getname()); 
     148                                        }                                        
     149                                }        
     150                        </cfscript>              
     151                        </cflock> 
     152                        <!--- Log First Entry ---> 
     153                        <cfset append('"Severity","Appender","Date","Time","Category","Message"')> 
     154                <cfelse> 
     155                        <cfscript> 
     156                        //Check if we can write 
     157                        fileObj = createObject("java","java.io.File").init(JavaCast("string",getLogFullPath())); 
     158                        if( NOT fileObj.canWrite() ){ 
     159                                $log("ERROR","Cannot write to file: #getLogFullpath()# by appender #getName()#"); 
     160                                getLogBox().unregister(getname()); 
     161                        } 
     162                        </cfscript> 
     163                </cfif> 
     164        </cffunction> 
     165         
     166<!------------------------------------------- PRIVATE -------------------------------------------> 
    32167 
    33 <!------------------------------------------- PUBLIC -------------------------------------------> 
    34                           
     168         
     169 
     170        <!--- append ---> 
     171        <cffunction name="append" output="false" access="private" returntype="void" hint="Append a message to a file"> 
     172                <cfargument name="message" type="any" required="true" hint="The message to append"/> 
     173                <cflock name="#instance.lockName#" type="exclusive" timeout="#instance.lockTimeout#" throwontimeout="true"> 
     174                        <cffile action="append"  
     175                                        addnewline="true"  
     176                                        file="#getlogFullPath()#"  
     177                                        output="#arguments.message#" 
     178                                        charset="#getProperty("fileEncoding")#">                 
     179                </cflock>                                
     180        </cffunction> 
     181 
     182        <!--- Ensure directory ---> 
     183        <cffunction name="ensureDefaultLogDirectory" access="private" hint="Ensures the log directory." output="false" returntype="void"> 
     184                <cfset var dirPath = getDirectoryFrompath(getLogFullpath())> 
     185                 
     186                <!--- Check if the directory already exists ---> 
     187                <cfif not directoryExists(dirPath)> 
     188                        <cfdirectory action="create" directory="#dirPath#"> 
     189                </cfif> 
     190        </cffunction> 
     191         
    35192 
    36193</cfcomponent> 
  • coldbox/trunk/system/logging/appenders/ScopeAppender.cfc

    r2363 r2365  
    8383                        entry.severity = severityToString(loge.getseverity()); 
    8484                        entry.message = loge.getMessage(); 
    85                         entry.extraInfo = loge.getextraInfo().toString(); 
     85                        entry.extraInfo = loge.getextraInfo(); 
    8686                        entry.category = loge.getCategory(); 
    8787                         
  • coldbox/trunk/system/plugins/Zip.cfc

    r2211 r2365  
    6565                <cfscript> 
    6666                        super.Init(arguments.controller); 
     67                         
    6768                        //Local Plugin Definition 
    6869                        setpluginName("Zip"); 
     
    7273                        setpluginAuthorURL("http://www.coldbox.org"); 
    7374                         
     75                        configure(); 
     76         
     77                        //Return instance 
     78                        return this; 
     79                </cfscript> 
     80        </cffunction> 
     81         
     82        <!--- configure ---> 
     83        <cffunction name="configure" output="false" access="public" returntype="Zip" hint="Configure for operation"> 
     84                <cfscript> 
    7485                        //This plugin's properties 
    7586                        instance.ioFile      = CreateObject("java","java.io.File"); 
     
    91102                        //LM. To fix Overflow. 
    92103                        instance.filename = ""; 
    93          
    94                         //Return instance 
     104                         
    95105                        return this; 
    96106                </cfscript> 
  • coldbox/trunk/testing/cases/logging/appenders/DBAppenderTest.cfc

    r2363 r2365  
    4141                        logdate = "logdate", 
    4242                        appendername = "appendername", 
    43                         messsage = "message" 
     43                        messsage = "message", 
     44                        extrainfo = "extrainfo" 
    4445                }; 
    4546                 
     
    5859                        logdate = "logdate", 
    5960                        appendername = "appendername", 
    60                         message = "message" 
     61                        message = "message", 
     62                        extrainfo = "extrainfo" 
    6163                }; 
    6264