Skip to content

Instantly share code, notes, and snippets.

@zircote
Created March 13, 2012 19:15
Show Gist options
  • Select an option

  • Save zircote/2030868 to your computer and use it in GitHub Desktop.

Select an option

Save zircote/2030868 to your computer and use it in GitHub Desktop.
MongoDB Logging
<?php
// db.createCollection("logCollection", {capped:true, size:100000})
$mongo = new Mongo();
$db = $mongo->selectDB('logging');
$collection = $db->selectCollection('logCollection');
$cursor = $collection->find()->tailable(true);
while (true) {
if ($cursor->hasNext()) {
$doc = $cursor->getNext();
echo date(DATE_ISO8601, $doc['timestamp']->sec), ' ',$doc['priorityName'],' ', $doc['message'], PHP_EOL;
} else {
usleep(100);
}
}
<?php
require_once 'Zend/Loader/Autoloader.php';
require_once '/Users/zircote/zend/Zend_Log_Write_Mongo/library/Zend/Log/Writer/Mongo.php';
$loader = Zend_Loader_Autoloader::getInstance();
$config = array(
'collection' => 'logCollection',
'database' => 'logging'
);
$writer = Zend_Log_Writer_Mongo::factory($config);
$log = new Zend_log();
$log->addWriter($writer);
$log->info('this is a test');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment