3
3
4
4
A MongoDB transport for [ winston] [ 0 ] .
5
5
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
+
6
9
## Motivation
7
10
` tldr;? ` : To break the [ winston] [ 0 ] codebase into small modules that work
8
11
together.
@@ -16,10 +19,10 @@ and a File is overkill.
16
19
``` js
17
20
var winston = require (' winston' );
18
21
19
- //
20
- // Requiring `winston-mongodb` will expose
21
- // `winston.transports.MongoDB`
22
- / /
22
+ /**
23
+ * Requiring `winston-mongodb` will expose
24
+ * `winston.transports.MongoDB`
25
+ * /
23
26
require (' winston-mongodb' ).MongoDB ;
24
27
25
28
winston .add (winston .transports .MongoDB , options);
@@ -31,43 +34,25 @@ The MongoDB transport takes the following options. 'db' is required:
31
34
'info'.
32
35
* __ silent:__ Boolean flag indicating whether to suppress output, defaults to
33
36
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}}} ` ).
36
40
* __ collection__ : The name of the collection you want to store log messages in,
37
41
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).
52
42
* __ storeHost:__ Boolean indicating if you want to store machine hostname in
53
43
logs entry, if set to true it populates MongoDB entry with 'hostname' field,
54
44
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.
55
48
* __ 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.
64
54
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.
71
56
72
57
* Logging unhandled exceptions:* For logging unhandled exceptions specify
73
58
winston-mongodb as ` handleExceptions ` logger according to winston documentation.
@@ -82,21 +67,27 @@ settled by mongodb, defaults to `false`.
82
67
83
68
## Installation
84
69
85
- ### Installing npm (node package manager)
86
-
87
- ``` bash
88
- $ curl http://npmjs.org/install.sh | sh
89
- ```
90
-
91
- ### Installing winston-mongodb
92
-
93
70
``` bash
94
71
$ npm install winston
95
72
$ npm install winston-mongodb
96
73
```
97
74
98
75
## Changelog
99
76
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
+
100
91
### Brief 0.5 changelog
101
92
102
93
* metadata is now stored into separate property ` meta ` ; so, there is no risk
0 commit comments