Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!