[coldbox:4223] LogBox: Return data from an appender

Ok, I’ve got an interesting brainstorm about LogBox. We just upgraded our app at work to M5 to see how everything works out. Of course, that now means that we’re using the new and improved Logging engine! It also seems like a good time to get around to making an enhancement we’ve had on our books for a while. Right how when CB handles an error in our app, the standard Big Report E-mail gets sent out, and we log the error to a log file. With the new Logger functionality, we’ll implement a DBAppender to start keeping our errors in a database table to better keep track of them.

As part of this change we are going to start generating an error reference number on the generic “call customer service” page. That way when someone calls in or E-mails a screen shot we can match the error reference number they give us with the specific error detail in our logs. (A lot of our site is public accessed so there is no logged in user to tie the error to)

Ok, so no problem, right? I’ll just write a custom database appender that inserts the error report, and grabs the last error number that was created. But the problem is how can I get that info back to the app. Right now appenders are sort of a black hole. For all my app knows, the appender could have run asynchronously or not at all. I could make the service or handler that logs the error generate the number ahead of time, but if it is a simple identity column, I won’t know the next ID until I insert it. Either that or I’ll have to single-thread the entire process to make sure only one error gets logged at a time. (yuck!)Alternatively, I could place the reference number in the request scope somewhere and pull it out later (assuming the appender is synchronous). but that just seems to poo all over the face of encapsulation.

Does anyone have any bright ideas or thoughts on this? If your only thought is that I’m pushing LogBox too far, then feel free to tell me that too. :slight_smile:



Definitely, interesting ideas Brad, it seems you want the logging engine to now communicate with your application, and the only way to do this is to bridge that appender with the running application.

Therefore, if you use logbox within a coldbox application, then you get this functionality out of the box. Each appender gets a reference to the running coldbox application just in case, well, somebody get’s funky and wants to talk back to the application. Therefore, in your appender you can use the “getColdbox()” method to retrieve the running application and then use it.

You can get the private request context for example:

event = getColdBox().getRequestService().getContext();
prc = getColdBox().getRequestService().getContext().getCollection(private=true);
rc = getColdBox().getRequestService().getContext().getCollection();

Would this help. You can also, announce an interception if you like and broadcast it.

Luis F. Majano
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Ooh, good one Luis. Since I had been playing at home with LogBox in a standalone project, I had forgotten about the link to ColdBox that gets set in there. The request collection would be the perfect place to tuck that data into.

As far as someone using LogBox outside of ColdBox who wanted this functionality, I guess they could inject a dummy reference in as “ColdBox” for the appender to fiddle with.