Sunday, November 4, 2007

MochaLogger Alpha Release

PHP is an interesting language. It's designed specifically for writing web sites. Furthermore, it's designed to do mostly presentation layer work. CakePHP follows Ruby on Rails' framework. It has a somewhat well defined MVC framework, good scaffolding functions and alright performance. PHP as a presentation layer language allows the system logs to be sent to client's browser. A developer can use browser to debug server side problem quickly. CakePHP also provides this function.

Displaying system logs on the browser is very useful during dev testing. However, in real production environment, nobody wants to expose any system logs to the end users. CakePHP's file logging system is poorly implemented. It only offers two levels of logs: DEBUG or ERROR. Furthermore, debug logs and error logs are saved to two different files. This makes troubleshooting system problem by reading logs very difficult.

I'm a long time Java user. Log4J is a great logging system. It allows users to write to the same or multiple log files with DEBUG, INFO, WARN, ERROR or FATAL level log messages. With Log4J, a developer can add as detailed as needed DEBUG logs to his code without worrying about printing out too much information on the production server. He can simply set the production server's log level to WARN above only. A developer can even configure different log level for different Java classes.

In order to log more meaningful information in our system, I implemented MochaLogger. It's a plugin into CakePHP. It offers basic logging functions with 5 different levels of logs. It has an UI that allows users to configure logging levels for each PHP file/object at run time. MochaLogger is open sourced on CakeForge: http://cakeforge.org/frs/?group_id=215

No comments: