Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
// Simple Config
config = new logbox.system.logging.config.LogBoxConfig();
// Create logbox instance
logBox = new logbox.system.logging.LogBox( config );log.debug( "This is my log message, some #dynamic# date is here", dataCFC );if( log.canDebug() ){
log.debug( "This is my log message, some #dynamic# date is here", dataCFC );
}logBox = getController().getLogBox();
// or
logBoxcomponent{
function configure(){
logBox = {};
// Define Appenders
logBox.appenders = {
console = { class="coldbox.system.logging.appenders.DummyAppender" }
};
// Root Logger
logBox.root = {
levelmax="OFF",
levelMin="OFF",
appenders="*"
};
}
}registerAppender(name, class, [properties={},] [layout="",] [levelMin=0,] [levelMax=4]);if( hasCustomLayout() ){
entry = getCustomLayout().format(loge);
}
else{
entry = "#severityToString(loge.getseverity())# #loge.getCategory()# #loge.getmessage()# ExtraInfo: #loge.getextraInfoAsString()#";
}
// Log message to system.out
instance.out.println(entry);config.debug( "com.model.myclass", "coldbox.system.controller" );
config.info( "com.model.otherclass", "coldbox.system.whatever" );
config.fatal( "com.model.otherclass", "coldbox.system.whatever" );
config.error( "com.model.otherclass", "coldbox.system.whatever" );
config.off( "com.model.otherclass", "coldbox.system.whatever" );logbox = new logbox.system.logging.LogBox();# Latest CommandBox
box install logbox
# Bleeding Edge
box install logbox@be __ ______ _______ .______ ______ ___ ___
| | / __ \ / _____|| _ \ / __ \ \ \ / /
| | | | | | | | __ | |_) | | | | | \ V /
| | | | | | | | |_ | | _ < | | | | > <
| `----.| `--' | | |__| | | |_) | | `--' | / . \
|_______| \______/ \______| |______/ \______/ /__/ \__\
// User.cfc
component{
function $toString(){
// return my representation as a comma list of values of my properties
return "#getName()#,#getAge()#,#getEmail()#";
}
}<--- format --->
<cffunction name="format" output="false" access="public" returntype="string" hint="Format a logging event message into your own format">
<cfargument name="logEvent" type="logbox.system.logging.LogEvent" required="true" hint="The logging event to use to create a message.">
</cffunction>//add a FileAppender with my own formatting
props = { filePath='/logs', fileName='Test' };
config.appender(
name='Fileapp',
class="logbox.system.logging.appenders.FileAppender",
properties=props,
layout="model.logging.MyFileLayout"
);public void root([numeric levelMin="-1",] [numeric levelMax="4",] string appenders)// LogBox wired in
property name="logBox" inject="logbox";
// Root Logger
property name="logger" type="logbox:root";
// Named Category
property name="logger" type="logbox:logger:com.api.model";
// Category eq to ClassPath
property name="logger" type="logbox:logger:{this}";//Add your own appender at runtime
jms = createObject( "component", "com.appender.JMSAppender" ).init( "JMSAppender", properties );
logger.addAppender( jms );
//log a message to all appenders and to my jms appender:
logger.fatal( "I FAILED MAN!" );
//remove it
logger.removeAppender( "JMSAppender" );user = userService.getUser( rc.id );
// need to log it.
if( log.canDebug() ){
log.debug( "User just got logged in right now!", user );
}config.root( appenders="*" );
config.root( levelMax="WARN", appenders="console,files" );
config.root( levelMin="INFO", levelMax="DEBUG", appenders="*" );<major>.<minor>.<patch> __ ______ _______ .______ ______ ___ ___
| | / __ \ / _____|| _ \ / __ \ \ \ / /
| | | | | | | | __ | |_) | | | | | \ V /
| | | | | | | | |_ | | _ < | | | | > <
| `----.| `--' | | |__| | | |_) | | `--' | / . \
|_______| \______/ \______| |______/ \______/ /__/ \__\
config.appender(
name="CFConsole",
class="coldbox.system.logging.appenders.ConsoleAppender"
);
config.appender(
name="MyCF",
class="coldbox.system.logging.appenders.CFAppender"
);
config.appender(
name="SocketBaby",
class="coldbox.system.logging.appenders.SocketAppender",
properties={ host="localhost", port="444", timeout="3", persistConnection=false }
);
config.appender(
name='Fileapp',
class="coldbox.system.logging.appenders.FileAppender",
properties={ filePath="/logs", fileName="Test" },
layout="model.logging.MyFileLayout"
);//log all email service messages to the MyLogFileAppender and the Console.
config.category( name="org.model.EmailService", appenders="MyLogFileAppender,Console" );<major>.<minor>.<patch>getLogger( this )// Appenders
config.appender(
name="console",
class="logbox.system.logging.appenders.ConsoleAppender"
);
config.appender(
name="file",
class="logbox.system.logging.appenders.FileAppender",
properties={ filePath="/logs" }
)// Explicit Categories
config.category(
name="coldbox.system",
levelMin=config.logLevels.INFO,
appenders="console"
);
// Implicit Categories
config.error(
"coldbox.system.plugins"
);
// same as
config.cateogry(
name="coldbox.system.plugins",
levelMax="ERROR"
);logger = logBox.getLogger( "coldbox.system.plugins.BeanFactory" );
logger.info( "hello info" );
logger.error( "wow and error occurred" );
logger = logBox.getLogger( "coldbox.system.interceptors.SES" );
logger.info( "hello info" );
logger.debug( "a cool debug message" );// setting some messages
myLogger = logBox.getLogger( this ); // "com.model.dao"
myLogger.info( "I just created my first logger" );
try{
data = dao.getDBData();
}
catch( any e ){
myLogger.error(
"Something really died on my dbdata method: #e.message# #e.detail#",
e.tagContext
);
}
// Any appender can be asynchronous!
dbDebugger = {
class="logbox.system.logging.appenders.DBAppender",
properties={
dsn="blog",
table="logs",
autocreate=true,
textDBType="NCLOB",
async=true
}
}// Adding appenders
props = {
filePath=expandPath( "/logbox/testing/cases/logging/tmp" ),
autoExpand=false,
fileMaxArchives=1,
fileMaxSize=3000,
async=true
};
config.appender(
name="MyAsyncFile",
class="logbox.system.logging.appenders.RollingFileAppender",
properties=props
);
// Socket
props = { host="localhost", port="444", timeout="3", persistConnection=false };
config.appender(
name="SocketAppender",
class="logbox.system.logging.appenders.SocketAppender",
properties=props
);function configure(){
logBox = {
// Register Appenders
appenders = {
MyAsyncFile = {
class="logbox.system.logging.appenders.RollingFileAppender",
properties={
filePath=expandPath( "/logbox/testing/cases/logging/tmp" ),
autoExpand=false,
fileMaxArchives=1,
fileMaxSize=3000,
async=true
}
},
SocketAppender = {
class="logbox.system.logging.appenders.SocketAppender",
properties={
host="localhost",
port="444",
timeout="3",
persistConnection=false
}
}
}
};
}


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" ]
};init([CFCConfig,CFCConfigPath])// Using config path
config = createObject( "component", "logbox.system.logging.config.LogBoxConfig" )
.init( CFCConfigPath="my.path.LogBoxConfig" );
logBox = createObject( "component", "logbox.system.logging.LogBox" ).init( config );
// Using config object
data = createObject( "component", "my.data.CFC" );
config = createObject( "component", "logbox.system.logging.config.LogBoxConfig" ).init( data );
logBox = createObject( "component", "logbox.system.logging.LogBox" ).init( config );<--- Init --->
<cffunction name="init" access="public" returntype="AbstractAppender" hint="Constructor called by a Concrete Appender" output="false" >
<--- ************************************************************* --->
<cfargument name="name" type="string" required="true" hint="The unique name for this appender."/>
<cfargument name="properties" type="struct" required="false" default="#structnew()#" hint="A map of configuration properties for the appender"/>
<cfargument name="layout" type="string" required="false" default="" hint="The layout class to use in this appender for custom message rendering."/>
<cfargument name="levelMin" type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARN"/>
<cfargument name="levelMax" type="numeric" required="false" default="4" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARN"/>
<--- ************************************************************* --->
</cffunction><--- Constructor --->
<cffunction name="init" access="public" returntype="FileAppender" hint="Constructor" output="false">
<---************************************************************** --->
<cfargument name="name" type="string" required="true" hint="The unique name for this appender."/>
<cfargument name="properties" type="struct" required="false" default="#structnew()#" hint="A map of configuration properties for the appender"/>
<cfargument name="layout" type="string" required="true" default="" hint="The layout class to use in this appender for custom message rendering."/>
<cfargument name="levelMin" type="numeric" required="false" default="0" hint="The default log level for this appender, by default it is 0. Optional. ex: LogBox.logLevels.WARN"/>
<cfargument name="levelMax" type="numeric" required="false" default="4" hint="The default log level for this appender, by default it is 5. Optional. ex: LogBox.logLevels.WARN"/>
<---************************************************************** --->
<cfscript>
super.init(argumentCollection=arguments);
// Setup Properties
if( NOT propertyExists("filepath") ){
$throw(message="Filepath property not defined",type="FileAppender.PropertyNotFound");
}
if( NOT propertyExists("autoExpand") ){
setProperty("autoExpand",true);
}
if( NOT propertyExists("filename") ){
setProperty("filename",getName());
}
if( NOT propertyExists("fileEncoding") ){
setProperty("fileEncoding","UTF-8");
}
// Setup the log file full path
instance.logFullpath = getProperty("filePath");
// Clean ending slash
if( right(instance.logFullpath,1) eq "/" OR right(instance.logFullPath,1) eq "\"){
instance.logFullPath = left(instance.logFullpath, len(instance.logFullPath)-1);
}
instance.logFullPath = instance.logFullpath & "/" & getProperty("filename") & ".log";
// Do we expand the path?
if( getProperty("autoExpand") ){
instance.logFullPath = expandPath(instance.logFullpath);
}
//lock information
instance.lockName = getname() & "logOperation";
instance.lockTimeout = 25;
return this;
</cfscript>
</cffunction><--- logMessage --->
<cffunction name="logMessage" access="public" output="false" returntype="void">
<cfargument name="logEvent" type="logbox.system.logging.LogEvent" required="true" hint="The logging event to log.">
</cffunction><--- Log Message --->
<cffunction name="logMessage" access="public" output="true" returntype="void" hint="Write an entry into the appender.">
<---************************************************************** --->
<cfargument name="logEvent" type="logbox.system.logging.LogEvent" required="true" hint="The logging event"/>
<---************************************************************** --->
<cfscript>
var logStack = "";
var entry = structnew();
var limit = getProperty('limit');
var loge = arguments.logEvent;
// Verify storage
ensureStorage();
// Check Limits
logStack = getStorage();
if( limit GT 0 and arrayLen(logStack) GTE limit ){
// pop one out, the oldest
arrayDeleteAt(logStack,1);
}
// Log Away
entry.id = createUUID();
entry.logDate = loge.getTimeStamp();
entry.appenderName = getName();
entry.severity = severityToString(loge.getseverity());
entry.message = loge.getMessage();
entry.extraInfo = loge.getextraInfo();
entry.category = loge.getCategory();
// Save Storage
arrayAppend(logStack, entry);
saveStorage(logStack);
</cfscript>
</cffunction><cffunction name="onRegistration" access="public" hint="Runs after the appender has been created and registered. Implemented by Concrete appender" output="false" returntype="void">
</cffunction>
<cffunction name="onUnRegistration" access="public" hint="Runs before the appender is unregistered from LogBox. Implemented by Concrete appender" output="false" returntype="void">
</cffunction><--- onRegistration --->
<cffunction name="onRegistration" output="false" access="public" returntype="void" hint="When registration occurs">
<cfif getProperty("persistConnection")>
<cfset openConnection()>
</cfif>
</cffunction>
<--- onRegistration --->
<cffunction name="onUnRegistration" output="false" access="public" returntype="void" hint="When Unregistration occurs">
<cfif getProperty("persistConnection")>
<cfset closeConnection()>
</cfif>
</cffunction>
