punkish/winston-better-sqlite3

Writing Nulls to Database

Closed this issue · 4 comments

I was looking through the library and noticed that the insert was failing.

I made a quick modification and noticed that inserting the logparams directing into seemed to work.

I am having the same issue - inserts are being executed and the auto fields are populated but no level or message. I don't understand fmikael's modification. Here is my config:

const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [
        new wbs({
            db: path.join(dbPath, 'evmaster.ev4'),
            params: ['level', 'message'],
            handleExceptions: true
        })
    ],
    exitOnError: false
});

This issue seems to be in this code:

const logparams = Object.values(info);

let params = [];
this.params.forEach(el => {
        params.push(logparams[ el ]);
});

the const is built as an array of values with the key 0 and 1
when the data is pushed into params, el is 'level' and 'message', not 0 or 1

    log(info, callback) {
        let params = [];
        this.params.forEach(el => {
            params.push(info[el]);
        });

        setImmediate(() => {
            this.emit('logged', info);
        });

        this.insert.run(params);

        // Perform the writing to the remote service
        callback();
    }

@punkish any chance you will fix that soon? There is actually a pull request for it.