[Coldbox 3.1] Small Issue with Email Logging

I'm implementing logbox to handle my 'exceptionHandler' in CB Config.
I'm using as a reference this article:
http://www.anujgakhar.com/2011/12/01/using-coldbox-and-logbox-for-error-logging/.

Basically I want an email notification when an exception occurs and
the error to be logged to the database. The database logging is
working fine, but I'm getting two emails for the one exception with
subjects that look like this:

1) ERROR-emaillogger-Error Email from Enrollment
2) ERROR-dbLog-Error Email from Enrollment

My logbox settings in coldbox are:

logBox = {
      // Define Appenders
      appenders = {
        coldboxFile = {
  
class="coldbox.system.logging.appenders.AsyncRollingFileAppender",
          properties={
            filePath="logs",
            fileName=coldbox.appname,
            autoExpand=true,
            fileMaxSize=2000,
            fileMaxArchives=2
          }
        },
        dbLog = {
  
class="coldbox.system.logging.appenders.AsyncDBAppender",
                properties = {
                    dsn = 'edi',
                    table = '_ERRORS',
                    autocreate = true
                },
                levelMax = "WARN",
                levelMin = "FATAL"
        },
          emailLog = {
                class="coldbox.system.logging.appenders.EmailAppender",
                properties =
                {
                    from = 'errors@enrollment.com',
                    to = 'brett@enrollment.com',
                    subject = 'Error Email from Enrollment'
                },
                levelMax = "WARN",
                levelMin = "FATAL"
        }
          },
        root = {levelMax="INFO", appenders="*"},
        categories = {
            "dblogger" = { levelMin="FATAL", levelMax= "WARN",
appenders="dbLog" },
            "emaillogger" = { levelMin="FATAL", levelMax= "WARN",
appenders="emailLog" }
        },
        OFF = ["coldbox.system"]
    };

And what is happening in my onException handler is this:

function onException(event){
    var exceptionBean = Event.getValue("ExceptionBean");

    var info = {};
    info.event = rc.event;
    info.appuser = rc.appuser;
    info.app_properties = rc.app_properties;
    info.exception = exceptionBean.getMemento();

dblogger.error("MESSAGE:#exceptionBean.getExceptionStruct().message#,
DETAIL:#exceptionBean.getExceptionStruct().detail#",info);

emaillogger.error("MESSAGE:#exceptionBean.getExceptionStruct().message#,
DETAIL:#exceptionBean.getExceptionStruct().detail#",info);
  }

Thoughts on why I would be getting two emails, instead of just the
one?

Thanks in advance.
Brett

I’m not quite sure what you’ve got going on there, but I would suggest trying only one appender or logger at a time to help narrow down what’s going on. You didn’t show us the code where you define dblogger and emaillogger, but if I was to guess, I would say that one of your named loggers (such as dblogger) isn’t picking up the config and is actually just the root logger which has all appenders mapped to it.

For instance, the following two examples would both exhibit that behavior:
dblogger = logBox.getRootLogger();
dblogger = logBox.getLogger(this);

This example, however, is what you should be doing:
dblogger = logBox.getLogger('dblogger;);

Output the following in your page, and tell us what you get back:

#dblogger.getCategory()#
#emaillogger.getCategory()#

You should get “dblogger” and “emaillogger” output. If not, you’re not getting the loggers you think you’re getting.

There’s also a chance that you’re logging the error and the framework is also logging the same error on the root logger.

Also, if I may offer a bit of commentary on your approach… I don’t see anything technically wrong with your config, but melding your appenders and your loggers together to the point where your logger is named after the appender feels a bit off. You are allowed to name your loggers however you want, but what you’re doing does preclude the possibility of using logging categories named after the classes emitting the message to cross-cut your logging configs.

For instance, I use the follow three appenders:

  1. file appender
  2. E-mail
  3. database
    I start by applying all appenders to the root logger (which every other logger inherits from), and then I apply max and min logging levels to each appender. For instance, I want my file appender to log ALL message regardless of severity, but I only want my E-mail and database appenders to log error and fatal messages.
    Then I add in a category for coldbox.system to get rid of the debug chatter and only log info and down.

Now, everywhere that I log any kind of message, I always get the logger like so:

This will return a logger that is named after the full path to whatever component I’m in. If I do logger.info(), then the DB and E-mail appender will ignore the message, and the file appender will pick it up. If I do logger.error(), then all three appenders will process it. In this way, my code doesn’t know or care which appenders will handle its message. My code just logs the message, and LogBox takes care of the rest based on my config. This allows you to change who logs what after the fact by only modifying your config, not all your logging code.

Now, the beauty comes here: If i want to turn off or change logging for only a certain portion of my app, I can can add logging categories to the config like so:

// Turn off logging for all classes in the “widget” package.
logbox.categories[“com.myOrg.widget”] = {levelMax=“OFF”,levelMin=“OFF”, appenders="" };

// Only use file appender in the “foobar” package.
logbox.categories[“com.myOrg.foobar”] = {appenders=“coldboxFile” };

These named logging categories “extend” the root logger and override its config.

Anyway, there can be many “right” LogBox configurations, but I wanted to show the separation we had in mind for loggers and appenders and what you can do with them.

Let us know what progress you make trying to narrow down which loggers are sending which E-mails.

Thanks!

~Brad