winston

Node.js - logging / Use morgan and winston

一世执手 提交于 2019-11-28 15:07:33
we use morgan in order to log our express transformation: var morgan = require('morgan'); morgan('combined'); // a format string morgan(':remote-addr :method :url :uuid'); // a custom function morgan(function (req, res) { return req.method + ' ' + req.url + ' ' + req.uuid; }) Also, we use winston in order to log our other logging: var winston = require('winston'); var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ level: 'info' }), new (winston.transports.File)({ filename: '/var/log/log-file.log' }) ] }); Is there any way to combine the two loggers together?

Winston / Morgan logging avoiding duplicate entries

主宰稳场 提交于 2019-11-28 09:58:37
问题 I just implemented Winston Logging and it works as expected but i came accross a few issues which i cant find answer for. The way winston works as far as i can tell, the set log level and anything below as far as priority gets used, like on error it will also include info logs etc. Is there a way to create a specific log level lets call it HTTP or db where i only log http or db events to and they don't end up in the combined file or console ? 回答1: A better solution is to use a single logger

NodeJS Express - Global Unique Request Id

*爱你&永不变心* 提交于 2019-11-28 08:28:30
Is it possible to define a unique request Id that is included in each log statement without handing the logger to each method/function call? Technologies in use: NodeJS, Express, Winston Edited Finally, I have created a library that makes all the work. https://github.com/davicente/express-logger-unique-req-id It is a wrapper of Winston library, so you can use it the same way. Let me know if it helps you We had this same problem in several projects, and I couldn't finde any complete solution for this question. We are using same technologies (Node.js, Express.js and Winston for logs) I found a

Mock fs function with jest

China☆狼群 提交于 2019-11-28 04:04:33
问题 First of all, I'm new to es6 and jest . I have a Logger class for instantiate winston and I would like to test it. Here my code : const winston = require('winston'); const fs = require('fs'); const path = require('path'); const config = require('../config.json'); class Logger { constructor() { Logger.createLogDir(Logger.logDir); this.logger = winston.createLogger({ level: 'info', format: winston.format.json(), transports: [ new (winston.transports.Console)({ format: winston.format.combine(

NodeJS Express - Global Unique Request Id

江枫思渺然 提交于 2019-11-27 02:12:40
问题 Is it possible to define a unique request Id that is included in each log statement without handing the logger to each method/function call? Technologies in use: NodeJS, Express, Winston 回答1: Edited Finally, I have created a library that makes all the work. https://github.com/davicente/express-logger-unique-req-id It is a wrapper of Winston library, so you can use it the same way. Let me know if it helps you We had this same problem in several projects, and I couldn't finde any complete