Logging Appender's use witch one

I have enabled programtically a few appenders, now the problem is how to I enable each one by name.

Every time I use getLogger(“myAppender”); It loads the appender component as the one to be logged as the name, what that means is the logs don’t show the (this) component and instead uses the appender class in the logs.

Now the problem is that I want send an email using the appender, only at specific times and I want the component that the log is raised to appear in the logs and not the new log appender. I can’t see a way in the docs or the wiki or anywhere, where someone actually switches between the appenders.

Any clues?

So does no one know how to do this?

Luis, the Wiki and docs don’t give any examples on this via code, and it doesn’t work. So if I am doing something wrong I need to find a solution to how to do this.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

You want an appender and not a logger is that right?

If so, you can do this via getting a reference to a root logger: logbox.getRootLogger().getAppender( name )

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

Yes but it is not being registered Luis, so how do I get the Appender if it is not registered to be used.

Now I hard coded the same appender in the ColdBox settings and it works the way I sort of need it too, except that the email Appender is being called for every log event and not the category name I give it.

But like I said if I want to do this by code, the error message is no such Appender, unless I do the hack and modify the registerAppender() from private to public, except the email is never sent and from what I can tell from further logging is that the appender is not in the list to cycle through.

So it boils back to how do I do this via code, there are no examples, and no docs on how to do this correctly.

That last statement is very important, all the Wiki says is that you can with no real world example.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

signature0.jpg

Ok, is the gist of it that you need to retrieve an appender by name?

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

signature0.jpg

Luis, How can I get the Appender by Name if it is not being registered?

But what I want to do is this.

  1. Dynamically add an Appender
  2. Use the Appender this newly added Appender to then log with, and also be able to use the root logger with normal logs
  3. Anything outside of the module still uses the root logger
  4. Be able to remove the Appender

The problem is I am not getting past Item #1, so when I am able to get past that then I can think about moving onto the next steps.

Steps 2 and 3 above, is something I would like to be able to switch appenders that should be used. In other words I have the following code.

log.info(“test from root logger”);
emailLog.info(“test from email logger”);

However as I can’t get past step 1, then I need to understand what is wrong an why it is not being registered.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

signature0.jpg

signature0.jpg

Andrew,

Adding appenders dynamically can only happen at the Logger level not at the LogBox level. But it requires that you have a logger to work with.

Where you trying directly to LogBox?

If so, that capability does not exist or well, not exposed. That could be an improvement ticket where you can allow to:

addAppender( appender )
removeAppender( name )
getAppender( name )

All in LogBox instead of an actual logger. Does that make sense

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

signature0.jpg

signature0.jpg

Luis,

Eventually I got down to the LogBox level, yes as I exposed the registerAppender publicly and still couldn’t get it to work. Which I moved to after trying it at the logger level.

Problem was with no guidance on examples I was pretty much in the dark, and guessed most of it.

Do you have an example where it works at the logger level?

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

signature0.jpg

signature0.jpg

signature0.jpg

Hi Andrew,

If you want that capabilities I have no issues with adding that to LogBox but you need to add some enhancement tickets for it.

https://ortussolutions.atlassian.net/browse/LOGBOX

As for the dynamic stuff on a Logger, you can see its API:
http://www.coldbox.org/documents/api/LogBoxDocs-1.6.1/logbox/system/logging/Logger.html

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

signature0.jpg

signature0.jpg

signature0.jpg

Cheers Luis,

Before I raise an E/R I wanted to explore it all first, as for the API I have gone through the API, like I stated I tried the logger first but was never able to get the addApender() to work. All I kept getting was getName() is undefined.

So when I went looking for examples, there is not one, no big deal, its just that how are we supposed to know what newAppender is, or what makes this up?

There is nothing in the Docs / Wiki to provide any further clues, and why I am now posting in here.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

signature0.jpg

signature0.jpg

signature0.jpg

signature0.jpg

Hi Andrew,

How did you write the appender? Did you inherit from our AbstractAppender class?

ALso, this is great because this means we need to improve the docs with your situation.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

signature0.jpg

signature0.jpg

signature0.jpg

signature0.jpg

Luis,

No the appender is, if you go back and look, the ColdBox EmailAppender. All I am trying to do is when the module is loaded it creates an appender for use, and when the module is removed then I want to remove the appender.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

signature0.jpg

So I gave up on this back then, and have tried to revisit this again today.

No matter what I do, I can’t get this to work.

Here is what I am trying to do, when a module is loaded I have an interceptor with postModuleLoad, which then does this.

if(interceptData.modulename == ‘myModule’) {
log.info(‘Module Name #interceptData.modulename#’);
var logboxConfig = logbox.getConfig();
logboxConfig.appender(name=‘myModuleTracer’,
class=“coldbox.system.logging.appenders.RollingFileAppender”,
properties = {filePath=’/logs’, fileName=‘myModule’, autoExpand=true, fileMaxSize=1000, fileMaxArchives=9}
);

var componentNames = directoryList( moduleSetting.path, true, “query”, “*.cfc”, “name asc” );
for(var file in componentNames) {
var cleanPath = replacenocase(file.directory, expandPath(modulesPath), “”, “all”);

cleanPath = “modules.” & removeChars(replacenocase(cleanPath, “”, “.”, “all”), 1, 1);
var catergoryName = cleanPath & “.” & replaceNoCase(file.name, “.cfc”, “”);
if(!logboxConfig.categoryExists(catergoryName)) {
logboxConfig.category(name = catergoryName, appenders = “myModuleTracer”);
}
}

}

Which works, if I dump the getAllAppenders or getAllCategories, everything looks fine. However, when I do something like this in a service or handler.

property name=“log” inject=“logbox:logger:{this}”;

I get an error…

Error Type: Builder.BuildCFCDependencyException : [N/A]
Error Messages: Error building: modules.myModule.handlers.security -> Element myModuleTracer is undefined in a CFML structure referenced as part of an expression. with constructor arguments: {controller={[(Component=coldbox.system.web.Controller)]}}

Now I have tracked this back to the following lines in LogBox.cfc.

//Do we have a category definition, so we can build it?
if( instance.config.categoryExists(arguments.category) ){
categoryConfig = instance.config.getCategory(arguments.category);
// Setup creation arguments
args.category = categoryConfig.name;
args.levelMin = categoryConfig.levelMin;
args.levelMax = categoryConfig.levelMax;
writeDump(categoryConfig);
args.appenders = getAppendersMap(categoryConfig.appenders);
}
else{
// Setup new category name
args.category = arguments.category;
// Do Category Inheritance? or else just return the root logger.
root = locateCategoryParentLogger(arguments.category);
// Setup the category levels according to parent found.
args.levelMin = root.getLevelMin();
args.levelMax = root.getLevelMax();
}

The actual line it is falling over on is the getAppendersMap() above, and to test this I then went into that method and placed a try catch around this.

for(x=1; x lte listlen(arguments.appenders); x=x+1){
thisAppender = listGetAt(arguments.appenders,x);
appendersMap[thisAppender] = instance.appenderRegistry[thisAppender];
}

And in the catch dumped out the appendersRegistry and appenders, it is interesting to note that the categories are all there, but the appender no longer exists.

Now, if I go back to the interceptor and comment out the line where it adds the category and rerun the application it will not error. In fact if I go into a handler and dump all the appenders and categories everything looks fine. So it appears that adding appenders dynamically, is missing a step as the appender is actually missing when it is needed.

Question now is, how the hell do I add appenders and categories as the documentation on this is really self explanatory. But it doesn’t work.

signature0.jpg

Andy,

I actually got into this a while back with the same issue. What happens is that some objects are built before and may have references to loggers already that don’t auto-update. the only solution I was able to find is to add things to the root logger. Here is my snippet from DataBoss on it

// Add databoss apender
var logBoxConfig = controller.getLogBox().getConfig();
var appenderProps = { filepath="#modulePath#/logs", filename=“databoss”, autoExpand=false };
logBoxConfig.appender(name=“databoss_logger”,
class=“coldbox.system.logging.appenders.AsyncRollingFileAppender”,
properties=appenderProps,
levelMin=moduleSettings.logging.levelMin,
levelMax=moduleSettings.logging.levelMax);
// Add databoss category
logBoxConfig.category(name=“databoss”,
appenders=“databoss_logger”,
levelMin=moduleSettings.logging.levelMin,
levelMax=moduleSettings.logging.levelMax);
// Store back config
controller.getLogBox().configure( logBoxConfig );

The final line is what helped me get this working.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

signature0.jpg

I was thinking the same thing, and thought afterAspectsload or someting might even be a solution to no avail.

Let me give that a shot.

signature0.jpg

signature0.jpg

bingo Luis, but I think you knew that would work.

signature0.jpg

signature0.jpg

LOL, that worked for me yes! Tricky little sucker!

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

signature0.jpg

signature0.jpg

Yeah, that’s why I reached out. But never thought of doing that.

But all is good now.

signature0.jpg

signature0.jpg

signature0.jpg