logger.js 1.11 KB
var strftime = require('strftime');
var winston = require('winston');


var loggerTimestamp = function() {
    return strftime('%F %T', new Date());
}

function start() {
    var logger = new winston.Logger({
        transports: [
            new (winston.transports.Console)({
                timestamp: function() {
                        return strftime('%F %T', new Date());
                },
                level: 'verbose',
            }),

            new (winston.transports.DailyRotateFile) ({
                name: 'log-file-txt',
                filename: 'logs/log.txt', 
                timestamp: loggerTimestamp,
                formatter: function(options) {
                    return options.timestamp() 
                        +' ' + options.level.toUpperCase() 
                        +' ' + (undefined !== options.message ? options.message : '') 
                        + (options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '' );
                },
                level: 'debug',
            }),
        ]
    });
    
    return logger;
}

exports.start = start;