bithavoc / express-winston

express.js middleware for winstonjs
https://www.npmjs.com/package/express-winston
MIT License
796 stars 187 forks source link

Posibility of sending meta, not as separate field, but in the same object with message and log level #209

Closed MikeKoval closed 3 years ago

MikeKoval commented 5 years ago

Hi! Thank you for awesome plugin :+1:

Is it possible to allow users send meta not inside separate meta field, but in the same object with message and level here https://github.com/bithavoc/express-winston/blob/master/index.js#L360?

The thing is winston documentation says const { level, message, ...meta } = info; is ok, also I tried to connect this module with https://github.com/logdna/logdna-winston/blob/master/index.js#L29 assuming meta is all other message fields except message itself and level...
Consequently I have meta.meta.res.statusCode in my logs... Visually it's ok ok, but it's not so important.

But I haven't written this issue if I haven't bumped into Depth of parsed nested fields limitation of logging service https://docs.logdna.com/docs/ingestion#section-service-limits

yinzara commented 4 years ago

This is actually a bug in how the "express-winston" library is sending log messages and has never been reported.

The "log" method on the winston Logger object is defined a "LogMethod" which has the signature:

interface LogMethod {
        (level: string, msg: string, callback: LogCallback): LoggerInstance;
        (level: string, msg: string, meta: any, callback: LogCallback): LoggerInstance;
        (level: string, msg: string, ...meta: any[]): LoggerInstance;
    }

However, the express-winston library calls winston using the syntax: logger.log({level, message: msg, meta}) when it should be: logger.log(level, msg, meta)

Doing this will correctly insert the information in the correct location in the logs. PR forthcoming however this will dramatically change the output from the library and I have a feeling will not be accepted unless we have a major version upgrade.

yinzara commented 4 years ago

This is now fixed with express-winston 4