Questions tagged [winston]

A multi-transport async logging library for node.js.

Winston is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs. Each instance of a winston logger can have multiple transports configured at different levels. For example, one may want error logs to be stored in a persistent remote location (like a database), but all logs output to the console or a local file.

There also seemed to be a lot of logging libraries out there that coupled their implementation of logging (i.e. how the logs are stored / indexed) to the API that they exposed to the programmer. This library aims to decouple those parts of the process to make it more flexible and extensible.

935 questions
128
votes
9 answers

Node.js - How to add timestamp to logs using Winston library?

I want to add timestamp to logs. What is the best way to achieve this? Thanks.
kolrie
  • 12,562
  • 14
  • 64
  • 98
121
votes
7 answers

Node.js - logging / Use morgan and winston

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 + ' '…
Or Smith
  • 3,556
  • 13
  • 42
  • 69
73
votes
11 answers

How to use Winston in several modules?

I have several modules - let's say server.js, module1.js,...,moduleN.js. I would like define the log file in my server.js: winston.add(winston.transports.File, { filename: 'mylogfile.log' }); and then use it in all my modules. What is the best way…
Alexander
  • 7,484
  • 4
  • 51
  • 65
59
votes
7 answers

How to Log Full Stack Trace with Winston 3?

My logger is set up like: const myFormat = printf(info => { return `${info.timestamp}: ${info.level}: ${info.message}: ${info.err}`; }); const logger = winston.createLogger({ level: "info", format: combine(timestamp(), myFormat), …
Anthony Xie
  • 599
  • 1
  • 5
  • 6
56
votes
1 answer

TypeError: winston.Logger is not a constructor with winston and morgan

I tried with Winston for logger. I used in one project their It's working well when I copy paste the code from their to the current existing project than I face an issue like TypeError: winston.Logger is not a constructor let logger = new…
Gunjan Patel
  • 2,342
  • 4
  • 24
  • 45
56
votes
1 answer

Winston Logger - NodeJs Debug console logs not showing in VSCode

I'm using VSCode debugger and winston logger for NodeJS, but can't see output from application unless I specify external terminal like this: "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", …
Josip
  • 1,061
  • 1
  • 9
  • 10
51
votes
9 answers

Disable winston logging when running unit tests?

Can Winston logging be selectively disabled when executing unit tests of a node module? Ideally, I'd like to have logging for informational and debug purposes when the application is running, but be suppressed as to not clutter the presentation…
Sk606
  • 2,182
  • 1
  • 21
  • 14
40
votes
6 answers

Logging all requests in Node.js/Express

In my small node.js application, using express, I wanted to log all the incoming requests, so I ended up with this: var bodyParser = require('body-parser'); module.exports = function(app) { app.set("port", 50001); app.set("json spaces", 2); …
Julien
  • 508
  • 2
  • 6
  • 13
39
votes
12 answers

How would a human read a json winston log file?

It seems nice for API's, scripts and what not. But reading a winston json stack trace is very hard with a text editor. E.g. {"level":"info","message":"starting","timestamp":"2014-05-14T15:45:44.334Z"} {"date":"Wed May 14 2014 08:45:45 GMT-0700…
ubershmekel
  • 11,864
  • 10
  • 72
  • 89
38
votes
8 answers

How to log JavaScript objects and arrays in winston as console.log does?

I was looking at top Node logging systems: npmlog, log4js, bunyan and winston and decided to use winston for having the most npm monthly downloads. What I want to set up is custom logger which I will be able to use on development environment with…
Tommz
  • 3,393
  • 7
  • 32
  • 44
37
votes
5 answers

Winston not displaying error details

I am using winston for logging and most of the time it works well, but when there is an exception, it just does not print any details. Here is my code for configuring winston: // Create logger const logger = winston.createLogger() // Create…
Balázs Vincze
  • 3,550
  • 5
  • 29
  • 60
37
votes
7 answers

Winston doesn't pretty-print to console

I'm trying to get Winston to pretty print to the console, so I stuck this in a file and ran it with node: var winston = require('winston'); winston.cli(); winston.data({ a: "test", of: "many", properties: { like: "this" …
JoBu1324
  • 7,751
  • 6
  • 44
  • 61
35
votes
2 answers

Winston : understanding logging levels

Reading and fiddling with Winston, I'm puzzled as to why the logging levels are ordered as they are and why the transports behave in the way they do (well, at least the Console one). I'd appreciate if someone could, perhaps even thoroughly, with…
Yanick Rochon
  • 51,409
  • 25
  • 133
  • 214
34
votes
5 answers

How do I change my node winston JSON output to be single line

When I create a nodejs winston console logger and set json:true, it always output JSON logs in multiline format. If I pipe these to a file and try to grep that file, my grep hits only include part of the log line. I want winston to output my log…
zayquan
  • 7,544
  • 2
  • 30
  • 39
33
votes
4 answers

winston:how to change timestamp format

I am using winston to add log details in node.js, i used the following procedure to add the logs var winston = require('winston'); winston.remove(winston.transports.Console); winston.add(winston.transports.Console,…
Amanda G
  • 1,931
  • 10
  • 33
  • 43
1
2 3
62 63