Changeset 2365
- Timestamp:
- 07/05/09 08:12:37 (4 years ago)
- Location:
- coldbox/trunk
- Files:
-
- 11 added
- 10 modified
-
system/logging/AbstractAppender.cfc (modified) (3 diffs)
-
system/logging/LogBox.cfc (modified) (3 diffs)
-
system/logging/LogEvent.cfc (modified) (2 diffs)
-
system/logging/appenders/AsyncFileAppender.cfc (added)
-
system/logging/appenders/AsyncRollingFileAppender.cfc (added)
-
system/logging/appenders/CFAppender.cfc (modified) (1 diff)
-
system/logging/appenders/ConsoleAppender.cfc (modified) (1 diff)
-
system/logging/appenders/DBAppender.cfc (modified) (6 diffs)
-
system/logging/appenders/FileAppender.cfc (modified) (1 diff)
-
system/logging/appenders/RollingFileAppender.cfc (added)
-
system/logging/appenders/ScopeAppender.cfc (modified) (1 diff)
-
system/logging/util (added)
-
system/logging/util/FileRotator.cfc (added)
-
system/plugins/Zip.cfc (modified) (3 diffs)
-
testing/cases/logging/appenders/AsyncFileAppenderTest.cfc (added)
-
testing/cases/logging/appenders/AsyncRollingFileAppenderTest.cfc (added)
-
testing/cases/logging/appenders/DBAppenderTest.cfc (modified) (2 diffs)
-
testing/cases/logging/appenders/FileAppenderTest.cfc (added)
-
testing/cases/logging/appenders/RollingFileAppenderTest.cfc (added)
-
testing/cases/logging/tmp (added)
-
testing/cases/logging/tmp/MYFILEAPPENDER.6E7E441F-2329-4F77-B3563007AFC8E318.zip (added)
Legend:
- Unmodified
- Added
- Removed
-
coldbox/trunk/system/logging/AbstractAppender.cfc
r2364 r2365 17 17 // The log levels enum as a public property 18 18 this.logLevels = createObject("component","coldbox.system.logging.LogLevels"); 19 // Populated when appender is created, public by default 20 this.logBox = ""; 19 21 20 22 // private instance scope … … 72 74 </cffunction> 73 75 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 74 81 <!--- getHash ---> 75 82 <cffunction name="getHash" output="false" access="public" returntype="string" hint="Get this appender's unique ID"> … … 179 186 180 187 <!--- $log ---> 181 <cffunction name="$log" output="false" access="p rivate" 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"> 182 189 <cfargument name="severity" type="string" required="true" default="INFO" hint="The severity to use."/> 183 190 <cfargument name="message" type="string" required="true" default="" hint="The message to log"/> -
coldbox/trunk/system/logging/LogBox.cfc
r2364 r2365 59 59 60 60 <!--- 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"> 62 62 <cfargument name="logBoxConfig" type="coldbox.system.logging.config.LogBoxConfig" required="true" hint="The LogBoxConfig object to use to configure this instance of LogBox"/> 63 63 <cfscript> … … 167 167 <cfscript> 168 168 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 } 169 173 // Store Logger 170 174 getAppenders().put(name, arguments.appender) … … 192 196 <cfscript> 193 197 // 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); 196 203 // Register it 197 204 register(appender); -
coldbox/trunk/system/logging/LogEvent.cfc
r2363 r2365 30 30 var key = ""; 31 31 for(key in arguments){ 32 if( isSimpleValue(arguments[key]) ){ 33 arguments[key] = trim(arguments[key]); 34 } 32 35 instance[key] = arguments[key]; 33 36 } … … 36 39 </cffunction> 37 40 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> 38 49 <cffunction name="getextraInfo" access="public" returntype="any" output="false"> 39 50 <cfreturn instance.extraInfo> -
coldbox/trunk/system/logging/appenders/CFAppender.cfc
r2363 r2365 58 58 <cflog file="#getName()#" 59 59 type="#severityToString(loge.getSeverity())#" 60 text="#loge.getCategory()# #loge.getMessage()# ">60 text="#loge.getCategory()# #loge.getMessage()# ExtraInfo: #loge.getextraInfoAsString()#"> 61 61 <cfelse> 62 62 <cflog log="Application" 63 63 type="#severityToString(loge.getSeverity())#" 64 text="#loge.getCategory()# #loge.getMessage()# ">64 text="#loge.getCategory()# #loge.getMessage()# ExtraInfo: #loge.getextraInfoAsString()#"> 65 65 </cfif> 66 66 -
coldbox/trunk/system/logging/appenders/ConsoleAppender.cfc
r2363 r2365 45 45 var loge = arguments.logEvent; 46 46 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 54 47 // 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()#"); 56 49 </cfscript> 57 50 </cffunction> -
coldbox/trunk/system/logging/appenders/DBAppender.cfc
r2363 r2365 26 26 - appendername : string 27 27 - message : string 28 - extrainfo : string 28 29 29 30 If you are building a mapper, the map must have the above keys in it. … … 65 66 66 67 // columns 67 instance.columns = "id,severity,category,logdate,appendername,message ";68 instance.columns = "id,severity,category,logdate,appendername,message,extrainfo"; 68 69 69 70 return this; … … 92 93 var cols = ""; 93 94 var loge = arguments.logEvent; 95 var message = loge.getMessage(); 94 96 95 97 // Check Category Sent? … … 101 103 if( propertyExists('columnMap') ){ 102 104 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#"; 104 106 } 105 107 else{ … … 116 118 <cfqueryparam cfsqltype="cf_sql_timestamp" value="#loge.getTimestamp()#">, 117 119 <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()#"> 119 122 ) 120 123 </cfquery> … … 164 167 #listgetAt(cols,5)# VARCHAR(100) NOT NULL, 165 168 #listgetAt(cols,6)# TEXT, 169 #listgetAt(cols,7)# TEXT, 166 170 PRIMARY KEY (id) 167 171 ) -
coldbox/trunk/system/logging/appenders/FileAppender.cfc
r2363 r2365 8 8 Date : 3/13/2009 9 9 Description : 10 Simple File Logger 10 Simple File Appender 11 12 Properties: 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; 11 19 -----------------------------------------------------------------------> 12 <cfcomponent name=" SimpleLogger"20 <cfcomponent name="FileAppender" 13 21 extends="coldbox.system.logging.AbstractAppender" 14 22 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."> 16 24 17 25 <!------------------------------------------- CONSTRUCTOR -------------------------------------------> 18 26 19 27 <!--- 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."> 21 93 <!--- ************************************************************* ---> 22 94 <cfargument name="logEvent" type="coldbox.system.logging.LogEvent" required="true" hint="The logging event"/> 23 95 <!--- ************************************************************* ---> 24 96 <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#"'); 28 115 </cfscript> 29 116 </cffunction> 30 117 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> 31 129 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 -------------------------------------------> 32 167 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 35 192 36 193 </cfcomponent> -
coldbox/trunk/system/logging/appenders/ScopeAppender.cfc
r2363 r2365 83 83 entry.severity = severityToString(loge.getseverity()); 84 84 entry.message = loge.getMessage(); 85 entry.extraInfo = loge.getextraInfo() .toString();85 entry.extraInfo = loge.getextraInfo(); 86 86 entry.category = loge.getCategory(); 87 87 -
coldbox/trunk/system/plugins/Zip.cfc
r2211 r2365 65 65 <cfscript> 66 66 super.Init(arguments.controller); 67 67 68 //Local Plugin Definition 68 69 setpluginName("Zip"); … … 72 73 setpluginAuthorURL("http://www.coldbox.org"); 73 74 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> 74 85 //This plugin's properties 75 86 instance.ioFile = CreateObject("java","java.io.File"); … … 91 102 //LM. To fix Overflow. 92 103 instance.filename = ""; 93 94 //Return instance 104 95 105 return this; 96 106 </cfscript> -
coldbox/trunk/testing/cases/logging/appenders/DBAppenderTest.cfc
r2363 r2365 41 41 logdate = "logdate", 42 42 appendername = "appendername", 43 messsage = "message" 43 messsage = "message", 44 extrainfo = "extrainfo" 44 45 }; 45 46 … … 58 59 logdate = "logdate", 59 60 appendername = "appendername", 60 message = "message" 61 message = "message", 62 extrainfo = "extrainfo" 61 63 }; 62 64
