// Application.cfc
component {
this.log.listener=function(caller, args){
// args being the args or attributes from either writeLog() or <cflog>
// then you could plug in something like https://github.com/GiancarloGomez/sentry-cfml
application.sentry.captureMessage(
message : args.text,
level : args.type,
useThread : true,
userInfo : {
id : 100,
email : "john.doe@test.com",
type : "administrator",
username : "john",
ip_address : cgi.remote_addr
}
);
// if args is returned false, no further logging, thus only using sentry for application logs
return false;
// otherwise
return args; // these values could also be modified in the listener before being logged normally
}
}
The advantage of that syntax is that they support multiple listeners
component {
this.log.listener={
before = function(caller, args){
// args being the args or attributes from either writeLog() or <cflog>
// then you could plug in something like https://github.com/GiancarloGomez/sentry-cfml
application.sentry.captureMessage(
message : args.text,
level : args.type,
useThread : true,
userInfo : {
id : 100,
email : "john.doe@test.com",
type : "administrator",
username : "john",
ip_address : cgi.remote_addr
}
);
// if args is returned false, no further logging, thus only using sentry for application logs
return false;
// otherwise
return args; // these values could also be modified in the listener before being logged normally
},
after = function(caller, args){},
error = function(caller, args, exception){
// do some recovery fallback magic when logging fails
// or when writeLog(text=""); explodes due to "" being ignored
}
};
}
I don’t like the fact that those listeners break precedent either It doesn’t make a great deal of sense to register more than one listener from the same Application.cfc file. However, i don’t think the overall ability to register more than one listener should require any particular syntax in the Application.cfc.