Using MongoDB for logging

Recently, we’ve tested using MongoDB for a lot of different purposes. This article gives an example of how to log to MongoDB from PHP.

First, a very basic logging class written in PHP:

To do logging from your code, you simply do So_log::debug(message, object);:

You may easily access your logs through the Mongo shell, however it might be convenient to write your own customized tool to tail the logs. Yoy may extend the tools to give more advanced filtering and presentation options.

Here is a very basic tool for tailing the log, written in javascript.

To run the log tailer, run mongo oauth log.js.

The result, will look like this:

Leave a Reply