How to use winston-transport - 9 common examples

To help you get started, we’ve selected a few winston-transport 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 satoripop / thesuperlogger / src / transports / winston-mail.js View on Github external
let Mail = exports.Mail = function(options) {
  options = options || {}
  Transport.call(this, options);

  if (!options.to) {
    throw new Error("super-logger(winston-email) requires 'to' property")
  }

  if (!options.transportOptions) {
    throw new Error("super-logger(winston-email) requires 'transportOptions'")
  }

  this.to = options.to;
  this.from = options.from || 'super-logger@' + os.hostname();
  this.subject = options.subject || '';
  this.html = options.html || false; // Send mail in html format
  this.formatter = options.formatter || false;
  this.level = options.level;
github satoripop / thesuperlogger / src / transports / winston-console.js View on Github external
var Console = module.exports = function (options) {
	options = options || {};
	TransportStream.call(this, options);
	this.stderrLevels = getStderrLevels(options.stderrLevels, options.debugStdout);
	this.eol = os.EOL;

	//
	// Convert stderrLevels into an Object for faster key-lookup times than an Array.
	//
	// For backwards compatibility, stderrLevels defaults to ['error', 'debug']
	// or ['error'] depending on whether options.debugStdout is true.
	//
	function getStderrLevels(levels, debugStdout) {
		var defaultMsg = 'Cannot have non-string elements in stderrLevels Array';
		if (debugStdout) {
			if (levels) {
				//
				// Don't allow setting both debugStdout and stderrLevels together,
				// since this could cause behaviour a programmer might not expect.
github winstonjs / winston-daily-rotate-file / daily-rotate-file.js View on Github external
var DailyRotateFile = function (options) {
    options = options || {};
    Transport.call(this, options);

    function throwIf(target /* , illegal... */) {
        Array.prototype.slice.call(arguments, 1).forEach(function (name) {
            if (options[name]) {
                throw new Error('Cannot set ' + name + ' and ' + target + ' together');
            }
        });
    }

    function getMaxSize(size) {
        if (size && typeof size === 'string') {
            var _s = size.toLowerCase().match(/^((?:0\.)?\d+)([k|m|g])$/);
            if (_s) {
                return size;
            }
        } else if (size && Number.isInteger(size)) {
github satoripop / thesuperlogger / src / transports / winston-mongodb.js View on Github external
* @license MIT
 * @author charlie@nodejitsu.com (Charlie Robbins)
 * @author 0@39.yt (Yurij Mikhalevich)
 * @author imen.ammar@satoripop.tn (Imen Ammar)
 */
const util = require('util');
const os = require('os');
const mongodb = require('mongodb');
const _ = require('lodash');
const { LEVEL } = require('triple-beam');
const Stream = require('stream').Stream;
const logTypes = require('../helpers/logTypes');
const helpers = require('./helpers');

let Transport = require('winston-transport');
Transport.prototype.normalizeQuery = function (options) {  //
	options = options || {};

	// limit
	options.rows = options.rows || options.limit || 10;

	// starting row offset
	options.start = options.start || 0;

	// now
	options.until = options.until || new Date();
	if (typeof options.until !== 'object') {
		options.until = new Date(options.until);
	}

	// now - 24
	options.from = options.from || (options.until - (24 * 60 * 60 * 1000));
github satoripop / thesuperlogger / src / transports / winston-mongodb.js View on Github external
// now - 24
	options.from = options.from || (options.until - (24 * 60 * 60 * 1000));
	if (typeof options.from !== 'object') {
		options.from = new Date(options.from);
	}

	// 'asc' or 'desc'
	options.order = options.order || 'desc';

	// which fields to select
	options.fields = options.fields;

	return options;
};
Transport.prototype.formatResults = function (results, options) {
	return results;
};

/**
 * Constructor for the MongoDB transport object.
 * @constructor
 * @param {Object} options
 * @param {string=info} options.level Level of messages that this transport
 * should log.
 * @param {boolean=false} options.silent Boolean flag indicating whether to
 * suppress output.
 * @param {string|Object} options.db MongoDB connection uri or preconnected db
 * object.
 * @param {Object} options.options MongoDB connection parameters
 * (optional, defaults to `{poolSize: 2, autoReconnect: true}`).
 * @param {string=logs} options.collection The name of the collection you want
github satoripop / thesuperlogger / src / transports / winston-mongodb.js View on Github external
let MongoDB = exports.MongoDB = function(options) {
	Transport.call(this, options);
	options = (options || {});
	if (!options.db) {
		throw new Error('You should provide db to log to.');
	}
	this.on('error', (err) => {
		console.error('super-logger(winston-mongodb), error on logging in database: ', err);
	});
	this.name = options.name || 'mongodb';
	this.db = options.db;
	this.options = options.options;
	if (!this.options) {
		this.options = {
			poolSize: 2,
			autoReconnect: true,
		};
	}
github satoripop / thesuperlogger / src / transports / winston-mongodb.js View on Github external
setupDatabaseAndEmptyQueue(this.db);
	}
};


/**
 * Inherit from `winston.Transport`.
 */
util.inherits(MongoDB, Transport);


/**
 * Define a getter so that `winston.transports.MongoDB`
 * is available and thus backwards compatible.
 */
Transport.MongoDB = MongoDB;


/**
 * Closes MongoDB connection so using process would not hang up.
 * Used by winston Logger.close on transports.
 */
MongoDB.prototype.close = function() {
	if (!this.logDb) {
		return;
	}
	this.logDb.close().then(()=>this.logDb = null).catch(err=>{
		console.error('Winston MongoDB transport encountered on error during closing.', err);
	});
};
github winstonjs / winston-mongodb / lib / winston-mongodb.js View on Github external
let MongoDB = exports.MongoDB = function(options) {
  Transport.call(this, options);
  options = (options || {});
  if (!options.db) {
    throw new Error('You should provide db to log to.');
  }
  this.name = options.name || 'mongodb';
  this.db = options.db;
  this.options = options.options;
  if (!this.options) {
    this.options = {
      poolSize: 2,
      autoReconnect: true,
      useNewUrlParser: true
    };
  }
  this.collection = (options.collection || 'log');
  this.level = (options.level || 'info');
github satoripop / thesuperlogger / src / transports / winston-mail.js View on Github external
this.transporter = nodemailer.createTransport(
    options.transportOptions
  );
}

/**
 * Inherit from `winston.Transport`.
 */
util.inherits(Mail, Transport);

/**
 * Define a getter so that `winston.transports.Mail`
 * is available and thus backwards compatible.
 */
Transport.Mail = Mail;

/**
 * Core logging method exposed to Winston. Metadata is optional.
 * @param {object} info **Optional** Additional metadata to attach
 * @param {Function} cb Continuation to respond to when complete.
 */
Mail.prototype.log = function(info, cb) {
  var self = this
  let level = info[LEVEL];
  if (levels[level] != levels[lowestLevel] && levels[level] >= levels[this.level]){
    if(cb) cb(null, true)
    return;
  }

  let body;
  let env  = (process.env.APP_ENV || "prod").toUpperCase();

winston-transport

Base stream implementations for winston@3 and up.

MIT
Latest version published 1 month ago

Package Health Score

89 / 100
Full package analysis