2

We have multiple applications running on the same server and default log files end up being a mess of everything, especially the Exception log for which the admin panel does not offer search capacities.

Is it at all possible to have Coldfusion log things pertaining to a given application (as defined by Application.cfm or .cfc) to a separate log?

If not, any alternative solutions to this issue?

leokhorn
  • 505
  • 1
  • 4
  • 11
  • Another alternative is to look for ways to read your exception log programmatically. We have a page that displays errors from the past X days. We deduce the application from the file path. – Dan Bracuk Jul 15 '14 at 12:14

2 Answers2

1

I'd recommend application.cfc onError method to log uncaught errors in separate log file. Also this doc could be helpful: Handling errors in Application.cfc

0

Here's a basic example of using the onError function in application.cfc to log errors to an application-specific log file.

<cfcomponent output="false">

    <cfset this.name    =   "myApp">

    <cffunction name="onError">
        <cfargument name="exception" required="true">
        <cfargument name="eventName" type="string" required="true">
        <cfset var myAppName    =   this.name>
        <cfset var details  =   "">
        <!--- You need to specify and check for the exception details you want to include in your log text --->
        <cfif IsDefined( "exception.type" )>
            <cfset details = "Type: #exception.type#. ">
        </cfif>
        <cfif IsDefined( "exception.message" )>
            <cfset details = details & "Details: #exception.message#">
        </cfif>
        <cflog type="error" file="#myAppName#" text="#details#">
        <!--- Specify how you want the error to be handled once it's been logged --->
        <cfdump var="#exception#">
    </cffunction>

</cfcomponent>

You need to specify which parts of the exception details you want to include in your log entry, bearing in mind that the keys of the exception struct will vary according to the type of error thrown. It's therefore best to check for their existence before adding them to the log text.

Official onError docs for ColdFusion MX7 (since your question's tagged with that version - which is also why I've used tags rather than cfscript in my example to be on the safe side).

CfSimplicity
  • 2,338
  • 15
  • 17