Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda