Appender
An appender is an object that LogBox uses to log statements to a destination repository. All appenders act as destinations that can include: databases, JMS, files, consoles, sockets, etc. The appender has the responsibility of taking the logged message and persisting the message or sending the message to an external service. LogBox comes bundled with the following appenders that can be found in the package coldbox.system.logging.appenders:
Appender
Description
CFAppender
Will deliver messages to the coldfusion logs.
ConsoleAppender
Will deliver messages to the server's console via system.out
DBAppender
Will deliver messages to a database table. It can auto create the table for you.
DummyAppender
An endless void of nothingness
EmailAppender
Will deliver messages to any email address.
FileAppender
Will deliver messages a file.
RollingFileAppender
A file appender that can do file rotation and archiving.
ScopeAppender
Will deliver messages to any ColdFusion variable scope.
SocketAppender
Will connect to any server socket and deliver messages.
TracerAppender
Will deliver messages to the ColdFusion tag cftrace.
Asynchronous Appenders
You may wish your logs to be asynchronous. You can do so by passing an async property in your configuration. ( This happens at the logger level and is available to all appenders out of the box, even ones that you create yourself!
1
// Any appender can be asynchronous!
2
dbDebugger = {
3
class="logbox.system.logging.appenders.DBAppender",
4
properties={
5
dsn="blog",
6
table="logs",
7
autocreate=true,
8
textDBType="NCLOB",
9
async=true
10
}
11
}
Copied!

Configuration

You can configure LogBox to use one or all of these appenders at any point in time. You can even register as many instances of any appender by defining a unique name for each. Here are examples of how one can configure appenders programmatically or via the simple configuration CFC:
Programmatic Approach
1
// Adding appenders
2
props = {
3
filePath=expandPath( "/logbox/testing/cases/logging/tmp" ),
4
autoExpand=false,
5
fileMaxArchives=1,
6
fileMaxSize=3000,
7
async=true
8
};
9
10
config.appender(
11
name="MyAsyncFile",
12
class="logbox.system.logging.appenders.RollingFileAppender",
13
properties=props
14
);
15
16
// Socket
17
props = { host="localhost", port="444", timeout="3", persistConnection=false };
18
config.appender(
19
name="SocketAppender",
20
class="logbox.system.logging.appenders.SocketAppender",
21
properties=props
22
);
Copied!
Configuration CFC approach
1
function configure(){
2
3
logBox = {
4
// Register Appenders
5
appenders = {
6
MyAsyncFile = {
7
class="logbox.system.logging.appenders.RollingFileAppender",
8
properties={
9
filePath=expandPath( "/logbox/testing/cases/logging/tmp" ),
10
autoExpand=false,
11
fileMaxArchives=1,
12
fileMaxSize=3000,
13
async=true
14
}
15
},
16
17
SocketAppender = {
18
class="logbox.system.logging.appenders.SocketAppender",
19
properties={
20
host="localhost",
21
port="444",
22
timeout="3",
23
persistConnection=false
24
}
25
}
26
}
27
};
28
29
}
Copied!
Another feature of a LogBox appender is that you can extend them or create new ones simply by leveraging the LogBox API. To customize LogBox appenders for your own unique needs you would simply extend the core appender class: coldbox.system.logging.AbstractAppender and implementing the init() and logMessage() methods. Extending LogBox will be reviewed in greater detail over the next few sections.
Copy link