UNPKG

3.43 kBMarkdownView Raw
1# winston
2[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/indexzero/winston-mongodb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
3
4A MongoDB transport for [winston][0].
5
6Current version supports only mongodb driver version 2.x. If you want to use
7winston-mongodb with mongodb version 1.4.x use winston-mongodb <1.x.
8
9## Motivation
10`tldr;?`: To break the [winston][0] codebase into small modules that work
11together.
12
13The [winston][0] codebase has been growing significantly with contributions and
14other logging transports. This is **awesome**. However, taking a ton of
15additional dependencies just to do something simple like logging to the Console
16and a File is overkill.
17
18## Usage
19``` js
20 var winston = require('winston');
21
22 /**
23 * Requiring `winston-mongodb` will expose
24 * `winston.transports.MongoDB`
25 */
26 require('winston-mongodb');
27
28 winston.add(winston.transports.MongoDB, options);
29```
30
31The MongoDB transport takes the following options. 'db' is required:
32
33* __level:__ Level of messages that this transport should log, defaults to
34'info'.
35* __silent:__ Boolean flag indicating whether to suppress output, defaults to
36false.
37* __db:__ MongoDB connection uri, pre-connected db object or promise object
38which will be resolved with pre-connected db object.
39* __options:__ MongoDB connection parameters (optional, defaults to
40`{poolSize: 2, autoReconnect: true}`).
41* __collection__: The name of the collection you want to store log messages in,
42defaults to 'log'.
43* __storeHost:__ Boolean indicating if you want to store machine hostname in
44logs entry, if set to true it populates MongoDB entry with 'hostname' field,
45which stores os.hostname() value.
46* __label:__ Label stored with entry object if defined.
47* __name:__ Transport instance identifier. Useful if you need to create multiple
48MongoDB transports.
49* __capped:__ In case this property is true, winston-mongodb will try to create
50new log collection as capped, defaults to false.
51* __cappedSize:__ Size of logs capped collection in bytes, defaults to 10000000.
52* __cappedMax:__ Size of logs capped collection in number of documents.
53* __tryReconnect:__ Will try to reconnect to the database in case of fail during
54initialization. Works only if __db__ is a string. Defaults to false.
55* __decolorize:__ Will remove color attributes from the log entry message,
56defaults to false.
57* __expireAfterSeconds:__ Seconds before the entry is removed. Works only if __capped__ is not set.
58
59*Metadata:* Logged as a native JSON object in 'meta' property.
60
61*Logging unhandled exceptions:* For logging unhandled exceptions specify
62winston-mongodb as `handleExceptions` logger according to winston documentation.
63
64## Querying and streaming logs
65
66Besides supporting the main options from winston, this transport supports the
67following extra options:
68
69* __includeIds:__ Whether the returned logs should include the `_id` attribute
70settled by mongodb, defaults to `false`.
71
72## Installation
73
74``` bash
75 $ npm install winston
76 $ npm install winston-mongodb
77```
78
79## [Changelog](https://github.com/winstonjs/winston-mongodb/releases)
80
81#### Author: [Charlie Robbins](http://blog.nodejitsu.com)
82#### Contributors: [Yurij Mikhalevich](https://github.com/39dotyt), [Kendrick Taylor](https://github.com/sktaylor), [Yosef Dinerstein](https://github.com/yosefd), [Steve Dalby](https://github.com/stevedalby)
83
84[0]: https://github.com/flatiron/winston
85
\No newline at end of file