Ross
Ross

Reputation: 362

Emailing Error Report from Coldfusion Administrator

We run an app that doesn't have great email notifications for errors but they do end up in the application.log in Coldfusion. Does Coldfusion have a way to send an email when this file changes and it's an error (not just a session rotation or other info level log entry)?

Upvotes: 0

Views: 56

Answers (1)

gordon
gordon

Reputation: 1182

This is not the solution but it might get you headed in the right direction. I haven't worked on CF watching the error log files and emailing - you'd want to set up a scheduled task to check it. But I will say that server error of type 500 were a thorn in my side because IIS didn't want to want to pass the error to CF to handle. Here's the page I am using to open the error log, get to the bottom and work backwards to display the 500-type errors. It's not terribly robust, but it does let me review the errors I used to not get notified about:

<cffile action="read" variable="exceptionLog" file="C:\ColdFusion10\cfusion\logs\exception.log">
<cfparam name="form.goBack" default="0">
<cfparam name="form.showHowMany" default="10">
<cfif structKeyExists(url,"goback") and  structKeyExists(url,"showHowMany")>
    <cfset form.goBack=url.goback>
    <cfset form.showHowMany=url.showHowMany>
</cfif>
<cfoutput>
<cfset bodyAttr=' style="font-family:arial;font-size:10pt;font-weight:normal;"'>
<cfinclude template="../html_header.cfm">
<form name="f" id="f" action="cfexception.cfm" method="post">
Go back<input name="goBack" id="goBack" class="intgr" size="4" value="#form.goBack#"> &nbsp;
Show how many<input name="showHowMany" id="showHowMany" class="intgr" size="4" value="#form.showHowMany#"> &nbsp;
<input type="button" value="Go" id="btnSbmt">
</form>
<script type="text/javascript">
$(document).ready(function(){
    $("input.intgr").keyup(function (e) { // Filter non-digits from input value.
        if (/\D/g.test($(this).val())) $(this).val($(this).val().replace(/\D/g, ''));
    });
    $("##btnSbmt").click(function(){
        if($("##goBack").val()=="" || $("##goBack").val()=="") alert("Both input fields (Go back and Show how many) are required.");
        else $("##f").submit();
    })
});
</script>
</cfoutput>
<cfset raText=listToArray(exceptionLog,chr(10))>
<cfset raErr=[]>
<cfset goneBack=0>
<cfset showHowMany=1>
<cfoutput>
<cfloop from="#arrayLen(raText)#" to="1" step="-1" index="idxErr">
    <cfif findNoCase("error",raText[idxErr])>
        <cfif goneBack lte form.goBack><cfset goneBack=goneBack+1><!--- display nothing, incr counter --->
        <cfelse><!--- now that we've gone far enough back, start displaying --->
            <strong>#showHowMany#</strong>#raText[idxErr]# <cfif idxErr neq (arrayLen(raText)-1)><br />#raText[idxErr+1]#</cfif><br /><br />
            <cfif int(showHowMany) lte int(form.showHowMany)-1><cfset showHowMany=showHowMany+1>
            <cfelse><cfbreak><!--- incr counter up to number user entered (or default) and then bail out --->
            </cfif>
        </cfif>
    </cfif>
</cfloop>
</body>
</html>
</cfoutput>

Upvotes: 1

Related Questions