LogBox : Enterprise Logging & Messaging
7.x
7.x
  • Introduction
    • Contribution Guide
    • Release History
      • What's New With 7.2.0
      • What's New With 7.1.0
      • What's New With 7.0.0
    • Upgrading to LogBox 7
    • About This Book
      • Author
  • Getting Started
    • Features at a Glance
    • Installation
      • LogBox Refcard
    • Need For Logging
    • How Does LogBox Work?
      • LogBox
      • Appender
      • Logger
        • Logger Category Inheritance
        • Security Levels
        • Dynamic Appenders
      • Layout
  • Configuration
    • Configuring LogBox
      • LogBox DSL
      • Adding Appenders
      • Adding Categories to Specific Logging Levels
      • Adding Categories Granularly
      • Configuring The Root Logger
  • Usage
    • Using LogBox
    • Using a Logger Object
      • When To Log
      • ExtraInfo Serialization
    • Appender Properties
      • CFAppender
      • ConsoleAppender
      • DBAppender
      • EmailAppender
      • FileAppender
      • RollingFileAppender
      • ScopeAppender
      • SocketAppender
      • TraceAppender
    • LogBox in a ColdBox Application
      • Configuration Within ColdBox
      • Benefits of using LogBox in a ColdBox application
      • Where is LogBox stored in a ColdBox app?
      • LogBox from the ColdBox Proxy
      • The LogBox Injection DSL
  • Extending LogBox
    • Creating Custom Appenders
      • Helper Methods
      • Instance Members
      • Dealing With Custom Layouts
      • Registering Appenders at Runtime
    • Creating a Custom Layout
      • Instance Members
Powered by GitBook
On this page
  • 1. Default Configuration
  • 2. Portable CFC
  • 3. Programmatic LogBoxConfig
  • 4. Struct Literal Config

Was this helpful?

Edit on GitHub
Export as PDF
  1. Configuration

Configuring LogBox

PreviousLayoutNextLogBox DSL

Last updated 1 year ago

Was this helpful?

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. No configuration: Uses the default configuration shown below

  2. Portable CFC: Creating a portable data CFC using the LogBox DSL in a configure() method

  3. LogBoxConfig: Creating the LogBoxConfig object and interacting with its methods programmatically

  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:

component {

  /**
   *  Configure logBox
   */
  function configure(){
    logBox = {
	// Define Appenders
	appenders : { 
		console : { class : "ConsoleAppender" } 
	},
	
	// Root Logger
	root : { 
		levelmax : "INFO", 
		appenders : "*" 
	}
    };
  }

}

// Instantiate it
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" ]
   }
);
LogBox DSL