Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 9 Examples of "winston-transport in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'winston-transport' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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;
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.
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)) {
* @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));
// 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
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,
		};
	}
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);
	});
};
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');
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();

Is your System Free of Underlying Vulnerabilities?
Find Out Now