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 is for you!
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).
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.
Start by cloning my GitHub repository (http://github.com/robmorgan/node_log) to a working directory on your system and start the server:
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.
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:
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:
gist:robmorgan/302310#test_nodelog_writer.php
And here's what the terminal output looks like:
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.