Skip to content

Instantly share code, notes, and snippets.

@jeaguilar
Created February 8, 2017 16:45
Show Gist options
  • Save jeaguilar/fcba7c6272e110ab7d278f2bd462b288 to your computer and use it in GitHub Desktop.
Save jeaguilar/fcba7c6272e110ab7d278f2bd462b288 to your computer and use it in GitHub Desktop.
BugLogHQ plugin for Mura. Modifications to plugins/BugLogHQ/plugin/eventHandler.cfc
<cfcomponent extends="mura.plugin.pluginGenericEventHandler" output="false">
<cffunction name="onApplicationLoad" returnType="any" access="public" output="false">
<cfif structKeyExists(application,'bugLogService')>
<cfset structDelete(application,'bugLogService') />
</cfif>
<cfset variables.pluginConfig.addEventHandler(this) />
<cfif len(variables.pluginConfig.getSetting('insertJSFiles')) && variables.pluginConfig.getSetting('insertJSFiles')>
<cfif len(variables.pluginConfig.getSetting('bugLogListener'))>
<cfsavecontent variable="local.bugLogReport"><cfoutput>
BugLog.listener='#jsStringFormat(variables.pluginConfig.getSetting('bugLogListener'))#';
BugLog.hostName='#jsStringFormat(variables.pluginConfig.getSetting('hostname'))#';
BugLog.appName='#jsStringFormat(variables.pluginConfig.getSetting('appName'))#';
BugLog.apiKey='#jsStringFormat(variables.pluginConfig.getSetting('apikey'))#';
window.onerror = function(message, file, line) {
BugLog.notifyService({
message: message,
extraInfo: 'Error occurred in: ' + file + ':' + line,
severity:"ERROR"
});
return true;
}
</cfoutput></cfsavecontent>
<cffile action="write" file="#getDirectoryFromPath(getCurrentTemplatePath())#../bugLogReport.js" output="#trim(local.bugLogReport)#" />
</cfif>
</cfif>
<cfif NOT structKeyExists(application,'bugLogService')>
<cfset application.bugLogService = createObject('component','bugLogService').init(
bugLogListener=variables.pluginConfig.getSetting('bugLogListener'),
bugEmailRecipients=variables.pluginConfig.getSetting('bugEmailRecipients'),
bugEmailSender=variables.pluginConfig.getSetting('bugEmailSender'),
hostname=variables.pluginConfig.getSetting('hostname'),
apikey=variables.pluginConfig.getSetting('apikey'),
appName=variables.pluginConfig.getSetting('appName'),
maxDumpDepth=variables.pluginConfig.getSetting('maxDumpDepth'),
writeToCFLog=variables.pluginConfig.getSetting('writeToCFLog')
) />
</cfif>
</cffunction>
<cffunction name="onRenderEnd" returnType="any" access="public" output="false">
<cfif fileExists('#getDirectoryFromPath(getCurrentTemplatePath())#../bugLogReport.js')>
<cfset local.response = arguments.$.event('__MuraResponse__') />
<cfset local.response = replaceNoCase(local.response,'<head>','<head>#chr(10)#<script src="#arguments.$.globalConfig('context')#/plugins/#variables.pluginConfig.getDirectory()#/bugLogClient.js"></script>#chr(10)#<script src="#arguments.$.globalConfig('context')#/plugins/#variables.pluginConfig.getDirectory()#/bugLogReport.js"></script>') />
<cfset arguments.$.event('__MuraResponse__',local.response) />
</cfif>
</cffunction>
<cffunction name="onGlobalError" returnType="any" access="public" output="false">
<cftry>
<cfif NOT structKeyExists(application,'bugLogService')>
<cfset application.bugLogService = createObject('component','bugLogService').init(
bugLogListener=variables.pluginConfig.getSetting('bugLogListener'),
bugEmailRecipients=variables.pluginConfig.getSetting('bugEmailRecipients'),
bugEmailSender=variables.pluginConfig.getSetting('bugEmailSender'),
hostname=variables.pluginConfig.getSetting('hostname'),
apikey=variables.pluginConfig.getSetting('apikey'),
appName=variables.pluginConfig.getSetting('appName'),
maxDumpDepth=variables.pluginConfig.getSetting('maxDumpDepth'),
writeToCFLog=variables.pluginConfig.getSetting('writeToCFLog')
) />
</cfif>
<cfif len(variables.pluginConfig.getSetting('bugLogListener'))>
<cfif isDefined('arguments.$.event')>
<cfset local.args = structNew() />
<cfset local.args.message = '' />
<cfset local.args.exception = arguments.$.event('exception') />
<cfset local.args.extraInfo = structNew() />
<cfif isStruct(local.args.exception)>
<cfif structKeyExists(local.args.exception,'message')>
<cfset local.args.message = local.args.exception.message />
<cfelseif structKeyExists(local.args.exception,'detail')>
<cfset local.args.message = local.args.exception.detail />
</cfif>
<cfif yesNoFormat(variables.pluginConfig.getSetting('reportCgiScope')) AND isDefined('cgi')>
<cfset local.args.extraInfo.cgi = cgi />
</cfif>
<cfif yesNoFormat(variables.pluginConfig.getSetting('reportSessionScope')) AND isDefined('session')>
<cfset local.args.extraInfo.session = session />
</cfif>
<cfthread name="notifyService#RandRange(10000,99999)#" threadArgs="#local.args#">
<cfset application.bugLogService.notifyService(argumentCollection=threadArgs) />
</cfthread>
</cfif>
</cfif>
</cfif>
<cfcatch type="any">
<cfif NOT yesNoFormat(variables.pluginConfig.getSetting('failSilently'))>
<cfdump var="#cfcatch#" abort="true" />
</cfif>
</cfcatch>
</cftry>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment