最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Winston not logging debug levels in node.js - Stack Overflow

matteradmin8PV0评论

I am not running this on VS Code, just a normal terminal.

When I pass an object with different levels to winston they are all output as expected - except debug

import { Logger, format, createLogger, transports } from "winston";

export const exampleLogger = (): Logger => {
  return createLogger({
    transports: [new transports.Console()],
    format: formatbine(
      format((info) => {
        info.level = info.level.toUpperCase();
        return info;
      })(),
      format.json(),
    ),
  });
}
import { exampleLogger } from './example'

const logger = exampleLogger();

const infoExample = {
  timestamp: '2021-06-25T07:06:03.901Z',
  level: 'info',
  message: 'this works fine'
}
logger.log(infoExample)

const debugExample = {
  timestamp: '2021-06-25T07:06:03.901Z',
  level: 'debug',
  message: 'this outputs nothing'
}
logger.log(debugExample)

const errorExample = {
  timestamp: '2021-06-25T07:06:03.901Z',
  level: 'error',
  message: 'this works fine'
}
logger.log(errorExample)

Execution

$ npx ts-node test.ts
{"timestamp":"2021-06-25T07:06:03.901Z","level":"INFO","message":"this works fine"}
{"timestamp":"2021-06-25T07:06:03.901Z","level":"ERROR","message":"this works fine"}

I am not running this on VS Code, just a normal terminal.

When I pass an object with different levels to winston they are all output as expected - except debug

import { Logger, format, createLogger, transports } from "winston";

export const exampleLogger = (): Logger => {
  return createLogger({
    transports: [new transports.Console()],
    format: format.bine(
      format((info) => {
        info.level = info.level.toUpperCase();
        return info;
      })(),
      format.json(),
    ),
  });
}
import { exampleLogger } from './example'

const logger = exampleLogger();

const infoExample = {
  timestamp: '2021-06-25T07:06:03.901Z',
  level: 'info',
  message: 'this works fine'
}
logger.log(infoExample)

const debugExample = {
  timestamp: '2021-06-25T07:06:03.901Z',
  level: 'debug',
  message: 'this outputs nothing'
}
logger.log(debugExample)

const errorExample = {
  timestamp: '2021-06-25T07:06:03.901Z',
  level: 'error',
  message: 'this works fine'
}
logger.log(errorExample)

Execution

$ npx ts-node test.ts
{"timestamp":"2021-06-25T07:06:03.901Z","level":"INFO","message":"this works fine"}
{"timestamp":"2021-06-25T07:06:03.901Z","level":"ERROR","message":"this works fine"}
Share Improve this question asked Jun 25, 2021 at 7:25 myolmyol 10k24 gold badges97 silver badges158 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Ok, looks like I misunderstood the documentation about default logging levels. As stated in this issue, I need to tell winston that it should output certain log levels

import { Logger, format, createLogger, transports } from "winston";

export const exampleLogger = (): Logger => {
  return createLogger({
    transports: [new transports.Console({ level: 'debug' })],
    format: format.bine(
      format((info) => {
        info.level = info.level.toUpperCase();
        return info;
      })(),
      format.json(),
    ),
  });
}
Post a comment

comment list (0)

  1. No comments so far