LogBox DSL

As we have seen the LogBox DSL can be used in different contexts:

  • Portable CFC with a configure() method in a logbox variable

  • ColdBox config inside the configure() method in a logbox variable

  • A struct literal sent in to the constructor of LogBox

NO matter how you dice it, it's the same LogBox Config DSL:

**
* A LogBox configuration data object
*/
component{

    function configure(){
        logBox = {
            
            appenders : {},
            
            root : {},
            
            categories : {},
            
            fatal : [],
            error : [],
            warn  : [],
            info  : [],
            debug : [],
            off   : []

        };
    }
}

Base Config

Root level configuration keys.

Appenders

appenders : {

    console: { class : "ConsoleAppender" },
    
    jsonConsole : {
        class : "ConsoleAppender",
        layout : "models.JSONLayout",
        levelMin : 0,
        levelMax : 4
    },
    
    errorLog: { 
        class: "FileAppender",
        properties: {
            filePath : "/logs",
            fileName : "appname-errors"     
        },
        levelMin : "FATAL",
        levelMax : "ERROR"
    }
}

To define an appender you must define a struct with a key value which is the internal name of the appender. Each appender's name must be unique. You configure each appender with the following keys:

Root Logger

To configure the root logger, use the following keys:

root : {
    levelMax : "INFO",
    appenders : "*"
}

root : {
    appenders : "console",
    levelMax : "DEBUG"
}

Categories

// Granualr Categories
categories={
    "coldbox.system" = { levelMin="FATAL", levelMax="INFO", appenders="*" },
    "model.security" = { levelMax="DEBUG", appenders="console" }
}

To define categories, you define a struct with a key value, which is the internal name of the category. Each category name must be unique,. You configure each category with the following keys:

As you might notice, the names of the keys on all the structures match 100% to the programmatic methods you can also use to configure logBox. So, when in doubt, refer back to the argument names.

Example Configuration

logBox = {
    // Appenders
    appenders = {
        appenderName = {
            class="class.to.appender",
            layout="class.to.layout",
            levelMin=0,
            levelMax=4,
            properties={
                name  = value,
                prop2 = value 2
            }
    },
    // Root Logger
    root = { levelMin="FATAL", levelMax="DEBUG", appenders="*" },
    // Granualr Categories
    categories={
        "coldbox.system" = { levelMin="FATAL", levelMax="INFO", appenders="*" },
        "model.security" = { levelMax="DEBUG", appenders="console" }
    },
    // Implicit categories
    debug = [ "coldbox.system.interceptors"  ],
    info  = [ "model.class", "model2.class2" ],
    warn  = [ "model.class", "model2.class2" ],
    error = [ "model.class", "model2.class2" ],
    fatal = [ "model.class", "model2.class2" ],
    off   = [ "model.class", "model2.class2" ]
};

Last updated