Yii 1.1: mongodblogroute

MongoDB log route

MongoDB Log Route.


Yii 1.1.8 or above



Extract the release file under protected/extensions

In config/main.php:

      'levels'=>'trace, info, error, warning',
      'categories' => 'system.*',


  • connectionString : host:port : defalut localhost:27017
  • dbName : database name : default test
  • collectionName : collaction name : default yiilog
  • message : message column name : default message
  • level : level column name : default level
  • category : category column name : default category
  • timestamp : timestamp column name : default timestamp
  • timestampType : float or date : default float
  • collectionSize : capped collection size : default 10000
  • collectionMax : capped collection max : default 100
  • installCappedCollection : capped collection install flag : default false
  • fsync : fsync flag : default false
  • safe : safe flag : default false
  • timeout : timeout miliseconds : default null i.e. MongoCursor::$timeout

Caped colection

  1. Set installCappedCollection true in main.php.
  2. Run application and loged.
  3. Remove installCappedCollection in main.php.


2011/08/01 ver 1.2

Add fsync, safe, timeout options

2011/07/09 ver 1.1

Add capped collection : Thank you joblo

2011/06/23 ver 1.0

First Release

Total 4 comments

#5688 report it
Joblo at 2011/11/01 06:22pm

I have integrated you extension in the directmongosuite

Hope this is ok for you and you will support updates there too.

#4456 report it
Joblo at 2011/07/10 05:12pm
Viewer component

As addon for this extension I have added a viewer component:


#4435 report it
aoyagikouhei at 2011/07/08 07:07pm
RE : Capped collection

Thanks for comment, joblo. I modified code and released ver1.1.

#4430 report it
Joblo at 2011/07/08 04:36am
Capped collection

Thanks for your extension. I'm working a lot with mongoDB and was waiting for this - did't had the time to implement for myself.

One remark:

MongoDB offers a high performance collection type for this purpose:

Capped collections

You have to specify a maximum size of the collection. Once the space is fully utilized, newly added objects will replace the oldest objects.

So I do as small change to your code to add this feature.

public $collectionSize = 10000;
  public $installCappedCollection = true; //set to false after first run
   * Initializes the route.
   * This method is invoked after the route is created by the route manager.
  public function init()
    $connection = new Mongo($this->connectionString);
    $dbName = $this->dbName;
    $collectionName = $this->collectionName;
      $connection->$dbName->createCollection($collectionName, true, $this->collectionSize); 
    $this->collection = $connection->$dbName->$collectionName;

But this collection cannot be used directly with Yii for caching, http-session ... because you cannot delete single records from a capped collection. You can only drop it.

Leave a comment

Please to leave your comment.

Create extension