Howto Log Directly to Your OS X Terminal using Zend Framework and NodeJS

Are you interested in being able to log directly to your OS X terminal from within your Zend Framework based app? If yes, then this tutorial may be for you!

What is Zend Framework and NodeJS

First of all you may be wondering about Zend Framework and NodeJS? Zend Framework is a PHP 5 based development framework. It is commonly used to build web applications. NodeJS is a tool designed to provide an easy way to build scalable network programs. By using the I/O capabilities of NodeJS, I have built a simple TCP server that writes log messages to the OS X terminal (via STDOUT).

Getting Started

First of all you will need to have NodeJS installed. You can follow the instructions on their website: http://nodejs.org/#build. You should also have a basic understanding of how to use Git and GitHub.

Running the Node_Log Server

Start by cloning my GitHub repository (http://github.com/robmorgan/node_log) to a working directory on your system and start the server:

$ git clone git://github.com/robmorgan/node_log.git
$ cd node_log
$ /usr/local/bin/node node_log.js

The server will fire up and start listening on the default host and port (tcp://localhost:8003):

Next we can begin logging events to the Node_Log server.

Logging Events from your Zend Framework App

I have written a Zend Framework compatible log writer specifically for Node_Log. It is available here: http://github.com/robmorgan/zfnode_log_writer. You can clone my git repository by executing:

$ git clone git://github.com/robmorgan/zfnode_log_writer.git

Next you should copy the contents of the library/ directory to the library/ directory within your Zend Framework based app. Now we are ready to log our first event to Node_Log. Simply include Zend_Log and the log writer (ignore the includes if you use the Autoloader) and make a standard logging call. I have provided an example below:

And here’s what the terminal output looks like:

Conclusion

Now you have the ability to log to your OS X terminal direct from your ZF-based app! In the future I plan to add a web interface, color highlighting based on severity and persistence of log messages to disk. Feel free to clone my GitHub repository if you’d like to contribute. Have any questions? Please leave a comment below or follow me on Twitter and @reply me.

Comments

comments powered by Disqus

Notes

  1. robbym posted this