Winston Journal Confidential

I decided to use winston

to log into my project node

. I am developing this application on Windows platform, but ultimately it will be on linux platform.

Here is the code I used to set up the logger.

/* Custom logging module
 * to write appropriate logs into log files as well as console.
 */

var winston = require( 'winston' );

winston.setLevels({
    info: 0,
    error: 1,
    warning: 2,
    audit: 3
});

winston.addColors({
    info: 'blue',
    error: 'red',
    warning: 'yellow',
    audit: 'green'
});

var logger = new ( winston.Logger )({
    levels: {
        info: 0,
        error: 1,
        warning: 2,
        audit: 3
    },

    transports : [
        new (winston.transports.Console)({
            level: 'info',
            prettyPrint: true,
            colorize: true,
            silent: false,
            timestamp: true
        }),

        new (winston.transports.File)({
            name : 'infoLogger',
            filename : './logs/info-log.log',
            prettyPrint: false,
            level: 'info',
            silent: false,
            colorize: true,
            timestamp: true,
            maxsize: 40000,
            maxFiles: 10,
            json: false,
            tailable : true
        }),

        new (winston.transports.File)({
            name : 'errorLogger',
            filename : './logs/error-log.log',
            prettyPrint : false,
            level : 'error',
            silent : false,
            colorize : true,
            timestamp : true,
            maxsize : 40000,
            maxFiles : 10,
            json : false,
            tailable : true
        }),

        new (winston.transports.File)({
            name : 'warningLogger',
            filename : './logs/warning-log.log',
            prettyPrint : false,
            level : 'warning',
            silent : false,
            colorize : true,
            timestamp : true,
            maxsize : 40000,
            maxFiles : 10,
            json : false,
            tailable : true
        }),

        new (winston.transports.File)({
            name : 'auditLog',
            filename : './logs/audit-log.log',
            prettyPrint : false,
            level : 'audit',
            silent : false,
            colorize : true,
            timestamp : true,
            maxsize : 40000,
            maxFiles : 10,
            json : false,
            tailable : true
        })
    ],

    colors: {
        info: 'blue',
        error: 'red',
        warning: 'yellow',
        audit: 'green'
    }
});

module.exports = logger;

      

And I am using the complete code to enter the files.

logger.info( 'Winstom Log Info' );
logger.error( 'Winstom Log Error' );
logger.warning( 'Winstom Log Waring' );
logger.audit( 'Winstom Log Audit' );

      

However, there are no colors in the message entries. And the logged files do not accurately log their own levels. For example,

error-log.log

contains changeable messages.

2015-05-23T13:34:32.479Z - error: Winstom Log Error
2015-05-23T13:34:32.480Z - warning: Winstom Log Waring
2015-05-23T13:34:32.481Z - audit: Winstom Log Audit
2015-05-23T13:45:33.433Z - error: Winstom Log Error
2015-05-23T13:45:33.436Z - warning: Winstom Log Waring
2015-05-23T13:45:33.436Z - audit: Winstom Log Audit
2015-05-23T13:56:50.660Z - error: Winstom Log Error
2015-05-23T13:56:50.661Z - warning: Winstom Log Waring
2015-05-23T13:56:50.661Z - audit: Winstom Log Audit
2015-05-23T14:00:04.319Z - error: Winstom Log Error
2015-05-23T14:00:04.319Z - warning: Winstom Log Waring
2015-05-23T14:00:04.319Z - audit: Winstom Log Audit

      

The error log records warning and audit logs. The same goes for warning logs, they also catch logs for audit logs.

2015-05-23T13:34:32.480Z - warning: Winstom Log Waring
2015-05-23T13:34:32.481Z - audit: Winstom Log Audit
2015-05-23T13:45:33.436Z - warning: Winstom Log Waring
2015-05-23T13:45:33.436Z - audit: Winstom Log Audit
2015-05-23T13:56:50.661Z - warning: Winstom Log Waring
2015-05-23T13:56:50.661Z - audit: Winstom Log Audit
2015-05-23T14:00:04.319Z - warning: Winstom Log Waring
2015-05-23T14:00:04.319Z - audit: Winstom Log Audit

      

At the moment, only the audit log and data log are working. An audit containing only audit trails and an information log containing each one.

What is causing this error? And please also enlighten me on any of the best journaling practices.

+3


source to share


1 answer


As per your log settings:

levels: {
    info: 0,
    error: 1,
    warning: 2,
    audit: 3
},

      

Winston is behaving as he should. That is, if you have a log transport installed to listen to log level error

(1), it will capture all logs at that level and above. Maybe you wanted to structure your levels as follows?

levels: {
    info: 0,
    warning: 1,
    error: 2,
    audit: 3
},

      



In this structure, your error log file will only write logs error

and audit

.

As far as your colors don't work, do you cmd.exe

accidentally use them? Console color may not work as it should. Friends don't let friends use cmd.exe on windows. cmder

is a much better option, especially for node.js development on Windows:

http://gooseberrycreative.com/cmder/

+3


source







All Articles