最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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(),
    ),
  });
}
发布评论

评论列表(0)

  1. 暂无评论