Skip to content

Instantly share code, notes, and snippets.

@sigmaprojects
Created November 22, 2013 18:13
Show Gist options
  • Save sigmaprojects/7604402 to your computer and use it in GitHub Desktop.
Save sigmaprojects/7604402 to your computer and use it in GitHub Desktop.
A Logger Appender for BugLogHQ
component extends="coldbox.system.logging.AbstractAppender" output="false"
hint="This is a simple implementation of a appender that is BugLogHQ Plugin based" {
public BugLogHQAppender function init(
Required name,
properties = {},
layout = "",
levelMin = 0,
levelMax = 4
) {
// Init supertype
super.init(argumentCollection=arguments);
if( NOT propertyExists('defaultCategory') ){
setProperty("defaultCategory",arguments.name);
}
variables.Controller = arguments.properties.Controller;
return this;
}
public void function onRegistration() {
}
public void function logMessage(Required Any LogEvent) {
var loge = arguments.logEvent;
var category = getProperty("defaultCategory");
if( NOT loge.getCategory() eq "" ){
category = loge.getCategory();
}
var ExceptionBeanProperties = {
errorStruct = {
message = loge.getMessage(),
type = category
},
extramessage = loge.getMessage(),
extraInfo = loge.getExtraInfo(),
errorType = category
};
if( isStruct(loge.getExtraInfo()) && structKeyExists(loge.getExtraInfo(),'TagContext') && isArray(loge.getExtraInfo().TagContext) ) {
ExceptionBeanProperties.errorStruct['TagContext'] = loge.getExtraInfo().TagContext;
if( structKeyExists(ExceptionBeanProperties.extraInfo,'TagContext') ) {
structDelete(ExceptionBeanProperties.extraInfo,'TagContext',false);
}
}
var exceptionBean = createObject('component','coldbox.system.web.context.ExceptionBean').init( argumentCollection=ExceptionBeanProperties );
var oEvent = variables.Controller.getRequestService().getContext();
var BugLogHQPlugin = variables.Controller.getPlugin(plugin="BugLog",customPlugin=true);
BugLogHQPlugin.logError(
oExceptionBean = exceptionBean,
sSseverityCode = severityToString(loge.getseverity()),
Event = oEvent
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment