How to use winston - 10 common examples

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 OpenTMI / opentmi / test / unittests / routes / schemas.js View on Github external
/* eslint-disable func-names, prefer-arrow-callback, no-unused-expressions */

// Third party components
const {expect} = require('chai');
const logger = require('winston');

// Local components
const SchemaRoute = require('../../../app/routes/schemas');

// Setup
logger.level = 'error';


describe('routes/schemas.js', function () {
  describe('Route', function () {
    it('should define a parameter handler for Collection parameter', function (done) {
      const app = {
        use: (router) => {
          expect(router).to.have.property('params');
          expect(router.params).to.have.property('Collection');
          done();
        }
      };

      SchemaRoute(app);
    });
github stefanwille / nodejs-integration-testing / src / server.js View on Github external
const booksController = require('./booksController');

winston.add(winston.transports.File, {
  filename: `logs/${process.env['NODE_ENV']}.log`,
});

process.on('unhandledRejection', (error, promise) => {
  console.error('##### Unhandled Promise Rejection: #####');
  console.error((error && error.stack) || error);
  console.error(promise);
  throw error;
});

// Don't show the log when in test env
if (process.env['NODE_ENV'] === 'test') {
  winston.remove(winston.transports.Console);
}

const winstonStream = {
  write: function(message, encoding) {
    winston.info(message);
  },
};

const app = express();
app.use(morgan('combined', { stream: winstonStream }));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());

app.use(booksController.getRouter());
github feathers-plus / generator-feathers-plus / test-expands / a-gens / js / cumulative.test-expected / src1 / logger.js View on Github external
// Logger. (Can be re-generated.)
const { createLogger, format, transports } = require('winston');
// !code: imports // !end
// !code: init // !end

// Configure the Winston logger. For the complete documentation seee https://github.com/winstonjs/winston
const moduleExports = createLogger({
  // ! code: level
  // To see more detailed errors, change this to debug'
  level: 'info',
  // !end
  // ! code: format
  format: format.combine(
    format.splat(),
    format.simple()
  ),
  // !end
  // ! code: transport
  transports: [
    new transports.Console()
  ],
  // !end
  // !code: moduleExports // !end
github adobe / helix-cli / test / testLogCommon.js View on Github external
beforeEach(async () => {
    // reset the winston loggers
    winston.loggers.loggers.clear();
    await clean();
  });
github alphagov / pay-selfservice / test / integration / transaction_details_ft_tests.js View on Github external
before(function () {
        // Disable logging.
        winston.level = 'none';
    });
github jsreport / jsreport-core / lib / reporter.js View on Github external
msg = 'Error from logger (winston) while trying to use a file to store logs. If the directory "' + dir + '" does not exist, please create it:'
          }

          // make the error intentionally more visible to get the attention of the user
          console.error('------------------------')
          console.error(msg, err)
          console.error('------------------------')
        }
      })
    } else {
      if (!winston.loggers.get('jsreport').transports.debug) {
        winston.loggers.get('jsreport').add(DebugTransport)
      }
    }

    this.logger = winston.loggers.get('jsreport')
    this.logger.rewriters.push(function (level, msg, meta) {
      // detecting if meta is jsreport request object
      if (meta != null && meta.context) {
        meta.context.logs = meta.context.logs || []

        meta.context.logs.push({
          level: level,
          message: msg,
          timestamp: meta.timestamp || new Date().getTime()
        })

        // excluding non relevant properties for the log
        return Object.assign({}, omit(meta, ['template', 'options', 'data', 'context', 'timestamp']))
      }

      return meta
github vpdb / server / src / express.js View on Github external
/* istanbul ignore if  */
	// production only
	if (!runningDev) {
		http.globalAgent.maxSockets = 500; // set this high, if you use httpClient or request anywhere (defaults to 5)
	}

	// development only
	if (runningDev) {
		app.use(expressErrorhandler());
		app.locals.pretty = false;
	}

	if (runningLocal) {
		// kill switch for CI
		logger.warn('[express] Enabling kill switch for continueous integration.');
		/* istanbul ignore next  */
		app.post('/kill', function(req, res) {
			res.status(200).end();
			process.exit(0);
		});
	}

	// add the coverage handler
	if (process.env.COVERAGE_ENABLED) {
		//enable coverage endpoints under /coverage
		app.use('/_coverage', require('istanbul-middleware').createHandler());
		app.use('/coverage', express.static(path.resolve(__dirname, '../test/coverage/lcov-report'), { maxAge: 3600*24*30*1000 }));
	}
};
github soomtong / blititor / core / index.js View on Github external
winston.info('Server listening on port ' + app.get('port') + ' in ' + BLITITOR.env + ' mode')
    console.info("=== Server listening on port " + clc.yellow(app.get('port')) + " in " + clc.red(BLITITOR.env) + " mode");
    // display default route table
    // misc.showRouteTable();
});

if (!process.send) {
    // If run using `node app`, log copyright info along with server info
    const config = require('../package.json');
    winston.info('----------------------------------------------------------------');
    winston.info('BLITITOR v' + config.version + ' Copyright (C) 2016 @' + config.author + '.');
    winston.info('This program comes with ABSOLUTELY NO WARRANTY.');
    winston.info('This is free software, under ' + config.license + ' license');
    winston.info('and you are welcome to redistribute it under certain conditions.');
    winston.info('----------------------------------------------------------------');
    winston.verbose('module data file loaded. ' + BLITITOR.moduleList.length + ' modules located');
}

if (BLITITOR.env === 'development') { // Only in dev environment
    process.nextTick(function () {
        winston.info('update route data to log folder');
        misc.showGlobalVar(BLITITOR);
        misc.showRoutes(app);
    });
}
github a632079 / teng-koa / core.js View on Github external
async function registerRoutes (routes) {
  try {
    await routes.then(router => {
      app
        .use(router.routes())
        .use(router.allowedMethods())
    })
      .catch(err => {
        winston.error(err)
        // mail.error(err)
        process.exit(1)
      })
    winston.verbose('All Routes Load done.')
  } catch (e) {
    winston.error(e)
    // mail.error(e)
    process.exit(1)
  }
}