How to use the winston.Logger 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 egovernments / egov-services / test / postman / datagen / bad_datagen.jsx View on Github external
const SwaggerParser = require("swagger-parser");
const yamljs = require("yamljs");

const fs = require("fs")
// const log = require("winston-color")
// log.level = 'debug';

const winston = require('winston');
const wcf = require('winston-console-formatter');
const util = require('util')
const log = new winston.Logger({
    level: 'debug',
});

const {formatter, timestamp} = wcf();

const JSONPath = function () {
    this.performOperations = (data, operations) => {
        for (let op in operations) {
            let json_path = operations[op]["json_path"]
            let value = operations[op]["value"];
            console.log("Performing - " + json_path + " - " + value)

            if (value == "##delete##")
                this.remove(data, json_path)
            else
                this.set(data, json_path, value)
github fugitivelabs / yote / server / logger.js View on Github external
// var config = require('./config')[env];

// adapted from http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
winston.emitErrs = true;

let logger;

if(env == 'production') {

  //testing Google Cloud Logging for production
  // //if deployed on compute engine, Google will handle auth automatically
  // var logging = require('@google-cloud/logging');


  //if prod, log to file and console
  logger = new winston.Logger({
    // // these logs get massive on the database end and frankly we never use them.
    transports: [
    //   new winston.transports.MongoDB({
    //     level: 'info'
    //     , db: config.db
    //     , capped: true
    //     , handleExceptions: true
    //     , collection: 'logs'
    //   })
      // NOTE: cannot get this to work on docker instance. it will not write to the linked docker volume for some reason. trying mongodb instead.
      // TODO: figure this out. logging to file would be more useful than to mongo
      // new winston.transports.File({
      //   level: 'info'
      //   , filename: './logs/all-logs.log'
      //   , handleExceptions: true
      //   , json: true
github pebble / keen-cache / lib / keen-proxy.js View on Github external
var KeenProxy = function(config) {
  var self = this;

  // Initialize our logger
  self.logger = new (winston.Logger)({
    transports: [
      new (winston.transports.Console)({ level: config.logLevel })
    ]
  });


  /* *** Private functions *** */

  // Decide whether this request should be authorized or not, based on the CORS headers
  var allowCrossDomain = function(req, res, next) {
    if (req.headers.origin && _.contains(config.allowedDomains, req.headers.origin)) {
      res.header('Access-Control-Allow-Origin', req.headers.origin);
      if(req.headers['access-control-request-method']) {
          res.header('Access-Control-Allow-Methods', req.headers['access-control-request-method']);
      }
      if(req.headers['access-control-request-headers']) {
github akyuujs / akyuu / lib / logger / index.js View on Github external
get(name) {
        if(this.loggers[name]) {
            return this.loggers[name];
        }

        // create a logger
        let logger = this.loggers[name] = new winston.Logger({
            transports: this.getTransports(name)
        });

        const self = this;
        this.loggers[name].on("close", function() {
            self._delete(name);
        });

        // hack logger
        logger.$error = logger.error;
        logger.error = function() {
            if(arguments.length) {
                if(arguments[0] && arguments[0].stack) {
                    arguments[0] = arguments[0].stack;
                }
            }
github foreversd / forever / lib / forever.js View on Github external
//
// Setup `forever.log` to be a custom `winston` logger.
//
forever.log = new (winston.Logger)({
  transports: [
    new (winston.transports.Console)()
  ]
});

forever.log.cli();

//
// Setup `forever out` for logEvents with `winston` custom logger.
//
forever.out = new (winston.Logger)({
  transports: [
    new (winston.transports.Console)()
  ]
});

//
// ### Export Components / Settings
// Export `version` and important Prototypes from `lib/forever/*`
//
forever.initialized  = false;
forever.kill         = require('forever-monitor').kill;
forever.checkProcess = require('forever-monitor').checkProcess;
forever.root         = process.env.FOREVER_ROOT || path.join(process.env.HOME || process.env.USERPROFILE || '/root', '.forever');
forever.config       = configUtils.initConfigFile(forever.root);
forever.Forever      = forever.Monitor = require('forever-monitor').Monitor;
forever.Worker       = require('./forever/worker').Worker;
github slidewiki / slidewiki-platform / configs / log.js View on Github external
const winston = require('winston');
const fs = require('fs');
const logDir = 'logs';
const obj = {};

// Create the log directory if it does not exist
//if (!fs.existsSync(logDir)) {
//    fs.mkdirSync(logDir);
//}

// winston.setLevels(winston.config.npm.levels);
//winston.setLevels(winston.config.syslog.levels);
//winston.addColors(winston.config.npm.colors);

if (!obj.log) {
    obj.log = new (winston.Logger)({
        transports: [
            // Console transport
            new (winston.transports.Console)({
                timestamp: true,
                colorize: true,
                level: 'debug',
                handleExceptions: true,
                humanReadableUnhandledException: true
            }),
            // file transport; If you uncomment below lines, pls also uncomment line 6 (if condition) in this file,
            // that is about creating log directory if it doesn't exist.
            /*
            new (require('winston-daily-rotate-file'))({
                label: 'slidewiki-platform',
                filename: `${logDir}/-platform.log`,
                timestamp: true,
github scality / Arsenal / tests / functional / socketTester1.js View on Github external
import net from 'net';
import { Kinetic } from '../../index';
import winston from 'winston';

const logger = new (winston.Logger)({
    transports: [
        new (winston.transports.Console)({ level: 'warn' }),
    ]
});

const errorMessage = new Buffer('qwerty');
const HOST = '127.0.0.1';
const PORT = 6970;
const kinetic = new Kinetic;

function loadLogs(int) {
    switch (int) {
    case kinetic.logs.UTILIZATIONS:
        return {
            "name": 'Device1',
            "value": 5,
github jamesmorgan / devicecast / lib / common / logger.js View on Github external
'use strict';
var winston = require('winston');
var config = require('../../config.json');
var _ = require('lodash');

winston.emitErrs = true;

var level = _.get(config, 'logger.level', 'debug');
console.log('Logger level set to', level);

var logger = new (winston.Logger)({
    transports: [
        new winston.transports.Console({
            handleExceptions: true,
            json: false,
            colorize: true,
            timestamp: true
        }),
        new (winston.transports.File)({
            level: 'error',
            filename: './logs/error.log',
            json: false,
            timestamp: true,
            handleExceptions: true,
            humanReadableUnhandledException: true
        })
    ],
github dragonbanshee / node-steam-chat-bot / lib / triggers / logTrigger.js View on Github external
LogTrigger.prototype._respondToChatMessage = function(roomId, userId, message) {
	var that = this;
	if(this.options.logGroupChats === true||this.options.logConsole) {
		this.winston.debug(this.chatBot.name+"/"+this.name+": Logging message from "+userId+" in "+roomId);
		if(!(this.logs.groups[roomId] && this.logs.groups[roomId].log instanceof Function)) {
			var filename = that.options.logDir+"/"+that.options.prefix[1]+handySanitizer(that.options.roomNames[roomId]||roomId)+that.options.suffix[1];
			that.winston.info(that.chatBot.name+"/"+that.name+": "+roomId+ " Initiating group log "+filename);
			that.logs.groups[roomId] = new winston.Logger;
			if(that.options.logGroupChats) {
				that.logs.groups[roomId].add(winston.transports.File, {colorize: false,timestamp: false,filename: filename,json:false});
			}
			if(that.options.logConsole === false) {
				that.logs.groups[roomId].remove(winston.transports.Console);
			}
		}
		this.logs.groups[roomId].info(this._timestamp() + this._username(userId) + this._message(message), function(){
			that.winston.debug(that.chatBot.name+"/"+that.name+": logged groupchat message");
		});
	};
	if(this.options.logGlobal) {
		this._global(roomId, userId, message,"group", null);
	}
	return false;
}
github AraiEzzra / DDKCORE / backlog / logger.js View on Github external
this.consoleTransport = consoleTransport;
        this.transport.formatter = function (options) {
            if (sessionId && address) {
                return `${options.timestamp()} - ${sessionId} - ${address} - [${options.level}] : ${options.message}`;
            } else if (sessionId) {
                return `${options.timestamp()} - ${sessionId} - [${options.level}] : ${options.message}`;
            } else if (address) {
                return `${options.timestamp()} - ${address} - [${options.level}] : ${options.message}`;
            }
            return `${options.timestamp()}  - [${options.level}] : ${options.message}`;
        };
        this.traceTransport = traceTransport;
        this.traceTransport.formatter = function (options) {
            return `${options.timestamp()}  - [${options.level}] : ${options.message}`;
        };
        this.logger = new (winston.Logger)({
            levels,
            transports: [this.traceTransport, this.transport, this.consoleTransport]
        });
    }
}