Added replica sets support
This commit is contained in:
Родитель
f098a0f09d
Коммит
59e29f34e7
|
@ -38,10 +38,14 @@ The MongoDB transport takes the following options. 'db' is required:
|
|||
* __storeHost:__ Boolean indicating if you want to store machine hostname in logs entry, if set to true it populates MongoDB entry with 'hostname' field, which stores os.hostname() value.
|
||||
* __ssl:__ Boolean indicating if you want to use SSL connections or not.
|
||||
* __authDb:__ Authentication database object.
|
||||
* __dbUri:__ Alternative way of specifying database connection data. Note, that __replica sets are unsupported__. If you specify a replica set or multiple databases, will be used first database connection data.
|
||||
* __replSet:__ Replica set name.
|
||||
* __hosts:__ Array of replica set hosts (in format ```{host: 'string', port: 'number'}```)
|
||||
* __dbUri:__ Alternative way of specifying database connection data. Supported specifying database, host, port, username, password and replica sets.
|
||||
|
||||
*Notice:* __db__ is required. You should specify it directly or in __dbUri__.
|
||||
|
||||
*ReplicaSet Notice:* If you use replica set, __db__, __replSet__ and __hosts__ are required. They may also be specified in __dbUri__.
|
||||
|
||||
*Metadata:* Logged as a native JSON object.
|
||||
|
||||
## Querying and streaming logs
|
||||
|
|
|
@ -26,7 +26,10 @@ var MongoDB = exports.MongoDB = function (options) {
|
|||
if (options.dbUri) {
|
||||
var uriOptions = muri(options.dbUri);
|
||||
options.db = uriOptions.db;
|
||||
if (uriOptions.hosts && uriOptions.hosts[0]) {
|
||||
if (uriOptions.options.replicaSet) {
|
||||
options.replSet = uriOptions.options.replicaSet;
|
||||
options.hosts = uriOptions.hosts;
|
||||
} else if (uriOptions.hosts && uriOptions.hosts[0]) {
|
||||
options.host = uriOptions.hosts[0].host;
|
||||
options.port = uriOptions.hosts[0].port;
|
||||
}
|
||||
|
@ -46,6 +49,8 @@ var MongoDB = exports.MongoDB = function (options) {
|
|||
this.db = options.db;
|
||||
this.host = options.host || 'localhost';
|
||||
this.port = options.port || mongodb.Connection.DEFAULT_PORT;
|
||||
this.replSet = options.replSet || null;
|
||||
this.hosts = options.hosts || null;
|
||||
this.collection = options.collection || 'logs';
|
||||
this.safe = options.safe || true;
|
||||
this.level = options.level || 'info';
|
||||
|
@ -73,10 +78,22 @@ var MongoDB = exports.MongoDB = function (options) {
|
|||
this.timeoutId = null;
|
||||
this.pending = [];
|
||||
|
||||
this.server = new mongodb.Server(this.host, this.port, {
|
||||
ssl: this.ssl
|
||||
});
|
||||
|
||||
if (this.replSet) {
|
||||
var servers = [];
|
||||
this.hosts.forEach(function(host) {
|
||||
servers.push(new mongodb.Server(host.host || 'localhost',
|
||||
host.port || mongodb.Connection.DEFAULT_PORT));
|
||||
});
|
||||
this.server = new mongodb.ReplSet(servers, {
|
||||
rs_name: this.replSet,
|
||||
ssl: this.ssl
|
||||
});
|
||||
} else {
|
||||
this.server = new mongodb.Server(this.host, this.port, {
|
||||
ssl: this.ssl
|
||||
});
|
||||
}
|
||||
|
||||
this.client = new mongodb.MongoClient(this.server, {
|
||||
native_parser: this.nativeParser,
|
||||
safe: this.safe
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "winston-mongodb",
|
||||
"version": "0.4.5",
|
||||
"version": "0.4.6",
|
||||
"description": "A MongoDB transport for winston",
|
||||
"author": "Charlie Robbins <charlie.robbins@gmail.com>",
|
||||
"contributors": [
|
||||
|
|
|
@ -15,8 +15,30 @@ var path = require('path'),
|
|||
MongoDB = require('../lib/winston-mongodb').MongoDB;
|
||||
|
||||
vows.describe('winston-mongodb').addBatch({
|
||||
"An instance of the MongoDB Transport": transport(MongoDB, {
|
||||
'An instance of the MongoDB Transport': transport(MongoDB, {
|
||||
db: 'winston',
|
||||
keepAlive: 1000
|
||||
})
|
||||
}).export(module);
|
||||
|
||||
|
||||
//vows.describe('winston-mongodb').addBatch({
|
||||
// 'Test MongoDB with replica set': transport(MongoDB, {
|
||||
// db: 'winston',
|
||||
// keepAlive: 1000,
|
||||
// replSet: 'rs0',
|
||||
// hosts: [
|
||||
// {port: 27018},
|
||||
// {port: 27019},
|
||||
// {port: 27020}
|
||||
// ]
|
||||
// })
|
||||
//}).export(module);
|
||||
|
||||
|
||||
//vows.describe('winston-mongodb').addBatch({
|
||||
// 'Test MongoDB with replica set': transport(MongoDB, {
|
||||
// keepAlive: 1000,
|
||||
// dbUri: 'mongodb://localhost:27018,localhost:27019,localhost:27020/winston?replicaSet=rs0'
|
||||
// })
|
||||
//}).export(module);
|
||||
|
|
Загрузка…
Ссылка в новой задаче