ColdFusion 9.0 Resources |
WritelogDescriptionA function equivalent of the cflog tag, which can be used in <cfscript>. ParametersSame as the <cflog> tag. CategoryFunction syntaxwritelog(text, application, file, log, type) For positional notation, the sequence of arguments is: writelog (text, application, file, log, type) UsageYou can call this function as name=value pair or as positional argument. For positional arguments, the order of the parameters remains the same as the corresponding tag or as mentioned in the preceding Function Syntax section. Example<cfscript> //Example: 1 function TotalInterest(principal, annualRate, months) { var years = 0; var interestRate = 0; var totalInterest = 0; principal = REReplace(trim(principal), "[\$]", "", "ALL"); annualRate = Replace(trim(annualRate), "%", "", "ALL"); if ((principal <= 0) OR (annualRate <= 0) OR (months <= 0)) { Throw(type="InvalidData",message="All values must be greater than 0."); } interestRate = annualRate / 100; years = months / 12; totalInterest = principal * (((1 + interestRate) ^ years) - 1); return DollarFormat(totalInterest); } try { Trace(type="Information", inline="true", text="Calculating interest."); WriteOutput(TotalInterest("$2500.00", "5.5%", "12")); Trace(type="Information", inline="true", text="Interest calculation done."); } catch(InvalidData ex) { //Writting the exception to log file under logs folder of web server. WriteLog(type="Error", file="myapp.log", text="[#ex.type#] #ex.message#"); } </cfscript> |