2

我们在同一台服务器上运行了多个应用程序,默认日志文件最终变得一团糟,尤其是管理面板不提供搜索功能的异常日志。

是否有可能让 Coldfusion 将与给定应用程序(由 Application.cfm 或 .cfc 定义)相关的内容记录到单独的日志中?

如果没有,这个问题的任何替代解决方案?

4

2 回答 2

1

我推荐 application.cfc onError方法在单独的日志文件中记录未捕获的错误。此文档也可能会有所帮助:处理 Application.cfc 中的错误

于 2014-07-15T14:25:56.460 回答
0

onError这是使用 application.cfc 中的函数将错误记录到特定于应用程序的日志文件的基本示例。

<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>

您需要指定要包含在日志条目中的异常详细信息的哪些部分,请记住,异常结构的键将根据抛出的错误类型而有所不同。因此,最好在将它们添加到日志文本之前检查它们的存在。

ColdFusion MX7 的官方 onError 文档(因为您的问题已标记为该版本 - 这也是我在示例中使用标签而不是 cfscript 以确保安全的原因)。

于 2014-07-21T13:24:44.017 回答