Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
What are the allowed colors in Winston 3?

I am using winston 3 logger and I want to customize colors. I am using below code:

winston.addColors( {
    info: 'green',
    error: 'red',
    warn: 'yellow',
    debug: 'cyan'
});

When I use other colors like brown, pink or hex-codes like #2E6E3E etc., I am getting error:

.../node_modules/winston/lib/winston/logger.js:307
    throw ex;
    ^
TypeError: colors[Colorizer.allColors[lookup]] is not a function
    at Colorizer.colorize (.../node_modules/logform/colorize.js:73:49)

Is there a list of allowed colors in Winston? If so, please provide that list.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In addition to the predefined npm, syslog, and cli levels available in winston, you can also choose to define your own:

const myCustomLevels = {
  levels: {
    foo: 0,
    bar: 1,
    baz: 2,
    foobar: 3
  },
  colors: {
    foo: 'blue',
    bar: 'green',
    baz: 'yellow',
    foobar: 'red'
  }
};

const customLevelLogger = winston.createLogger({
  levels: myCustomLevels.levels
});

customLevelLogger.foobar('some foobar level-ed message');

Although there is slight repetition in this data structure, it enables simple encapsulation if you do not want to have colors. If you do wish to have colors, in addition to passing the levels to the Logger itself, you must make winston aware of them:

winston.addColors(myCustomLevels.colors);

This enables loggers using the colorize formatter to appropriately color and style the output of custom levels.

Additionally, you can also change background color and font style. For example,

baz: 'italic yellow',
foobar: 'bold red cyanBG'

Possible options are below.

  • Font styles: bold, dim, italic, underline, inverse, hidden, strikethrough.

  • Font foreground colors: black, red, green, yellow, blue, magenta,
    cyan, white, gray, grey.

  • Background colors: blackBG, redBG, greenBG, yellowBG, blueBG
    magentaBG, cyanBG, whiteBG

These are the only possible options for colors provided by winston. Please check the documentation for winston.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda