question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Silent option not working with winston.loggers.add configuration

See original GitHub issue

Please tell us about your environment:

  • winston version? 3.0.0-rc4
  • node -v outputs: 8.4.0
  • Operating System? MacOS
  • Language? ES6/7

What is the problem?

silent: true - option not working as expected for multiple logger use. I have a ‘winston.js’ file with a logger configuration I use on multiple files. winston.js

winston.loggers.add('customLogger', { 
  console: {
    level: 'info',
    label: 'info,
  },
  transports: [
    new winston.transports.Console({
      silent: true
    }),
  ],
});

I then import the logger app.js

const winston = require('winston');
const logger = winston.loggers.get('customLogger');

logger.info('message');

The logs are not suppressed.

If I use createLogger in the app.js with the same configuration it works as expected. Can we get the silent option to work for multiple loggers use? Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
davelnewtoncommented, Apr 4, 2019

FWIW, I had the same issue using winston.loggers.add and retrieving them later. The loggers existed, e.g., calling get on the named logger returned the logger, but it had an empty transports array, despite having been created with a transports array in the add call.’

"winston": "^3.2.1"

This is an Electron (via electron-forge) app, Babel 6.24, etc. if that matters.

3reactions
EvanSchaltoncommented, Jan 24, 2021

FWIW I think this is still an issue: "winston": "^3.3.3"

my setup file looks like this:

import winston, {format} from 'winston';
const { combine, timestamp, json } = format;

const transports = {
  console: new winston.transports.Console({ level: 'warn', silent: true }),
  file: new winston.transports.File({ filename: './stdout.log', level: 'info' }),
  verbose: new winston.transports.File({ filename: './verbose-stdout.log', level: 'debug' })
};

winston.loggers.add('logger', {
  format: combine(
    timestamp(),
    json()
  ),
  transports: [transports.console, transports.file, transports.verbose]
})

my application files try to import like this: import { loggers } from 'winston' const logger = loggers.get('logger')

a log like this: logger.debug("test")

results in this: console.error [winston] Attempt to write logs with no transports ...

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Disable winston logging when running unit tests?
Winston transports have a silent property that you can set, which is probably a little nicer than removing the entire transport. I add...
Read more >
How to use the winston.createLogger function in winston - Snyk
To help you get started, we've selected a few winston.createLogger examples, based on popular ways it is used in public projects.
Read more >
Complete Winston Logger Guide With Hands-on Examples
With Winston, you can change your code in a single place and customize the format of your logs (e.g., logging in JSON format,...
Read more >
winston - npm
Start using winston in your project by running `npm i winston`. ... The recommended way to use winston is to create your own...
Read more >
A Guide Into Logging in Node.js using Winston - Bird Eats Bug
This can lead to performance issues when logging a large amount of data, as such calls can block the ... Setting up the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found