Creating Custom Appenders
In order to create your own appenders, you will have to create a cfc that extends logbox.system.logging.AbstractAppender and implement the following methods:
init()
Your constructor. Make sure to call super.init( argumentCollection=arguments );
logMessage()
The method that is called when a message is received.
onRegistration()
An interceptor that fires when the appender gets created and initialized. It can be used for preparing the appender for operation.
onUnRegistration()
An interceptor that fires when the appender is removed from a logger.
init()
The signature of the init method is the following:
function init(
required name,
struct properties = {},
layout = "",
levelMin = 0,
levelMax = 4
){
super.init( argumentCollection = arguments )
// your setup here
return this
}function init(
required name,
struct properties = {},
layout = "",
numeric levelMin = 0,
numeric levelMax = 4
){
super.init( argumentCollection = arguments );
// your setup here
return this;
}As you can see each appender receives a name, a structure of properties, an optional layout class, and optional levelMin and levelMax severity levels. The properties and layout are both optional, but you must call super.init( argumentCollection = arguments ) to have full appender operation. Here is a FileAppender-style example:
logMessage()
The signature of the logMessage method is the following:
As you can see it is a very simple method that receives a LogBox logging event object. This object keeps track of the following properties with its appropriate getters and setters:
timestampcategorymessageseverityextraInfo
It also exposes a helper method, getExtraInfoAsString(), which returns the extraInfo value already serialized to a string (following the same $toString()/exception/JSON/XML rules described in ExtraInfo Serialization), so appenders and layouts don't have to duplicate that serialization logic themselves.
You can then use this logging event object to log to whatever destination you want. Here is a snippet from a scope appender:
onRegistration() & onUnregistration()
Both the onRegistration and onUnregistration methods are void methods with no arguments. They are great for starting or stopping resources. Here is a sample from a socket appender:
Last updated
Was this helpful?