Skip to content

Commit bf8a1c0

Browse files
Version 1.0.0 released:
* migrated to mongodb 2.x driver; * changed configuration format to MongoDB uri string; * added support of passing preconnected db object instead of MongoDB uri string; * added support of passing MongoDB connection parameters in options property; * added support of replica sets through new options and db properties; * migrated to [Semantic Versioning](http://semver.org/) in package versions names; * changed comments format to JSDoc; * removed authDb from configuration options (it's impossible to handle all possible authorization scenarios, so, if you need to use complicated authorization pattern, please provide winston-mongodb with already prepared db connection object).
1 parent 15dbb82 commit bf8a1c0

8 files changed

+380
-530
lines changed

README.md

+33-42
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
A MongoDB transport for [winston][0].
55

6+
Current version supports only mongodb driver version 2.x. If you want to use
7+
winston-mongodb with mongodb version 1.4.x use winston-mongodb <1.x.
8+
69
## Motivation
710
`tldr;?`: To break the [winston][0] codebase into small modules that work
811
together.
@@ -16,10 +19,10 @@ and a File is overkill.
1619
``` js
1720
var winston = require('winston');
1821

19-
//
20-
// Requiring `winston-mongodb` will expose
21-
// `winston.transports.MongoDB`
22-
//
22+
/**
23+
* Requiring `winston-mongodb` will expose
24+
* `winston.transports.MongoDB`
25+
*/
2326
require('winston-mongodb').MongoDB;
2427

2528
winston.add(winston.transports.MongoDB, options);
@@ -31,43 +34,25 @@ The MongoDB transport takes the following options. 'db' is required:
3134
'info'.
3235
* __silent:__ Boolean flag indicating whether to suppress output, defaults to
3336
false.
34-
35-
* __db:__ The name of the database you want to log to.
37+
* __db:__ MongoDB connection uri or preconnected db object.
38+
* __options:__ MongoDB connection parameters (optional, defaults to
39+
`{db: {native_parser: true}, server: {poolSize: 2, socketOptions: {autoReconnect: true}}}`).
3640
* __collection__: The name of the collection you want to store log messages in,
3741
defaults to 'logs'.
38-
* __safe:__ Boolean indicating if you want eventual consistency on your log
39-
messages, if set to true it requires an extra round trip to the server to ensure the write was committed, defaults to true.
40-
* __nativeParser:__ Boolean indicating if you want the driver to use native
41-
parser feature or not.
42-
* __host:__ The host running MongoDB, defaults to localhost.
43-
* __port:__ The port on the host that MongoDB is running on, defaults to
44-
MongoDB's default port.
45-
* __username:__ The username to use when logging into MongoDB.
46-
* __password:__ The password to use when logging into MongoDB. If you don't
47-
supply a username and password it will not use MongoDB authentication.
48-
* __errorTimeout:__ Reconnect timeout upon connection error from Mongo,
49-
defaults to 10 seconds (10000).
50-
* __timeout:__ Timeout for keeping idle connection to Mongo alive, defaults to
51-
10 seconds (10000).
5242
* __storeHost:__ Boolean indicating if you want to store machine hostname in
5343
logs entry, if set to true it populates MongoDB entry with 'hostname' field,
5444
which stores os.hostname() value.
45+
* __username:__ The username to use when logging into MongoDB.
46+
* __password:__ The password to use when logging into MongoDB. If you don't
47+
supply a username and password it will not use MongoDB authentication.
5548
* __label:__ Label stored with entry object if defined.
56-
* __ssl:__ Boolean indicating if you want to use SSL connections or not.
57-
* __authDb:__ Authentication database object.
58-
* __replSet:__ Replica set name.
59-
* __hosts:__ Array of replica set hosts (in format
60-
`{host: 'string', port: 'number'}`)
61-
* __dbUri:__ Alternative way of specifying database connection data. Supported
62-
specifying database, host, port, username, password and replica sets.
63-
* __name:__ Transport instance identifier. Useful if you need to create multiple MongoDB transports.
49+
* __name:__ Transport instance identifier. Useful if you need to create multiple
50+
MongoDB transports.
51+
* __capped:__ In case this property is true, winston-mongodb will try to create
52+
new log collection as capped, defaults to false.
53+
* __cappedSize:__ Size of logs capped collection in bytes, defaults to 10000000.
6454

65-
*Notice:* __db__ is required. You should specify it directly or in __dbUri__.
66-
67-
*ReplicaSet Notice:* If you use replica set, __db__, __replSet__ and __hosts__
68-
are required. They may also be specified in __dbUri__.
69-
70-
*Metadata:* Logged as a native JSON object in meta property.
55+
*Metadata:* Logged as a native JSON object in 'meta' property.
7156

7257
*Logging unhandled exceptions:* For logging unhandled exceptions specify
7358
winston-mongodb as `handleExceptions` logger according to winston documentation.
@@ -82,21 +67,27 @@ settled by mongodb, defaults to `false`.
8267

8368
## Installation
8469

85-
### Installing npm (node package manager)
86-
87-
``` bash
88-
$ curl http://npmjs.org/install.sh | sh
89-
```
90-
91-
### Installing winston-mongodb
92-
9370
``` bash
9471
$ npm install winston
9572
$ npm install winston-mongodb
9673
```
9774

9875
## Changelog
9976

77+
### Brief 1.0.0 changelog
78+
79+
* migrated to mongodb 2.x driver;
80+
* changed configuration format to MongoDB uri string;
81+
* added support of passing preconnected db object instead of MongoDB uri string;
82+
* added support of passing MongoDB connection parameters in options property;
83+
* added support of replica sets through new options and db properties;
84+
* migrated to [Semantic Versioning](http://semver.org/) in package versions names;
85+
* changed comments format to JSDoc;
86+
* removed authDb from configuration options (it's impossible to handle all
87+
possible authorization scenarios, so, if you need to use complicated
88+
authorization pattern, please provide winston-mongodb with already prepared
89+
db connection object).
90+
10091
### Brief 0.5 changelog
10192

10293
* metadata is now stored into separate property `meta`; so, there is no risk

lib/helpers.js

+27-30
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
/*
2-
* mongodb.js: Transport for outputting to a MongoDB database
3-
*
4-
* (C) 2014 Yurij Mikhalevich
5-
* MIT LICENCE
6-
*
1+
/**
2+
* @module helpers
3+
* @fileoverview Helpers for winston-mongodb
4+
* @license MIT
5+
* @author [email protected] (Yurij Mikhalevich)
76
*/
87
var common = require('winston/lib/winston/common');
98

109

11-
//
12-
// ### function prepareMetaData (meta)
13-
// #### @meta {*} Metadata
14-
// Prepares metadata to store into database.
15-
//
16-
exports.prepareMetaData = function (meta) {
10+
/**
11+
* Prepares metadata to store into database.
12+
* @param {*} meta Metadata
13+
* @return {*}
14+
*/
15+
exports.prepareMetaData = function(meta) {
1716
if (typeof meta === 'object' && meta !== null) {
1817
makeObjectNonCircular(meta);
1918
cleanFieldNames(meta);
@@ -31,11 +30,10 @@ exports.prepareMetaData = function (meta) {
3130
};
3231

3332

34-
//
35-
// ### function cleanFieldNames (object)
36-
// #### @object {Object} Object to clean
37-
// Removes unexpected characters from metadata field names.
38-
//
33+
/**
34+
* Removes unexpected characters from metadata field names.
35+
* @param {Object} object Object to clean
36+
*/
3937
function cleanFieldNames(object) {
4038
for (var field in object) {
4139
if (!object.hasOwnProperty(field)) {
@@ -59,33 +57,32 @@ function cleanFieldNames(object) {
5957
}
6058

6159

62-
//
63-
// ### function makeObjectNonCircular (node, [parents])
64-
// #### @node {Object} Current object or its leaf
65-
// #### @parents {array} Object's parents
66-
// Cleans object from circular references, replaces them with string
67-
// "[Circular]"
68-
//
69-
function makeObjectNonCircular(node, parents) {
70-
parents = parents || [];
60+
/**
61+
* Cleans object from circular references, replaces them with string
62+
* "[Circular]"
63+
* @param {Object} node Current object or its leaf
64+
* @param {Array=} opt_parents Object's parents
65+
*/
66+
function makeObjectNonCircular(node, opt_parents) {
67+
opt_parents = opt_parents || [];
7168

7269
var keys = Object.keys(node);
7370
var i;
7471
var value;
7572

76-
parents.push(node); // add self to current path
73+
opt_parents.push(node); // add self to current path
7774
for (i = keys.length - 1; i >= 0; --i) {
7875
value = node[keys[i]];
7976
if (value && typeof value === 'object') {
80-
if (parents.indexOf(value) === -1) {
77+
if (opt_parents.indexOf(value) === -1) {
8178
// check child nodes
82-
arguments.callee(value, parents);
79+
arguments.callee(value, opt_parents);
8380
} else {
8481
// circularity detected!
8582
node[keys[i]] = '[Circular]';
8683
}
8784
}
8885
}
8986

90-
parents.pop();
87+
opt_parents.pop();
9188
}

0 commit comments

Comments
 (0)