winstonjs / logform

An mutable object format designed for chaining & objectMode streams
MIT License
250 stars 97 forks source link

if (!Array.isArray(Colorizer.allColors[lookup])) { #86

Open openainext opened 5 years ago

openainext commented 5 years ago
const { format } = require('logform');

const alignedWithColorsAndTime = format.combine(
  format.colorize(),
  format.timestamp(),
  format.align(),
  format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
);

const info = alignedWithColorsAndTime.transform({
  level: 'info',
  message: 'What time is the testing at?'
});

console.log(info);

error if (!Array.isArray(Colorizer.allColors[lookup])) { ^

TypeError: Cannot read property 'undefined' of undefined

akapps commented 2 years ago

For the record, the object passed to a format.transform method must hold certain metadata for some formatters to work properly - for instance, the colorizer requires that the original level property has been "secured" in a Symbol:

const { LEVEL } = require('triple-beam');

const info = alignedWithColorsAndTime.transform({
  level: 'info',
  message: 'What time is the testing at?',
  [LEVEL]: 'info'
});

winston adds such metadata in its Logger.log method for instance: see here.

TomlDev commented 2 years ago

I had to upgrade winston from 3.1.0 to 3.8.1, then it worked without this error.