[ColdBox SEEK 4.1.0+00002 Gideon] ColdboxTracerAppender

Hi, I’m trying to configure the coldboxTracerAppender adding it to a logger category in my configuration so when I inject it into a handler I can write for example:

property name="log" inject="logbox:logger:Tracer"

This is my configuration struct:

`
//LogBox DSL
logBox = {
// Define Appenders
appenders = {
consoleLog = { class=“coldbox.system.logging.appenders.ConsoleAppender” },
fileLog = {
class=‘coldbox.system.logging.appenders.RollingFileAppender’,
properties={
filePath = ‘/logs’,
fileName = ‘bitacora’,
autoExpand = true,
fileMaxSize = 2000,
fileMaxArchives = 3
}
},
tracer = {
class=‘modules.cbdebugger.includes.appenders.ColdBoxTracerAppender’,
properties={}
}
},
// Root Logger
root = { levelmax=“INFO”, appenders=“consoleLog” },
categories = {
Seguridad = { levelmin=“ERROR”, levelmax=“INFO”, appenders=“fileLog” },
Tracer = { levelmin=“DEBUG”, appenders=“tracer” }
},

// Implicit Level Categories
//info = [ “coldbox.system” ],

OFF = [“coldbox.system”]
};
`

It has an appender named “tracer” which points to modules.cbdebugger.includes.appenders.ColdBoxTracerAppender
and a logger named “Tracer” which includes the tracer appender, with this configuration if I do this

log.debug('My message', myStruct );

Coldbox should send the message to the Coldbox Tracer and see it in the debugger panel but instead I get this error

Element BINDER is undefined in a Java object of type class [Ljava.lang.String;.

The error occurred in /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/ioc/Injector.cfc: line 222
Called from /Applications/ColdFusion9/wwwroot/sofom4/modules/cbdebugger/includes/appenders/ColdBoxTracerAppender.cfc: line 34
Called from /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/logging/LogBox.cfc: line 211
Called from /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/logging/LogBox.cfc: line 86
Called from /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/web/services/LoaderService.cfc: line 38
Called from /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/Bootstrap.cfc: line 71
Called from /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/Bootstrap.cfc: line 107
Called from /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/Bootstrap.cfc: line 350
Called from /Applications/ColdFusion9/wwwroot/sofom4/Application.cfc: line 88
220 :
221 : // Check if Mapping Exists?
222 : if( NOT instance.binder.mappingExists(arguments.name) ){
223 : // No Mapping exists, let’s try to locate it first. We are now dealing with request by conventions
224 : instancePath = locateInstance(arguments.name);

I see that line 34 of the ColdBoxTracerAppender gets the debuggerService

<cfset variables.debuggerService = getColdBox().getWireBox().getInstance( "debuggerService@cbdebugger" )>

But it seems like wirebox doesn’t find the mapping, so I removed the appender from the logbox config structure and the app ran normally.
However I know that wirebox can find that mapping because I can inject the service in my handler

property name="debuggerService" inject="debuggerService@cbdebugger";

or like this

debuggerService = wirebox.getInstance(‘debuggerService@cbdebugger’);

And add some message to the tracer

debuggerService.pushTracer('This is my message', myStruct );

To finally achieve my goal, but what am I doing wrong with the appender?

Thanks in advance,

Angel Chrystian

This is another chicken and egg problem. The tracer appender can’t be specified in your LogBox config any longer since the modules haven’t been loaded yet when the ColdBox config is processed. And in your specific case, WireBox hasn’t been initialized yet either. Also note, the path to the appender should start with cbdebugger since that is the root mapping for the module.

The only way I’ve found to get the tracer appender to work is to add it after the application has loaded in an interceptor like so:

https://github.com/ColdBox/coldbox-samples/blob/master/applications/helloworld/interceptors/LogBox.cfc

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Ok, thank you very much.
I’m having fun learning with this framework.

Hi Brad I used the code for the interceptor

<i>component {
	
	// This appender is part of a module, so we need to register it after the modules have been loaded.
	function afterConfigurationLoad() {
		var logBox = controller.getLogBox();
		logBox.registerAppender( 'tracer', 'cbdebugger.includes.appenders.ColdBoxTracerAppender' );
		var appenders = logBox.getAppendersMap( 'tracer' );
		
		// Register the appender with the root loggger, and turn the logger on.
		var root = logBox.getRootLogger();
		root.addAppender( appenders['tracer'] );
		root.setLevelMax( 4 );
		root.setLevelMin( 0 );
	}
	
}</i>

But it failed because getAppendersMap function has private access, so I got and error
The method getAppendersMap was not found in component /Applications/ColdFusion9/wwwroot/sofom4/coldbox/system/logging/LogBox.cfc.

I changed the access of that function to public and it worked, so I guess that should be changed in LogBox.cfc

Hmm, so it is. Well, I’m not entirely sure how I had gotten that code to work. Must have made the method public and forgotten to put in a ticket for it. I’m afraid there might not be a clean way to get that appender working without reconfiguring logbox after the framework has loaded (or making that method public)

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Another question I have is how do I configure the appender to only respond to debug level messages?.

root.setLevelMin( 3 ); root.setLevelMax( 4 );

With that when I do a log.debug() message it will be traced to the debug panel and when I do a log.info() it will do trace the message too.

I tried with root.setLevelMax( 4 ) only, but got an error.
Then I tried with root.setLevelMin( 4 ) only, bu got an error too, it seems both levels of the range are required.

Finally y tried both levels to 4

root.setLevelMin( 4 ); root.setLevelMax( 4 );

Got an error that levelMin is greater than levelMax.

Thanks for your help.

Angel.

The logger levels are in the docs, but you can also see them here:

https://github.com/ColdBox/coldbox-platform/blob/master/system/logging/LogLevels.cfc

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yes I read that in the doc, but my point is that it only allows me to configure a range, I know level 4 is debug so my understanding is to put from 4 to 4 so no other level is involved only debug.
I want to only trace messages to the coldbox panel only when I do log.debug()

Thanks