当无法访问CFIDE时查看执行堆栈跟踪

时间:2014-11-14 06:42:06

标签: coldfusion stack-trace

我目前正在为客户调试ColdFusion系统......

问题是,因为如果我要触摸CF管理员模块,他们对任何系统被搞砸都非常敏感,他们已经把它限制在了极限......而且他们已经把它限制了甚至对在特定的IP上打开它非常犹豫,因为他们不希望其他用户意外地看到堆栈跟踪......

所以我想知道......是否有一个CF标签或函数我可以在代码的各个部分实现,以触发堆栈跟踪代替此访问?

1 个答案:

答案 0 :(得分:3)

如果您在发生错误时尝试获取堆栈跟踪,那么您应该可以使用Application.cfc上的onError事件来执行此操作。从那里,您可以将异常记录到文件中,以电子邮件形式发送或挂钩到HothBugLogHG甚至第三方服务,例如AirbrakeSentry

// in Application.cfc

function onError(any exception, string event) {
   // do something here like send an email / log to file etc
}

如果你没有任何错误并且想要获得堆栈跟踪,那么这就更难了,但你可以伪造一个错误,所以这样的事情可能会有效:

<cfset greeting = "Hello World!">

<cftry>
  <!--- deliberately throw an error --->
  <cfthrow type="ForceException" message="Thrown Exception">
  <cfcatch>
    <!--- 
    the cfcatch key has a stacktrace key so you can log/email it
    to get the information and the rest of the code will execute
    --->
    <cflog file="somefile" text="#SerializeJSON(cfcatch)#">

  </cfcatch>
</cftry>

<!--- this code will still run --->
<cfoutput>
#greeting#
</cfoutput>