UNPKG

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