How to use the winston.transports function in winston

To help you get started, we’ve selected a few winston examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DIYgod / RSSHub / lib / utils / logger.js View on Github external
// - Write all logs error (and below) to `error.log`.
        //
        new winston.transports.File({
            filename: 'logs/error.log',
            level: 'error',
        }),
        new winston.transports.File({ filename: 'logs/combined.log' }),
    ],
});

//
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
logger.add(
    new winston.transports.Console({
        format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
        silent: process.env.NODE_ENV === 'test',
    })
);

module.exports = logger;
github soomtong / blititor / core / index.js View on Github external
const device = require('express-device');
const compress = require('compression');
const morgan = require('morgan');
const errorHandler = require('errorhandler');
const lusca = require('lusca');
const nunjucks = require('nunjucks');
const winston = require('winston');
const passport = require('passport');
const moment = require('moment');
const mkdirp = require('mkdirp');
const args = require('minimist');
const clc = require('cli-color');

// set log level
if (BLITITOR.env === 'production') {
    winston.add(new winston.transports.File({
        filename: path.join(__dirname, 'log', 'winston.log'),
        format: winston.format.combine(
            winston.format.timestamp({
                format: 'YYYY-MM-DD HH:mm:ss'
            }),
            winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
        ),
        level: BLITITOR.config.logLevel || 'verbose'
    }));
} else {
    winston.add(new winston.transports.Console({
        format: winston.format.combine(
            winston.format.colorize(),
            winston.format.timestamp({
                format: 'MM-DD HH:mm:ss'
            }),
github ethanlim / ccmf / tests / text / shingles-performance.js View on Github external
* 	Testing Parameters
 */
var n = 1000,
	testFileName = '/tests/shingles-performance.js',
	sampleFile = '../../samples/reuters/reut2-000.sgm',
	outputFileName = '../../logs/tests/shingles-performance.txt';

/**
 *  Logger
 */
winston.profile('test');

var logger = new (winston.Logger)({
    transports: [
      new (winston.transports.Console)(),
      new (winston.transports.File)({filename: outputFileName })
    ]
});

/**
 *  Prepare Test Situation 
 */

var	startTime = null,
	elapsedTime = null;

/**
 *  Generate Test Cases  
 */
test('Time taken for extracting shingles',function(t){
	
	fs.exists(outputFileName, function(exists) {
github stormpath / express-stormpath / test / helpers / test-get-user.js View on Github external
},
      expand: {
        customData: true
      },
      web: {
        login: {
          enabled: true
        }
      }
    });

    app.set('stormpathApplication', stormpathApplication);
    app.set('stormpathClient', stormpathClient);
    app.set('stormpathLogger', new winston.Logger({
      transports: [
        new winston.transports.Console({
          colorize: true,
          level: 'error'
        })
      ]
    }));
    app.set('stormpathConfig', config);
    app.use(cookieParser());

    return function (req, res, next) {
      req.app = app;
      next();
    };
  }
github sonatype-nexus-community / auditjs / config.js View on Github external
}
    programPackage = program['package'] ? path.basename(program['package']): 'scan_node_modules.json';
    output = `${programPackage.toString().split('.json').slice(0, -1)}.xml`;
    pm = program['bower'] ? 'bower' : 'npm';

    if (program['dependencyTypes'] && program['production']) {
     throw Error('Cannot use --dependencyTypes and --production options together');
    }

    //Set logging level based on environmental value or flag
    if (program['quiet']) {
     logger = new (winston.Logger)();
    } else {
     logger = new (winston.Logger)({
       transports: [
         new (winston.transports.Console)({
           level: process.env.LOG_LEVEL ||
             (program['verbose']?'verbose':false) ||
             (LOGGER_LEVELS.includes(program['level'])?program['level']:false)
             || 'info',
           formatter: logFormatter})
       ]
     });
    }

    /** Hack code to allow us to check if a specific logger level is enabled.
    */
    logger.isLevelEnabled = function(level) {
     if (this.transports && this.transports.console) {
       var levels = this.transports.console.level;
       return levels == level;
     }
github uosl / steam-chat / lib / logger.js View on Github external
exports.logFile = (bool, level) => {
    if (bool && !useLogFile) {
        logger.add(winston.transports.File, { 
            filename: path.join(__dirname, '..', 'steam-chat.log'),
            level: getLogLevel(level)
        });
        useLogFile = true;
        logger.log('info', doc.cmd.logFileEnable, level);
    } else if (!bool && useLogFile) {
        logger.remove(winston.transports.File);
        useLogFile = false;
        logger.log('info', doc.cmd.logFileDisable);
    }
}
github arminhammer / bellerophon / src / logger.js View on Github external
var Logger = function() {
	var self = this;
	if(process.env['BELLEROPHON_LOG'] === 'debug') {
		self.logger = new winston.Logger({
			level: 'info',
			transports: [
				new (winston.transports.Console)(),
				new (winston.transports.File)({filename: os.homedir() + '/.bellerophon.log'})
			]
		});
	}

	self.log = function(msg, level, from) {
		if(!level) {
			level = 'info';
		}
		if(!from) {
			from = 'SERVER:'
		}
		if(process.env['BELLEROPHON_LOG'] === 'debug') {
			self.logger.log(level, from, msg);
		}
	};
github shipengqi / sactive-bot / lib / framework / logger.js View on Github external
info.message = Object.assign({
          message: info.message.message,
          stack: info.message.stack
        }, info.message);
      }

      if (info instanceof Error) {
        return Object.assign({
          message: info.message,
          stack: info.stack
        }, info);
      }

      return info;
    });
    let dailyRotateFileTransport = new (logger.transports.DailyRotateFile)({
      filename: dailyFileName,
      datePattern: 'YYYY-MM-DD',
      maxSize: '20m',
      maxFiles: $$utils.envs('SBOT_LOG_FILE_TIME'),
      level: $$utils.envs('SBOT_LOG_LEVEL')
    });
    let consoleTransport = new (logger.transports.Console)({
      format: combine(
        label(sbotFormatLabel),
        timestamp(sbotFormatTimestamp),
        colorize(),
        sbotFormat
      ),
      level: $$utils.envs('SBOT_LOG_LEVEL')
    });
    let transports = [
github AnuraConfig / anura-server / server / utils / logger.js View on Github external
_getTransports(config) {
        const transports = []
        if (config.ERROR_LOG_FILE)
            transports.push(new winston.transports.File({ filename: config.ERROR_LOG_FILE, level: 'error' }))
        if (config.LOG_FILE)
            transports.push(new winston.transports.File({ filename: config.LOG_FILE }))
        return transports
    }
}