views:

362

answers:

2

I’m currently using Coldfusion 8.01 in a J2EE environment (jBoss), and looking to clean up what's written to the logs. Currently Coldfusion logs everything to STDOUT instead of using a proper logger like commons or log4j. Has anyone managed to change this? Maybe there are some hidden properties you can set or a log4j.properties hiding some where. Since Coldfusion has CFLog (which outputs to STDOUT) I’d like to see that output via commons if possible as well.

+1  A: 

Hi

We use log4j with CF 8 and it works well. However, we are using a standalone configuration. Not sure if this will be of much help but here you go anyway...

All you need to do is drop in the log4j.jar file into the CF lib directory or any other directory stored in the CF classpath that suits you. Once you have done this restart CF and you can usually do something like this:

<!--- Create logger --->
<cfset objLoggerCategory = CreateObject("java", "org.apache.log4j.Category") />
<cfset objLogger = objLoggerCategory.getInstance("MY-LOGGER-XML-HOOK") />
<cfset objLogger.debug("Hello World!") />

Obviously you will need to get the Xml file configured, but there are plently of examples of that on the net.

I haven't head of overriding the CF logs to run through log4j. That said you can direct the CF logs to any directory you please if this will help. This is available in CF admin: Debugging & Logging > Logging Settings.

Cheers.

Ciaran Archer
Thanks, but I'm really looking to direct the standard Coldfusion output to a proper logger rather than STDOUT.
qbn
Well... you can ask the Railo or OpenBD guys and see if they're interested to add this feature to their CFML engines. Or... u can write your own CFLOG custom tag that uses a backward-compatible API.
Henry
+1  A: 

Hey Daniel - CF actually does use log4j for it's internal logging and has a configuration that lets you edit the layout pattern if you don't like the comma delimited pattern it defaults to.

You can edit the pattern in 'neo-logger.xml',

{your_deployment}/cfusion-war/WEB-INF/cfusion/lib/neo-logger.xml

Unfortunately, there aren't too many other properites that you can edit. You might be able to override the root logger settings in the "logger.xml" file under the same directory, I didn't have any luck in trying. In the past to I've used it to define log4j settings on custom and third party jars that we loaded up with CF.

Hope this helps.

jalpino