winstonjs / winston

A logger for just about everything.
http://github.com/winstonjs/winston
MIT License
22.89k stars 1.81k forks source link

Transport formatter options schema #1269

Open Nokel81 opened 6 years ago

Nokel81 commented 6 years ago

When writing my own custom formatter it would very useful to know the schema for the options object that is passed to the formatter. Does this exist already or would it be possible to be made?

unlucio commented 6 years ago

@Nokel81 it's JS, which means you can always obtain it by your self :D (one non trivial advantage of dynamic languages VS static ones)

start with a simple:

winstonTransports.push(new winston.transports.Console({
[...]
formatter: function (options) {
        console.log('options: ', options);
        return options;
    }
});

or just simply place a debugger before the console.log, open a remote debug session and have fun :D

Nokel81 commented 6 years ago

I have to do that with a process.stdout.write command else I get a maximum stack size crash. Yes I can do that but might not every possible option be there always?

unlucio commented 6 years ago

weird, just ran it on a project of mine and got the expected:

formatter options: { colorize: true,
  json: false,
  level: 'debug',
  message: 'App setup done, loaded layers: [...]',
  meta: {},
  stringify: undefined,
  timestamp: [Function: tsFormat],
  showLevel: true,
  prettyPrint: false,
  raw: false,
  label: null,
  logstash: false,
  depth: null,
  formatter: [Function: formatter],
  align: false,
  humanReadableUnhandledException: false }

perhaps you sent in an object with recursive references?

And well, I guess there might be some enumerable: false property (even if currently looking for then in winston's codebase is an empty set: https://github.com/winstonjs/winston/search?q=enumerable&type=Code). But even in that case:

indexzero commented 6 years ago

@Nokel81 are you using winston@2 or winston@3?

Nokel81 commented 6 years ago

I am using winston@3

indexzero commented 6 years ago

Interesting – just to be clear if you are talking about filter orrewritersfromwinston@2` please see the Upgrade Guide.

Defining and documenting the schema of info objects in winston@3 (and what formats add what properties) would be very useful documentation. Will leave this open as a way to track those docs.

indexzero commented 6 years ago

Related to https://github.com/winstonjs/logform/issues/9