Configuring LogBox

LogBox comes pre-configured for operation with very basic logging. However, you can customize it to your fancy using different configuration strategies using the programmatic configuration object or the LogBox Config DSL.
When you are in a ColdBox application, you will have a logbox structure in your ColdBox.cfc already that you can use, or you can create a portable CFC as well and place it in config/LogBox.cfc
The cool thing about this LogBox DSL is that it is the same whether you are using LogBox in ColdBox applications or any other framework or non-framework ColdFusion application.
Configuration can be done in the following ways:
  1. 1.
    No configuration: Uses the default configuration shown below
  2. 2.
    Portable CFC: Creating a portable data CFC using the LogBox DSL in a configure() method
  3. 3.
    LogBoxConfig: Creating the LogBoxConfig object and interacting with its methods programmatically
  4. 4.
    LogBox DSL Struct: Passing a struct literal into LogBox, using the LogBox DSL.

1. Default Configuration

This is the default configuration when LogBox is created with no config:
1
component {
2
3
/**
4
* Configure logBox
5
*/
6
function configure(){
7
logBox = {
8
// Define Appenders
9
appenders : {
10
console : { class : "ConsoleAppender" }
11
},
12
13
// Root Logger
14
root : {
15
levelmax : "INFO",
16
appenders : "*"
17
}
18
};
19
}
20
21
}
22
23
// Instantiate it
24
application.logbox = new logbox.system.logging.LogBox();

2. Portable CFC

You can create a CFC with a single configure method with the LogBox configuration in a variable called logbox using the LogBox DSL.
component output="false" hint="A LogBox Configuration Data Object" {
/**
* Configure LogBox, that's it!
*/
function configure(){
logBox = {
// Define Appenders
appenders : {
coldboxTracer : {
class : "ConsoleAppender",
layout : "coldbox.tests.specs.logging.MockLayout",
properties : { name : "awesome" }
}
},
// Root Logger
root : { levelmax : "INFO", levelMin : 0, appenders : "*" },
// Categories
categories : {
"coldbox.system" : { levelMax : "INFO" },
"coldbox.system.interceptors" : { levelMin : 0, levelMax : "DEBUG", appenders : "*" },
"hello.model" : { levelMax : 4, appenders : "*" }
},
debug : [ "coldbox.system", "models.system" ],
info : [ "hello.model", "yes.wow.wow" ],
warn : [ "hello.model", "yes.wow.wow" ],
error : [ "hello.model", "yes.wow.wow" ],
fatal : [ "hello.model", "yes.wow.wow" ],
OFF : [ "hello.model", "yes.wow.wow" ]
};
}
}
// Instantiate it by passing the path to this CFC
application.logbox = new logbox.system.logging.LogBox( "config.LogBoxConfig" );

3. Programmatic LogBoxConfig

config = new logbox.system.logging.config.LogBoxConfig();
// Appenders
config
.appender( name = "luis", class = "coldbox.system.logging.appenders.ConsoleAppender" )
.appender( name = "luis2", class = "coldbox.system.logging.appenders.ConsoleAppender" )
.root( appenders = "luis,luis2" )
// Sample categories
.OFF( "coldbox.system" )
.debug( "coldbox.system.async" );
// init logBox with Config CFC
application.logbox = new logbox.system.logging.LogBox( config );

4. Struct Literal Config

var logBox = new logbox.system.logging.LogBox(
{
appenders : { myConsoleLiteral : { class : "ConsoleAppender" } },
root : { levelmax : "FATAL", appenders : "*" },
info : [ "hello.model", "yes.wow.wow" ],
warn : [ "hello.model", "yes.wow.wow" ],
error : [ "hello.model", "yes.wow.wow" ]
}
);
Last modified 3mo ago