-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta is broken again in 5.0.0 #160
Comments
try this:
|
Have the same issue. I'm using "winston": "3.2.1" with "winston-mongodb": "5.0.1". In addition, I tried above, but it doesn't work for me. Downgrade "winston-mongodb" to v4.0.9 and the issue resolved |
It seems to me that it's not broken, but it has a different API from normal winston. |
@MastroLindus changing the API to agree with the default |
Workaround 1 const winston = require('winston');
require('winston-mongodb');
const _ = require('lodash');
const insertMetaForWinstonMongo = winston.format(logEntry => {
logEntry.metadata = _.chain(logEntry).omit(logEntry, ['level', 'message']).omitBy((value, key) => _.isSymbol(key)).value();
// For winston-mongodb < 5.x I was using
// logEntry.meta = _.chain(logEntry).omit(logEntry, ['level', 'message']).omitBy((value, key) => _.isSymbol(key)).value();
return logEntry;
});
const logger = winston.createLogger({
transports: [new winston.transports.MongoDB()],
format: insertMetaForWinstonMongo(),
}); EDIT Workaround 2 const winston = require('winston');
require('winston-mongodb');
const insertMetaForWinstonMongo = winston.format(logEntry => {
logEntry.metadata = logEntry.meta;
return logEntry;
});
const logger = winston.createLogger({
transports: [new winston.transports.MongoDB()],
format: winston.format.combine(winston.format.splat(), insertMetaForWinstonMongo()),
}); It's a breacking change in 5.x |
@HugoPoi 's formatter in un-lodash is something like:
|
@yurijmikhalevich : the winston-mongodb API has not yet been changed to match the winston API to allow easily pass meta data, without extra format configurations |
Currently, as with winston-mongodb v5.1.1 and winston v3.11.0, only @HugoPoi 's Workaround 1 works as best configurations to apply |
The below code does not work when trying to set the metadata currently in version 5.0.0
Rolling back to 4.0.9 was my only option.
is there a new way to setting metadata?
in 3.0.0 you could simply set
winston.error(err.message, err)
and the second argument would automatically populate the meta field in mongo. now I need to set the parameters via an object in 4.0.9. So what is the new way for 5.0.0?The text was updated successfully, but these errors were encountered: