alanwilliamson

Adding Java Logging to CFML via logger()

Logging in CFML has always been a bit of a home-grown affair. Sure we have always had CFLOG, WriteLog() and even Console(), and as powerful and useful as they are, they do not offer the flexibility of the logging on offer from the underlying Java platform through the Java Logging API.

With the Java Logging you can do more than just output simple log messages to the console or a log file. There is a whole eco-system around the output of the Java Logging, including alert systems, special formats, logging to system files (on Linux) or even to remote servers in a distributed network.

At aw2.0 we have our own centralized logging we designed for specifically for our large cloud installations that gathers up the logging from our Java processes in real time to a centralized server that we can then investigate and drill down using a web interface.

But we've missed this power in our OpenBD CFML applications. So we just had to do something about it.

Allow us to introduce to the CFML world a new powerful log hook: logger().

<cfscript>
  logger( msg="this is a test message", level="info" );
</cfscript>

This very simple looking function maps directly down to the underlying Java Logging framework. Not only will you get the message out, but as part of the Java logging detailed information, you will also get the context of your call with you doing any extra work. This means if you are running in a CFC for example, you will get the name of the CFC, the name of the method you are currently within, and also the line number within that file. That's a lot of extra information, free of charge.

What is nice about this is that logging can be controlled by a separate logging properties file allow you to turn off logging messages of a given level, or even, alert when certain log messages are marked only as 'servere'. Most application engines define a special place for this output to go.

This method is wonderfully compatible with our Google App Engine build. Any call to logger() inside the OpenBD:GAE application will get stored to your applications main logger, that is viewable via the Google App Administration console. Very neat.

Available now from the nightly build.


 

Recent Cloud posts

Recent JAVA posts

Latest CFML posts


 
Site Links