cocalc/src / smc-project / node_modules / broadway / node_modules / winston / lib / winston / transports / transport.js
50665 views/*1* transport.js: Base Transport object for all Winston transports.2*3* (C) 2010 Charlie Robbins4* MIT LICENCE5*6*/78var events = require('events'),9util = require('util');1011//12// ### function Transport (options)13// #### @options {Object} Options for this instance.14// Constructor function for the Tranport object responsible15// base functionality for all winston transports.16//17var Transport = exports.Transport = function (options) {18events.EventEmitter.call(this);1920options = options || {};21this.level = options.level || 'info';22this.silent = options.silent || false;23this.raw = options.raw || false;2425this.handleExceptions = options.handleExceptions || false;26};2728//29// Inherit from `events.EventEmitter`.30//31util.inherits(Transport, events.EventEmitter);3233//34// ### function formatQuery (query)35// #### @query {string|Object} Query to format36// Formats the specified `query` Object (or string) to conform37// with the underlying implementation of this transport.38//39Transport.prototype.formatQuery = function (query) {40return query;41};4243//44// ### function normalizeQuery (query)45// #### @options {string|Object} Query to normalize46// Normalize options for query47//48Transport.prototype.normalizeQuery = function (options) {49//50// Use options similar to loggly.51// [See Loggly Search API](http://wiki.loggly.com/retrieve_events#optional)52//5354options = options || {};5556// limit57options.rows = options.rows || options.limit || 10;5859// starting row offset60options.start = options.start || 0;6162// now - 2463options.from = options.from || new Date - (24 * 60 * 60 * 1000);64if (typeof options.from !== 'object') {65options.from = new Date(options.from);66}6768// now69options.until = options.until || new Date;70if (typeof options.until !== 'object') {71options.until = new Date(options.until);72}7374// 'asc' or 'desc'75options.order = options.order || 'desc';7677// which fields to select78options.fields = options.fields;7980return options;81};8283//84// ### function formatResults (results, options)85// #### @results {Object|Array} Results returned from `.query`.86// #### @options {Object} **Optional** Formatting options87// Formats the specified `results` with the given `options` accordinging88// to the implementation of this transport.89//90Transport.prototype.formatResults = function (results, options) {91return results;92};9394//95// ### function logException (msg, meta, callback)96// #### @msg {string} Message to log97// #### @meta {Object} **Optional** Additional metadata to attach98// #### @callback {function} Continuation to respond to when complete.99// Logs the specified `msg`, `meta` and responds to the callback once the log100// operation is complete to ensure that the event loop will not exit before101// all logging has completed.102//103Transport.prototype.logException = function (msg, meta, callback) {104var self = this;105106function onLogged () {107self.removeListener('error', onError);108callback();109}110111function onError () {112self.removeListener('logged', onLogged);113callback();114}115116this.once('logged', onLogged);117this.once('error', onError);118this.log('error', msg, meta, function () { });119};120121122