logger customization

Hi

Is it possible to customize logger message severity and only log
messages with certain severity?
e.g log message with severity = error or fatal

cheers
MAQ.

Sure, you can call the logger plugin anytime you want.
To write an entry, call method logEntry with following arguments:
severity,message and extrainfo.

e.g. getPlugin('logger').logEntry('fatal','some error occured','line 456')

Ernst

No I mean is there any config settings to filter the global log
messages to generate only error/warning/fatal, as once I set
    <!--Log Errors and entries in ColdBox's own logging facilities. You
choose the location, finally per application logging.-->
    <Setting name="EnableColdboxLogging" value="true" />
    <!--The absolute or relative path to where you want to store your
log files for this application-->
    <Setting name="ColdboxLogsLocation" value="logs" />
ColdBox start generating log file logs/hr.log:

"Severity","ThreadID","Date","Time","Application","Message"
"information","logger-plugin","12/26/2008","20:10:40","Dependency:
{NAME={CandidateService}, TYPE={model}, SCOPE={instance}} --> injected
into hr.handlers.ehcandidate."
"information","logger-plugin","12/26/2008","20:10:40","Dependency:
{NAME={CookieStorage}, TYPE={coldbox:plugin:cookiestorage}, SCOPE=
{instance}} --> injected into hr.handlers.ehcandidate."
"information","logger-plugin","12/26/2008","20:10:40","Dependency:
{NAME={SessionStorage}, TYPE={coldbox:plugin:sessionstorage}, SCOPE=
{instance}} --> injected into hr.model.userservice."
"information","logger-plugin","12/26/2008","20:10:40","Dependency:
{NAME={Transfer}, TYPE={ocm}, SCOPE={instance}} --> injected into
hr.model.userservice."
"information","logger-plugin","12/26/2008","20:10:40","Dependency:
{NAME={ColdBox}, TYPE={coldbox}, SCOPE={instance}} --> injected into
hr.model.userservice."
"information","logger-plugin","12/26/2008","20:10:40","Dependency:
{NAME={MessageBox}, TYPE={coldbox:plugin:messagebox}, SCOPE=
{instance}} --> injected into hr.model.userservice."
"information","logger-plugin","12/26/2008","20:10:40","Dependency:
{NAME={UserService}, TYPE={model}, SCOPE={instance}} --> injected into
hr.handlers.ehcandidate."
"error","logger-plugin","12/26/2008","20:10:40","Custom Error
Message: Application Execution ExceptionCFErrorType=expression
CFMessage=No matching Method/Function for Struct.getbean(string) found
at railo.runtime.reflection.Reflector.a(Unknown Source)
"information","logger-plugin","12/26/2008","20:11:26","Dependency:
{NAME={BeanFactory}, TYPE={coldbox:plugin:beanFactory}, SCOPE=
{instance}} --> injected into hr.handlers.ehcandidate."
"information","logger-plugin","12/26/2008","20:11:26","Dependency:
{NAME={SessionStorage}, TYPE={coldbox:plugin:sessionstorage}, SCOPE=
{instance}} --> injected into hr.handlers.ehcandidate."
"information","logger-plugin","12/26/2008","20:11:26","Dependency:
{NAME={Transfer}, TYPE={ocm}, SCOPE={instance}} --> injected into
hr.handlers.ehcandidate."
"information","logger-plugin","12/26/2008","20:11:26","Dependency:
{NAME={MessageBox}, TYPE={coldbox:plugin:messagebox}, SCOPE=
{instance}} --> injected into hr.handlers.ehcandidate."
"information","logger-plugin","12/26/2008","20:11:26","Dependency:
{NAME={SessionStorage}, TYPE={coldbox:plugin:sessionstorage}, SCOPE=
{instance}} --> injected into hr.model.candidateservice."

I don't want the info messages.

MAQ.

No, not that I know MAQ.

You could disable the logging and create an interceptor which listens
to the interceptor-point 'onExeception'.
In that method you can call the logger plugin and only log certain
messages depending on interceptorData.

Ernst

Thanks Ernst

I have disabled the ColdBox logging in Production.
We should have some sort of logging level in the logger plugin.

Since I start using the new DI <cfproperty type="" the log file is
growing very fast with the "dependency information" entries but in
Production I am more interested in error/warning/fatal messages

MAQ.

Ernst
Interceptors: I am still in the learning phase
Could you please give me some sample or example
cheers
MAQ.

Check out the docs for interceptors...

Here is a short example:

<cfcomponent name="myErrorInterceptor" output="true"
extends="coldbox.system.interceptor" hint="My error interceptor">
  <cffunction name="onException" access="public" returntype="void" output="true">
    <cfargument name="event" required="true"
type="coldbox.system.beans.requestContext">
                 e.g. <cfset
getPlugin('logger').logEntry('fatal','some error occured','line 456')>
  </cffunction>
</cfcomponent>

Thanks Ernst

I have disable the coldbox logging and using ExceptionHandler

again forgot the basic rule "Read the Docs"

http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbExceptionHandler

MAQ.

Everybody makes that mistake, but usually.....there are NO docs :slight_smile:

Ernst

:frowning: once i disabled ColdBoxLogging, logger plugin stops working even i
can't use:
getPlugin('logger').logEntry()
getPlugin("logger").logErrorWithBean()

to log entries via ExceptionHandler or Interceptor in App log file

any ideas on
ExceptionBean
ExceptionService

MAQ.

Try this in your interceptor:

method: afterConfigurationLoad
     getPlugin("logger").initLogLocation()

method: onException
getPlugin('logger').logEntry('fatal','some error occured','line 456')

Maybe Luis has another suggestion.

Ernst

Ernst

I have added the method "afterConfigurationLoad" in myErrorInterceptor
but still its not working.
both ExceptionHandler and myErrorInterceptor only works with logger
plugin if ColdboxLogging is enable

MAQ.

Maybe this helps:

http://www.codersrevolution.com/index.cfm/2009/1/1/ColdBox-262-Bug-Log-File-Paths

if coldboxlogging or coldfusion logging is disabled, then the plugin does not log. It must be turned on in order for it to work. What do you need to do?

is there a way to control the logging at Severity level?
means record only error messages or error/warnings/fatal ones but not
the information

Sorry Maq,

Not at the moment, but you can spec out an enhancement for it.

Heh, I was thinking about this recently, so I cooked up a workaround and posted it to my blog.

http://www.fancybread.com/blog/post.cfm/customizing-the-coldbox-logger-plugin-with-method-injection

Cheers,

Paul

WOW! great stuff Paul, you can also used the mixin method on any plugin calling: includeUDF(). So you can just create a UDF helper and mixit in. The UDF helper can be a cfm template or a full fledged cfc. To make it work externally you use the methodInjector plugin also, in order to call a private method:

getPlugin("methodInjector").start(logger);
logger.invokerMixin(method='includeUDF',argList="``includes/mixin/loggerMixin")
getPlugin("methodInjector").stop(logger);

That’s it, the plugin will automix itself. Also, if you don’t want to pollute the application start handler with tons of things to happen at application startup as an event, you can create a custom interceptor that can handle your application startup in a more decoupled and reusable fashion. You can create a loggerObserver interceptor that can be reused on any application you want this functionality, just tap into the afterAspectsLoad observation point. You can even distribute it.

Luis

Also, I have added a ticket for enhancing the logger plugin to do what you did. I have been meaning to update the plugin for a while now but haven’t. This will be in the next maintenance release of 2.6.3. So if you have any more recommendations, please write them.

Hi Luis,

Very good idea to decouple the customization from the appInit event. I like the invokerMixin example as well.

I’ll mod my app for that shortly. Looking forward to the enhanced logger and the next CB release!

Paul