winstonjs / winston

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

Mutating the info object does nothing when combined with format.splat #1492

Open riker09 opened 6 years ago

riker09 commented 6 years ago

Environment

What is the problem?

A few lines of code tell more than a picture:

const mask = format((info) => {
    if (info.password) {
        info.password = '****';
    }
    return info;
});

const logger = createLogger({
    'info',
    format: format.combine(
        mask(),
        format.splat(),
        format.simple()
    ),
    transports: [
        new transports.Console(),
    ],
});

const obj = {
    username: "foo",
    password: "bar",
};

logger.info('logging %O', obj);

The resulting log entry still has the value of field password in plain text:

info: logging { username: "foo", password: "bar" }

What do you expect to happen instead?

The value of the password field should be masked with four asterisks:

info: logging { username: "foo", password: "****" }

Other information

DABH commented 6 years ago

I'm looking into a related issue, may have some updates for you soon!

FYI -- level: 'info', not 'info',, that may be one issue...

indexzero commented 5 years ago

This feels like a bug related to format ordering and SPLAT. This is a work-around in the mean-time:

const { createLogger, format, transports } = require('../');

const mask = format((info) => {
    if (info.password) {
        info.password = '****';
    }
    return info;
});

const logger = createLogger({
    level: 'info',
    format: format.combine(
        format.splat(),
        mask(),
        format.simple()
    ),
    transports: [
        new transports.Console(),
    ],
});

const obj = {
    username: "foo",
    password: "bar",
};

logger.info('logging', obj);