RE: [coldbox:17601] Re: Logging Appender's use witch one

I’m not certain I fully understand what you have set up, but at first glance it does seem as though you’re confusing appenders and logging categories.

When you call logbox.getLogger(“foobar”), foobar is the name of a logging category, not the name of an appender. Remember that loggers (or logger categories) can have any number of appenders assigned to them. Now, I suppose there’s nothing keeping you from also creating an appender called foobar and assigning it to the foobar logger, but that just sounds confusing.

So to try and answer your questions:

How do I have the name of the component show up in the logged message?
You will either need to allow LogBox to automatically create named loggers for you with logbox.getLogger(this) which uses the metadata of the component OR you will have to manually include that name in the log text yourself.

I want send an email using the appender, only at specific times…
I think the crux of the issue might be that you are crossing your concerns. The code generating the log message should not know or care what kind of appender will be used if any at all. The only information your code is aware of is the log severity and the message itself. Once that is passed off to the logger, LogBox will make a determination about what appenders are assigned to that logger based on its category name. If there is no explicit assignment it climbs the dot-delimited hierarchy until it reaches the root logger. If your code knows that it specifically wants an E-mail to be sent, you might need to be looking at the EmailService instead.

If that doesn’t help you, I’ll need more information about what you’re trying to accomplish.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Brad,

That is the problem, I am adding the appenders via code, I understand the categories etc., the problem is that when adding the appender LogBox doesn’t see the appender.

Now as there are absolutely no code to show how this should be done, I am turn with reading between the Wiki and the code to try to do this. The problem is that the only way to dynamically add appenders is like this.

logger.appender(
name = “myEmailAppender”,
class=“coldbox.system.logging.appenders.EmailAppender”,
properties = {
}
);

And the error message is unknown appender myEmailAppender, so when I went digging I then looked and found a private method called RegisterAppender() which if I make public and call it like this.

logBox.registerAppender(
name = “myEmailAppender”,
class=“coldbox.system.logging.appenders.EmailAppender”,
properties = {
}
);

I no longer see the error message, but the appender is not fired. What I have done is locked it down so that the category for this Appender is my module, so that any time I do log.debug() my email appender is suppose to fire. Well it appears to fire but no email is ever sent.

But the problem is that I had to hack LogBox to remove a private method and make it public to stop throwing errors, so the question is am I doing this right or is there a better approach?

I tried not adding a category for the appender and adding a category with the same results, no email. To prove that I have email logging switched on in ColdFusion for sent and all errors and nothing is showing up in here, so I am at a loss to explain what I need to do.

Ideally, I should be able to add an appender via code for any given Module, and make that the root or the default appender and automatically switch back to the root when I am not in that Module. So this could be an E/R to have that added, but for now I just need this appender added via code and only be available to this Module. Which is what the categories appear to achieve, but like I said the appender is not even being fired.

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

In fact when I put logging into the logger.cfc when it loops over the appenders, shows that the appender is not being registered no matter which way I try to register this. And being an emailAppender I need to do this dynamically for ContentBox because I need it to use the same settings as defined in the dashboard settings, so putting this into the config.cfc is way out of the question.

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