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.

Winston 3 Console Transport removing whitespace

See original GitHub issue

I have come across this this while trying out winston 3.

OS: Macos 10.13.4 Terminal: iTerm2 or Terminal.app Winston: 3.0.0-rc5 Node: 8.11.1

I am using a custom formatter that is setting options[Symbol.from('message')] before returning it to winston. I am providing to that transport the following string (an example):

                                   \u001b[36m\u001b[4m*INFO   * ↳ \u001b[24m\u001b[39m     pid:   \u001b[33m13071\u001b[39m

But sometimes both newlines and initial whitespace are being ignored when writing to the console. This doesn’t seem to happen when running on linux.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nickdexcommented, Jun 23, 2018

Here’s what I’m experiencing; maybe its related?

When I don’t use uppercase method on info.level I get logs on console as expected

2018-06-24 00:03:47 [jarvis-server] info: App is running at http://localhost:3000 in development
2018-06-24 00:03:47 [jarvis-server] info:  Press CTRL-C to stop

2018-06-24 00:03:47 [jarvis-server] error: Db already exists

but when I use uppercase method

                                        : App is running at http://localhost:3000 in development
                                        :  Press CTRL-C to stop

                                         : Db already exists

Code (Typescript)

import * as winston from 'winston';

const logFormat = winston.format.printf(info => {
  // return `${info.timestamp} [${info.label}] ${info.level}: ${ info.message }`;
  return `${info.timestamp} [${info.label}] ${info.level.toUpperCase()}: ${
    info.message
  }`;
});

const logger = winston.createLogger({
  level: process.env.LOG_LEVEL,
  transports: [new winston.transports.File({ filename: 'app.log' })],
  format: winston.format.combine(
    winston.format.label({ label: 'jarvis-server' }),
    winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
    logFormat
  )
});

if (process.env.NODE_ENV !== 'production') {
  logger.add(
    new winston.transports.Console({
      format: winston.format.combine(
        winston.format.colorize(),
        winston.format.label({ label: 'jarvis-server' }),
        winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
        logFormat
      )
    })
  );
}

export default logger;
0reactions
Nokel81commented, May 28, 2018

I was developing on macos

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodejs winston - Logging with multiple arguments
Since Winston API doesn't work like console.log , therefore a workaround would be to create a wrapper function which utilizes util.format in ...
Read more >
How to use the winston.remove function in winston - Snyk
To help you get started, we've selected a few winston.remove examples, based on popular ways it is used in public projects.
Read more >
Winston Logger Filename Error Undefined - ADocLib
For one there's no way to disable console.log calls. used to send log messages to their destination is known as a transport and...
Read more >
kiS - River Thames Conditions - Environment Agency - GOV.UK
Pakistan air force pilots, Nacional 3 defensor 0 clausura 2011, Cryptsetup luksopen, ... Toms shoe sizing tiny, Degrassi season 14 frankie and winston?...
Read more >
Changelog - Cypress Documentation
Cypress has made several configuration option changes including renaming options, removing options, and only allowing some options within a specific testing ...
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