Difference between revisions of "Error Logging in Node"
From Logic Wiki
(Created page with "Category:Node.js == Installation == npm i winston == Setup == const winston = require('winston'); ... winston.add(winston.transports.File, {filename:'logfile.log'}) =...") |
|||
| Line 1: | Line 1: | ||
[[Category:Node.js]] | [[Category:Node.js]] | ||
| + | [[Category:MongoDb]] | ||
| + | |||
== Installation == | == Installation == | ||
Revision as of 12:02, 8 November 2018
Contents
Installation
npm i winston
Setup
const winston = require('winston');
...
winston.add(winston.transports.File, {filename:'logfile.log'})
Usage
winston.log('error', err.message);
or
winston.error(err.message, error); // error // warn // info // verbose // debug // silly
Logging to MongoDb
npm i winston-mongodb@3.0.0
require('winston-mongodb');
winston.add(winston.transports.MongoDB, { db: 'mongodb://localhost/somedb' });
To set only the errors to go to db
winston.add(winston.transports.MongoDB, { db: 'mongodb://localhost/somedb', level:'error' });
if we give the parameter as info error, warn and info will be logged.