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
31
votes
6 answers

How to set log level in Winston/Node.js

I am using Winston logging with my Node.js app and have defined a file transport. Throughout my code, I log using either logger.error, logger.warn, or logger.info. My question is, how do I specify the log level? Is there a config file and value that…
Silent User
  • 2,657
  • 7
  • 29
  • 36
29
votes
2 answers

How do I set a peer dependency optional?

I'm developing a module A. The user can, optionally, inject a Winston logger to my module, therefore winston is its peer dependency. Whenever I install my module A in another module where I don't want to log stuff (therefore I don't include Winston)…
John Smith
  • 3,863
  • 3
  • 24
  • 42
29
votes
7 answers

Winston logging object

I use Winston for my backend logging I cannot log the object without using JSON.stringify which is annoying logger.debug(`Register ${JSON.stringify(req.body)}`) const logger: Logger = createLogger({ // change level if in dev environment versus…
coinhndp
  • 2,281
  • 9
  • 33
  • 64
27
votes
8 answers

Much needed: well-highlighted JSON log viewer

Using winston for node.js logging, I get json log files. A log file in this vein is simply a sequence of (newline delimited) json objects. This is great for log querying and treating logs as first-class data! However, both Sublime and gedit (at…
matanster
  • 15,072
  • 19
  • 88
  • 167
26
votes
2 answers

Mock fs function with jest

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 =…
Oyabi
  • 824
  • 3
  • 10
  • 27
26
votes
5 answers

How to flush winston logs?

I want to flush the winston logger before process.exit. process.on('uncaughtException', function(err){ logger.error('Fatal uncaught exception crashed cluster', err); logger.flush(function(){ // <- process.exit(1); }); }); Is…
bevacqua
  • 47,502
  • 56
  • 171
  • 285
26
votes
5 answers

I want to display the file Name in the log statement

For every logger statement with any level, I need to display the file name from where the log statement executed, below is the illustration I given below: Example : Below is the line executed from JobWork.js logger.info("getInCompleteJobs in job…
Dexter
  • 12,172
  • 9
  • 27
  • 30
25
votes
3 answers

winston: Attempt to write logs with no transports - using default logger

I followed a tutorial to set up winston (2.x) default logger in my express app. When updating to the current version of winston (3.0.0) I have a problem with adding the transports. I have followed the latest docs but still I get the notice in…
tertek
  • 890
  • 1
  • 10
  • 20
24
votes
3 answers

NodeJS Express - Global Unique Request Id

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
smokedice
  • 900
  • 2
  • 10
  • 25
22
votes
7 answers

Winston 3.0 colorize whole output on console

I am developing a Node.js application, using babel-cli as an ES6 transpiler and I am using Winston 3.0 as my logging service. Question: I want the whole output of the messages from the winston logger to appear in color, not just the label and the…
trashtatur
  • 381
  • 1
  • 3
  • 12
21
votes
3 answers

NestJS Logging into File, Database, etc using either default logger or npm like winston

NestJS implemented with default logger. It send the output to console. May I know, How to configure the default logger to send the output to file, database. In addition, if I want to use Winston in NestJS, how to use/inject/extend with various…
user3497702
  • 695
  • 3
  • 12
  • 25
21
votes
5 answers

Multiple log files with Winston?

We'd like to use Winston for our logging in Node.js. But, we can't figure out how to have two log files: one for just errors, and one for everything else. Doing this the naive way doesn't work, however: adding multiple winston.transports.File…
Domenic
  • 110,262
  • 41
  • 219
  • 271
19
votes
1 answer

NodeJS/Forever archive logs

I am using forever to run my node application. When I start forever I specify where to write the logs. I also specify to append to the log. Problem here is that my log is going to grow out of control over the course of months. Is there any way to…
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
18
votes
7 answers

can I change the color of log data in winston?

I happened to use bunyan to log the the data . I wanted the logs be printed with appropriate colors like errors in red , debug yellow .. etc; unfortunately I couldn't find anyways to do that . And now I would like to know if its possible with…
srujana
  • 501
  • 2
  • 6
  • 13
18
votes
1 answer

Using Winston in typescript

I can't figure how to use the logging module Winston in typescript. I have an error when I try to set the logger level, and another one when I try to log an error: import * as logger from "winston"; logger.level = 'debug'; // [ts] Cannot assign to…
Christophe Le Besnerais
  • 3,895
  • 3
  • 24
  • 44
1
2
3
62 63