MongoDB Log Route.
Requirements ¶
Yii 1.1.8 or above
Usage ¶
Install ¶
Extract the release file under protected/extensions
In config/main.php:
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'ext.EMongoDbLogRoute',
'levels'=>'trace, info, error, warning',
'categories' => 'system.*',
),
),
),
Options ¶
- 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 ¶
- Set installCappedCollection true in main.php.
- Run application and loged.
- Remove installCappedCollection in main.php.
History ¶
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
User Contributed Notes 4
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() { parent::init(); $connection = new Mongo($this->connectionString); $dbName = $this->dbName; $collectionName = $this->collectionName; if($this->installCappedCollection) $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.
RE : Capped collection
Thanks for comment, joblo.
I modified code and released ver1.1.
Viewer component
As addon for this extension I have added a viewer component:
mongodblogviewer
directmongosuite
I have integrated you extension in the directmongosuite
Hope this is ok for you and you will support updates there too.
Leave a comment
If you have any questions, please ask in the forum instead.
Join the conversation to share a note.