Socket
Socket
Sign inDemoInstall

winston

Package Overview
Dependencies
6
Maintainers
0
Versions
82
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.11 to 0.3.3

docs/winston/config/cli-config.html

85

lib/winston.js

@@ -9,44 +9,38 @@ /*

require.paths.unshift(require('path').join(__dirname));
var winston = exports;
// Expose version
winston.version = [0, 2, 9];
//
// Include transports defined by default by winston
// Expose version using `pkginfo`
//
winston.transports = require('winston/transports');
require('pkginfo')(module, 'version');
//
// function findTransport (transport)
// Helper method to find existing transport
// Include transports defined by default by winston
//
winston.findTransport = function (transport) {
var name, existing = Object.keys(winston.transports).filter(function (k) {
return winston.transports[k] === transport;
});
winston.transports = require('./winston/transports');
return existing.length > 0 ? existing[0].toLowerCase() : null;
};
var utils = require('winston/utils');
winston.hash = utils.hash;
winston.clone = utils.clone;
winston.longestElement = utils.longestElement;
winston.config = require('winston/config');
var internal = require('./winston/internal');
winston.hash = internal.hash;
winston.clone = internal.clone;
winston.longestElement = internal.longestElement;
winston.config = require('./winston/config');
winston.addColors = winston.config.addColors;
winston.Logger = require('winston/logger').Logger;
winston.Logger = require('./winston/logger').Logger;
//
// We create and expose a "defaultLogger" so that the programmer may do the
// We create and expose a 'defaultLogger' so that the programmer may do the
// following without the need to create an instance of winston.Logger directly:
// var winston = require('winston');
// winston.log('info', 'some message');
// winston.error('some error');
//
var defaultLogger = new (winston.Logger)({ transports: [new (winston.transports.Console)()] });
utils.setLevels(winston, null, defaultLogger.levels);
// var winston = require('winston');
// winston.log('info', 'some message');
// winston.error('some error');
//
var defaultLogger = new winston.Logger({
transports: [new winston.transports.Console()]
});
//
// Pass through the target methods onto `winston.
//
internal.setLevels(winston, null, defaultLogger.levels);
['log', 'add', 'remove', 'profile', 'extend', 'cli'].forEach(function (method) {

@@ -58,5 +52,11 @@ winston[method] = function () {

winston.cli = function (foo, bar) {
//
// ### function cli ()
// Configures the default winston logger to have the
// settings for command-line interfaces: no timestamp,
// colors enabled, padded output, and additional levels.
//
winston.cli = function () {
winston.padLevels = true;
utils.setLevels(winston, defaultLogger.levels, winston.config.cli.levels);
internal.setLevels(winston, defaultLogger.levels, winston.config.cli.levels);
defaultLogger.setLevels(winston.config.cli.levels);

@@ -69,7 +69,14 @@ winston.config.addColors(winston.config.cli.colors);

}
return winston;
};
winston.setLevels = function (levels) {
utils.setLevels(winston, defaultLogger.levels, levels);
defaultLogger.setLevels(levels);
//
// ### function setLevels (target)
// #### @target {Object} Target levels to use
// Sets the `target` levels specified on the default winston logger.
//
winston.setLevels = function (target) {
internal.setLevels(winston, defaultLogger.levels, target);
defaultLogger.setLevels(target);
};

@@ -93,7 +100,9 @@

//
// function defaultTransports ()
// returns the transports set on the default winston logger
// @transports {Object}
// The default transports for the default winston logger.
//
winston.defaultTransports = function () {
return defaultLogger.transports;
};
Object.defineProperty(winston, 'defaultTransports', {
get: function () {
return defaultLogger.transports;
}
});

@@ -9,20 +9,7 @@ /*

require.paths.unshift(__dirname);
var colors = require('colors');
var colors = require('colors'),
config = exports,
var config = exports,
allColors = exports.allColors = {};
function mixin (target) {
var args = Array.prototype.slice.call(arguments, 1);
args.forEach(function (a) {
var keys = Object.keys(a);
for (var i = 0; i < keys.length; i++) {
target[keys[i]] = a[keys[i]];
}
});
return target;
};
config.addColors = function (colors) {

@@ -39,5 +26,5 @@ mixin(allColors, colors);

//
config.cli = require('config/cli-config');
config.npm = require('config/npm-config');
config.syslog = require('config/syslog-config');
config.cli = require('./config/cli-config');
config.npm = require('./config/npm-config');
config.syslog = require('./config/syslog-config');

@@ -48,2 +35,14 @@ //

config.addColors(config.npm.colors);
config.addColors(config.syslog.colors);
config.addColors(config.syslog.colors);
function mixin (target) {
var args = Array.prototype.slice.call(arguments, 1);
args.forEach(function (a) {
var keys = Object.keys(a);
for (var i = 0; i < keys.length; i++) {
target[keys[i]] = a[keys[i]];
}
});
return target;
};

@@ -9,9 +9,7 @@ /*

require.paths.unshift(require('path').join(__dirname, '..'));
var events = require('events'),
util = require('util'),
config = require('./config'),
internal = require('./internal');
var util = require('util'),
events = require('events'),
winston = require('winston'),
utils = require('./utils');
function capitalize(str) {

@@ -27,22 +25,32 @@ return str && str[0].toUpperCase() + str.slice(1);

//
// function Logger (options)
// Constructor for the logger object.
// ### function Logger (options)
// #### @options {Object} Options for this instance.
// Constructor function for the Logger object responsible
// for persisting log messages and metadata to one or more transports.
//
var Logger = exports.Logger = function (options) {
events.EventEmitter.call(this);
options = options || {};
var self = this;
options = options || {};
//
// Set Levels and default logging level
//
this.padLevels = options.padLevels || false;
this.setLevels(options.levels);
this.level = options.level || 'info';
this.emitErrs = options.emitErrs || false;
this.transports = {};
this.profilers = {};
//
// Setup other intelligent default settings.
//
this.level = options.level || 'info';
this.emitErrs = options.emitErrs || false;
this.stripColors = options.stripColors || false;
this.transports = {};
this.profilers = {};
this._names = [];
if (options.transports) {
options.transports.forEach(function (transport) {
self._names.push(transport.name);
self.transports[transport.name] = transport;

@@ -53,8 +61,12 @@ });

//
// Inherit from `events.EventEmitter`.
//
util.inherits(Logger, events.EventEmitter);
//
// function extend (target)
// Extends the target object with a 'log' method
// along with a method for each level in this instance.
// ### function extend (target)
// #### @target {Object} Target to extend.
// Extends the target object with a 'log' method
// along with a method for each level in this instance.
//

@@ -68,12 +80,18 @@ Logger.prototype.extend = function (target) {

});
return this;
};
//
// function log (level, msg, [meta, callback])
// Core logging method for Winston. Metadata and callback are is optional.
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
// #### @msg {string} Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} Continuation to respond to when complete.
// Core logging method exposed to Winston. Metadata is optional.
//
Logger.prototype.log = function (level, msg) {
var self = this, logged = 0, errs = [],
len = Object.keys(this.transports).length,
meta, callback;
var self = this,
callback,
meta;

@@ -103,4 +121,4 @@ if (arguments.length === 3) {

}
else if (self.emitErrs){
throw err;
else if (self.emitErrs) {
self.emit('error', err);
};

@@ -116,16 +134,32 @@ }

for (var key in this.transports) {
var transport = this.transports[key];
for (var i = 0, l = this._names.length; i < l; i++) {
var transport = this.transports[this._names[i]];
if ((transport.level && self.levels[transport.level] <= self.levels[level])
|| (!transport.level && self.levels[self.level] <= self.levels[level])) {
//
// For consideration of terminal 'color" programs like colors.js,
// which can add ANSI escape color codes to strings, we destyle the
// ANSI color escape codes when `this.stripColors` is set.
//
// see: http://en.wikipedia.org/wiki/ANSI_escape_code
//
if (this.stripColors) {
var code = /\u001b\[\d+m/g;
msg = ('' + msg).replace(code, '');
}
transport.log(level, msg, meta, function (err) {
if (err) errs.push({ error: err, transport: transport });
if (err && self.emitErrs) return self.emit('error', err, transport);
self.emit('log', transport, level, msg, meta);
if (++logged == len && callback) callback(errs.length > 0 ? errs : null, level, msg, meta);
});
}
};
}
//
// Immediately respond to the callback
//
if (callback) {
callback(null, level, msg, meta);
}
return this;

@@ -135,13 +169,28 @@ };

//
// function add (transport, [options])
// Adds a transport of the specified type to this instance.
// ### function add (transport, [options])
// #### @transport {Transport} Prototype of the Transport object to add.
// #### @options {Object} **Optional** Options for the Transport to add.
// Adds a transport of the specified type to this instance.
//
Logger.prototype.add = function (transport, options) {
var name = winston.findTransport(transport);
var instance = (new (transport)(options));
if (!name && !transport.prototype.log) throw new Error('Unknown transport with no log() method');
else if (this.transports[name]) throw new Error('Transport already attached: ' + name);
if (!instance.name && !instance.log) {
throw new Error('Unknown transport with no log() method');
}
else if (this.transports[instance.name]) {
throw new Error('Transport already attached: ' + instance.name);
}
var instance = (new (transport)(options));
this.transports[instance.name] = instance;
this._names = Object.keys(this.transports);
if (instance.on) {
//
// If the instance has an `on` method
// then listen for the `'error'` event.
//
instance.on('error', this._onError.bind(this, instance));
}
return this;

@@ -151,16 +200,25 @@ };

//
// function remove (transport)
// Removes a transport of the specified type from this instance.
// ### function remove (transport)
// #### @transport {Transport} Transport to remove.
// Removes a transport of the specified type from this instance.
//
Logger.prototype.remove = function (transport) {
var name = winston.findTransport(transport);
var name = transport.name || transport.prototype.name;
if (!this.transports[name]) {
throw new Error('Transport ' + name + ' not attached to this instance');
}
// If we can't find the name, try to use transport.name
if (!name) name = transport.name;
var instance = this.transports[name];
delete this.transports[name];
this._names = Object.keys(this.transports);
if (!this.transports[name]) throw new Error('Transport ' + name + ' not attached to this instance');
if (instance.close) {
instance.close();
}
var transportObject = this.transports[name];
delete this.transports[name];
if (transportObject.close) transportObject.close();
if (instance.removeListener) {
instance.removeListener('error', this._onError);
}
return this;

@@ -170,6 +228,10 @@ };

//
// function profile (id, [msg, meta, callback])
// Tracks the time inbetween subsequent calls to this method
// with the same [id] parameter. The second call to this method
// will log the difference in milliseconds along with the message.
// ### function profile (id, [msg, meta, callback])
// #### @id {string} Unique id of the profiler
// #### @msg {string} **Optional** Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} **Optional** Continuation to respond to when complete.
// Tracks the time inbetween subsequent calls to this method
// with the same `id` parameter. The second call to this method
// will log the difference in milliseconds along with the message.
//

@@ -185,6 +247,6 @@ Logger.prototype.profile = function (id) {

// Support variable arguments: msg, meta, callback
args = Array.prototype.slice.call(arguments);
args = Array.prototype.slice.call(arguments);
callback = typeof args[args.length - 1] === 'function' ? args.pop() : null;
meta = typeof args[args.length - 1] === 'object' ? args.pop() : {};
msg = args.length === 2 ? args[1] : id;
meta = typeof args[args.length - 1] === 'object' ? args.pop() : {};
msg = args.length === 2 ? args[1] : id;

@@ -198,12 +260,25 @@ // Set the duration property of the metadata

}
return this;
};
Logger.prototype.setLevels = function (current) {
return utils.setLevels(this, this.levels, current);
//
// ### function setLevels (target)
// #### @target {Object} Target levels to use on this instance
// Sets the `target` levels specified on this instance.
//
Logger.prototype.setLevels = function (target) {
return internal.setLevels(this, this.levels, target);
};
//
// ### function cli ()
// Configures this instance to have the default
// settings for command-line interfaces: no timestamp,
// colors enabled, padded output, and additional levels.
//
Logger.prototype.cli = function () {
this.padLevels = true;
this.setLevels(winston.config.cli.levels);
winston.config.addColors(winston.config.cli.colors);
this.setLevels(config.cli.levels);
config.addColors(config.cli.colors);

@@ -214,2 +289,17 @@ if (this.transports.console) {

}
return this;
};
//
// ### @private function _onError (transport, err)
// #### @transport {Object} Transport on which the error occured
// #### @err {Error} Error that occurred on the transport
// Bubbles the error, `err`, that occured on the specified `transport`
// up from this instance if `emitErrs` has been set.
//
Logger.prototype._onError = function (transport, err) {
if (self.emitErrs) {
self.emit('error', err, transport);
}
};

@@ -9,8 +9,21 @@ /*

var fs = require('fs'),
path = require('path');
var transports = exports;
transports.Console = require('./transports/console').Console;
transports.File = require('./transports/file').File;
transports.Loggly = require('./transports/loggly').Loggly;
transports.Riak = require('./transports/riak').Riak;
transports.MongoDB = require('./transports/mongodb').MongoDB;
function capitalize (str) {
return str && str[0].toUpperCase() + str.slice(1);
};
//
// Setup all transports as lazy-loaded getters.
//
fs.readdirSync(path.join(__dirname, 'transports')).forEach(function (file) {
var transport = file.replace('.js', ''),
name = capitalize(transport);
transports.__defineGetter__(name, function () {
return require('./transports/' + transport)[name];
});
});

@@ -9,40 +9,60 @@ /*

var util = require('util'),
var events = require('events'),
util = require('util'),
colors = require('colors'),
log = require('./../utils').log;
log = require('../internal').log;
//
// function Console (options)
// Constructor for the Console transport object.
// ### function Console (options)
// #### @options {Object} Options for this instance.
// Constructor function for the Console transport object responsible
// for persisting log messages and metadata to a terminal or TTY.
//
var Console = exports.Console = function (options) {
events.EventEmitter.call(this);
options = options || {};
this.name = 'console';
this.level = options.level || 'info';
this.silent = options.silent || false;
this.colorize = options.colorize || false;
this.timestamp = options.timestamp || true;
this.name = 'console';
this.level = options.level || 'info';
this.silent = options.silent || false;
this.colorize = options.colorize || false;
this.timestamp = options.timestamp === true;
};
//
// function log (level, msg, [meta], callback)
// Core logging method exposed to Winston. Metadata is optional.
// Inherit from `events.EventEmitter`.
//
util.inherits(Console, events.EventEmitter);
//
// Expose the name of this Transport on the prototype
//
Console.prototype.name = 'console';
//
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
// #### @msg {string} Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} Continuation to respond to when complete.
// Core logging method exposed to Winston. Metadata is optional.
//
Console.prototype.log = function (level, msg, meta, callback) {
if (!this.silent) {
var output = log(level, msg, meta, {
colorize: this.colorize,
timestamp: this.timestamp
});
if (this.silent) {
return callback(null, true);
}
if (level === 'error' || level === 'debug') {
util.error(output);
}
else {
util.puts(output);
}
var output = log(level, msg, meta, {
colorize: this.colorize,
timestamp: this.timestamp
});
if (level === 'error' || level === 'debug') {
util.error(output);
}
else {
util.puts(output);
}
callback(null, true);
};

@@ -9,41 +9,268 @@ /*

var util = require('util'),
var events = require('events'),
fs = require('fs'),
path = require('path'),
util = require('util'),
colors = require('colors'),
log = require('./../utils').log;
log = require('../internal').log;
//
// function File (options)
// Constructor for the File transport object.
// ### function File (options)
// #### @options {Object} Options for this instance.
// Constructor function for the File transport object responsible
// for persisting log messages and metadata to one or more files.
//
var File = exports.File = function (options) {
options = options || {}
events.EventEmitter.call(this);
options = options || {};
if (options.filename) this.stream = fs.createWriteStream(options.filename, options.options || { flags: 'a' });
else if (options.stream) this.stream = options.stream;
else throw new Error('Cannot log to file without filename or stream.');
//
// Helper function which throws an `Error` in the event
// that any of the rest of the arguments is present in `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');
}
});
}
if (options.filename || options.dirname) {
throwIf('filename or dirname', 'stream');
this._basename = this.filename = path.basename(options.filename) || 'winston.log';
this.dirname = options.dirname || path.dirname(options.filename);
this.options = options.options || { flags: 'a' };
}
else if (options.stream) {
throwIf('stream', 'filename', 'maxsize');
this.stream = options.stream;
}
else {
throw new Error('Cannot log to file without filename or stream.');
}
this.name = 'file';
this.level = options.level || 'info';
this.silent = options.silent || false;
this.colorize = options.colorize || false;
this.timestamp = options.timestamp || true;
this.level = options.level || 'info';
this.silent = options.silent || false;
this.colorize = options.colorize || false;
this.timestamp = options.timestamp === true;
this.maxsize = options.maxsize || null;
//
// Internal state variables representing the number
// of files this instance has created and the current
// size (in bytes) of the current logfile.
//
this._size = 0;
this._created = 0;
this._buffer = [];
};
//
// function log (level, msg, [meta], callback)
// Core logging method exposed to Winston. Metadata is optional.
// Inherit from `events.EventEmitter`.
//
util.inherits(File, events.EventEmitter);
//
// Expose the name of this Transport on the prototype
//
File.prototype.name = 'file';
//
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
// #### @msg {string} Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} Continuation to respond to when complete.
// Core logging method exposed to Winston. Metadata is optional.
//
File.prototype.log = function (level, msg, meta, callback) {
if (!this.silent) {
var output = log(level, msg, meta, {
colorize: this.colorize,
timestamp: this.timestamp
});
output += '\n';
if (this.silent) {
return callback(null, true);
}
var self = this, output = log(level, msg, meta, {
colorize: this.colorize,
timestamp: this.timestamp
}) + '\n';
this._size += output.length;
if (!this.filename) {
//
// If there is no `filename` on this instance then it was configured
// with a raw `WriteableStream` instance and we should not perform any
// size restrictions.
//
this.stream.write(output);
}
else {
this.open(function (err) {
if (err) {
//
// If there was an error enqueue the message
//
return self._buffer.push(output);
}
self.stream.write(output);
});
}
callback(null, true);
};
//
// ### function open (callback)
// #### @callback {function} Continuation to respond to when complete
// Checks to see if a new file needs to be created based on the `maxsize`
// (if any) and the current size of the file used.
//
File.prototype.open = function (callback) {
if (this.opening) {
//
// If we are already attempting to open the next
// available file then respond with a value indicating
// that the message should be buffered.
//
return callback(true);
}
else if (!this.stream || (this.maxsize && this._size >= this.maxsize)) {
//
// If we dont have a stream or have exceeded our size, then create
// the next stream and respond with a value indicating that
// the message should be buffered.
//
this._createStream();
return callback(true);
}
//
// Otherwise we have a valid (and ready) stream.
//
callback();
};
//
// ### function flush ()
// Flushes any buffered messages to the current `stream`
// used by this instance.
//
File.prototype.flush = function () {
var self = this;
//
// Iterate over the `_buffer` of enqueued messaged
// and then write them to the newly created stream.
//
this._buffer.forEach(function (str) {
process.nextTick(function () {
self.stream.write(str);
self._size += str.length;
});
});
//
// Quickly truncate the `_buffer` once the write operations
// have been started
//
self._buffer.length = 0;
//
// When the stream has drained we have flushed
// our buffer.
//
self.stream.once('drain', function () {
self.emit('flush');
});
};
//
// ### @private function _createStream ()
// Attempts to open the next appropriate file for this instance
// based on the internal state (such as `maxsize` and `_basename`).
//
File.prototype._createStream = function () {
var self = this;
this.opening = true;
(function checkFile (target) {
var fullname = path.join(self.dirname, target);
//
// Creates the `WriteStream` and then flushes any
// buffered messages.
//
function createAndFlush (size) {
if (self.stream) {
self.stream.end();
self.stream.destroySoon();
}
self._size = size;
self.filename = target;
self.stream = fs.createWriteStream(fullname, self.options);
//
// When the current stream has finished flushing
// then we can be sure we have finished opening
// and thus can emit the `open` event.
//
self.once('flush', function () {
self.opening = false;
self.emit('open', fullname);
});
//
// Remark: It is possible that in the time it has taken to find the
// next logfile to be written more data than `maxsize` has been buffered,
// but for sensible limits (10s - 100s of MB) this seems unlikely in less
// than one second.
//
self.flush();
}
fs.stat(fullname, function (err, stats) {
if (err) {
if (err.code !== 'ENOENT') {
return self.emit('error', err);
}
return createAndFlush(0);
}
if (!stats || (self.maxsize && stats.size >= self.maxsize)) {
//
// If `stats.size` is greater than the `maxsize` for
// this instance then try again
//
return checkFile(self._getFile(true));
}
createAndFlush(stats.size);
});
})(this._getFile());
};
//
// ### @private function _getFile ()
// Gets the next filename to use for this instance
// in the case that log filesizes are being capped.
//
File.prototype._getFile = function (inc) {
var self = this,
ext = path.extname(this._basename),
basename = path.basename(this._basename, ext);
if (inc) {
//
// Increment the number of files created or
// checked by this instance.
//
this._created += 1;
}
return this._created
? basename + this._created + ext
: basename + ext;
};

@@ -9,15 +9,29 @@ /*

var loggly = require('loggly'),
utils = require('./../utils');
var events = require('events'),
loggly = require('loggly'),
util = require('util'),
internal = require('../internal');
//
// function Loggly (options)
// Constructor for the Loggly transport object.
// ### function Loggly (options)
// #### @options {Object} Options for this instance.
// Constructor function for the Loggly transport object responsible
// for persisting log messages and metadata to Loggly; 'LaaS'.
//
var Loggly = exports.Loggly = function (options) {
events.EventEmitter.call(this);
options = options || {};
if (!options.subdomain) throw new Error('Loggly Subdomain is required');
if (!options.inputToken && !options.inputName) throw new Error('Target input token or name is required.');
if (!options.auth && options.inputName) throw new Error('Loggly authentication is required');
if (!options.subdomain) {
throw new Error('Loggly Subdomain is required');
}
if (!options.inputToken && !options.inputName) {
throw new Error('Target input token or name is required.');
}
if (!options.auth && options.inputName) {
throw new Error('Loggly authentication is required');
}
this.name = 'loggly';

@@ -42,3 +56,5 @@ this.level = options.level || 'info';

this.client.getInput(this.inputName, function (err, input) {
if (err) throw err;
if (err) {
throw err;
}

@@ -52,30 +68,60 @@ self.inputToken = input.input_token;

//
// function log (level, msg, [meta], callback)
// Core logging method exposed to Winston. Metadata is optional.
// Inherit from `events.EventEmitter`.
//
util.inherits(Loggly, events.EventEmitter);
//
// Expose the name of this Transport on the prototype
//
Loggly.prototype.name = 'loggly';
//
// ### function log (level, msg, [meta], callback)
// #### @level {string} Level at which to log the message.
// #### @msg {string} Message to log
// #### @meta {Object} **Optional** Additional metadata to attach
// #### @callback {function} Continuation to respond to when complete.
// Core logging method exposed to Winston. Metadata is optional.
//
Loggly.prototype.log = function (level, msg, meta, callback) {
var message = utils.clone(meta);
if (this.silent) {
return callback(null, true);
}
var message = internal.clone(meta);
message.level = level;
message.message = msg;
// If we haven't gotten the input token yet
// add this message to the log buffer.
if (!this.ready) {
//
// If we haven't gotten the input token yet
// add this message to the log buffer.
//
this.logBuffer.push(message);
return callback(null, true);
}
// Otherwise if we have buffered messages
// add this message to the buffer and flush them.
if (this.ready && this.logBuffer.length > 0) {
else if (this.ready && this.logBuffer.length > 0) {
//
// Otherwise if we have buffered messages
// add this message to the buffer and flush them.
//
this.logBuffer.push(message);
return this.flush(callback);
this.flush();
}
else {
//
// Otherwise just log the message as normal
//
this.client.log(this.inputToken, message);
}
// Otherwise just log the message as normal
this.client.log(this.inputToken, message, callback);
callback(null, true);
};
Loggly.prototype.flush = function (callback) {
var self = this, flushed = 0,
//
// ### function flush ()
// Flushes any buffered messages to the current `stream`
// used by this instance.
//
Loggly.prototype.flush = function () {
var self = this,
length = this.logBuffer.length;

@@ -85,11 +131,11 @@

this.logBuffer.forEach(function (msg) {
process.nextTick(function () {
this.client.log(self.inputToken, msg, function () {
if (flushed++ === count) return callback(null, true);
});
self.client.log(self.inputToken, msg, function (err) {
if (err) {
self.emit('error', err);
}
});
});
// Then quickly truncate the list (thanks isaacs)
// Then quickly truncate the list
this.logBuffer.length = 0;
};
{
"name": "winston",
"description": "A multi-transport async logging library for Node.js",
"version": "0.2.11",
"version": "0.3.3",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",
"contributors": [
{ "name": "Matthew Bergman", "email": "mzbphoto@gmail.com" }
{ "name": "Matthew Bergman", "email": "mzbphoto@gmail.com" },
{ "name": "Marak Squires", "email": "marak@nodejitsu.com" }
],

@@ -18,4 +19,3 @@ "repository": {

"loggly": "0.3.x",
"riak-js": ">= 0.4.0rc2",
"mongodb": "0.9.x"
"pkginfo": "0.2.x"
},

@@ -22,0 +22,0 @@ "devDependencies": {

@@ -80,4 +80,4 @@ # winston

//
logger.log('info', '127.0.0.1 - there's no place like home');
logger.info('127.0.0.1 - there's no place like home');
logger.log('info', "127.0.0.1 - there's no place like home");
logger.info("127.0.0.1 - there's no place like home");

@@ -87,4 +87,4 @@ //

//
winston.log('info', '127.0.0.1 - there's no place like home');
winston.info('127.0.0.1 - there's no place like home');
winston.log('info', "127.0.0.1 - there's no place like home");
winston.info("127.0.0.1 - there's no place like home");
```

@@ -323,5 +323,36 @@

### Riak Transport
As of `0.3.0` the Riak transport has been broken out into a new module: [winston-riak][17]. Using it is just as easy:
``` js
var Riak = require('winston-riak').Riak;
winston.add(Riak, options);
```
In addition to the options accepted by the [riak-js][3] [client][4], the Riak transport also accepts the following options. It is worth noting that the riak-js debug option is set to *false* by default:
* __level:__ Level of messages that this transport should log.
* __bucket:__ The name of the Riak bucket you wish your logs to be in or a function to generate bucket names dynamically.
``` js
// Use a single bucket for all your logs
var singleBucketTransport = new (Riak)({ bucket: 'some-logs-go-here' });
// Generate a dynamic bucket based on the date and level
var dynamicBucketTransport = new (Riak)({
bucket: function (level, msg, meta, now) {
var d = new Date(now);
return level + [d.getDate(), d.getMonth(), d.getFullYear()].join('-');
}
});
```
*Metadata:* Logged as JSON literal in Riak
### MongoDB Transport
As of `0.3.0` the MongoDB transport has been broken out into a new module: [winston-mongodb][16]. Using it is just as easy:
``` js
winston.add(winston.transports.MongoDB, options);
var MongoDB = require('winston-mongoDB').MongoDB;
winston.add(MongoDB, options);
```

@@ -341,3 +372,2 @@

### Adding Custom Transports

@@ -389,3 +419,3 @@ Adding a custom transport (say for one of the datastore on the Roadmap) is actually pretty easy. All you need to do is accept a couple of options, set a name, implement a log() method, and add it to the set of transports exposed by winston.

3. Create API for reading from logs across all transports.
4. Add more transports: CouchDB, Redis
4. Add more transports: Redis

@@ -417,3 +447,3 @@ ## Run Tests

#### Author: [Charlie Robbins](http://twitter.com/indexzero)
#### Contributors: [Matthew Bergman](http://github.com/fotoverite)
#### Contributors: [Matthew Bergman](http://github.com/fotoverite), [Marak Squires](http://github.com/marak)

@@ -435,2 +465,4 @@ [0]: https://github.com/isaacs/npm/blob/master/lib/utils/log.js

[14]: http://nodejs.org/docs/v0.3.5/api/streams.html#writable_Stream
[15]: http://github.com/nodejitsu/require-analyzer
[15]: http://github.com/nodejitsu/require-analyzer
[16]: http://github.com/indexzero/winston-mongodb
[17]: http://github.com/indexzero/winston-riak

@@ -9,8 +9,6 @@ /*

require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('winston'),
winston = require('../lib/winston'),
helpers = require('./helpers');

@@ -17,0 +15,0 @@

@@ -9,8 +9,6 @@ /*

require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('winston'),
winston = require('../lib/winston'),
helpers = require('./helpers');

@@ -17,0 +15,0 @@

/*
* console-test.js: Tests for instances of the Console transport
* file-test.js: Tests for instances of the File transport
*

@@ -9,4 +9,2 @@ * (C) 2010 Charlie Robbins

require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var path = require('path'),

@@ -16,10 +14,10 @@ vows = require('vows'),

assert = require('assert'),
winston = require('winston'),
winston = require('../lib/winston'),
helpers = require('./helpers');
var stream = fs.createWriteStream(path.join(__dirname, 'testfile.log')),
fileTransport = new (winston.transports.File)({ filename: path.join(__dirname, 'testfilename.log') }),
var stream = fs.createWriteStream(path.join(__dirname, 'fixtures', 'testfile.log')),
fileTransport = new (winston.transports.File)({ filename: path.join(__dirname, 'fixtures', 'testfilename.log') }),
streamTransport = new (winston.transports.File)({ stream: stream });
vows.describe('winston/transports/console').addBatch({
vows.describe('winston/transports/file').addBatch({
"An instance of the File Transport": {

@@ -45,2 +43,11 @@ "when passed a valid filename": {

}
}).addBatch({
"These tests have a non-deterministic end": {
topic: function () {
setTimeout(this.callback, 200);
},
"and this should be fixed before releasing": function () {
assert.isTrue(true);
}
}
}).export(module);

@@ -9,4 +9,2 @@ /*

require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var fs = require('fs'),

@@ -17,3 +15,3 @@ util = require('util'),

assert = require('assert'),
winston = require('winston'),
winston = require('../lib/winston'),
loggly = require('loggly')

@@ -23,7 +21,7 @@

helpers.loadConfig = function () {
helpers.loadConfig = function (dir) {
try {
if (helpers.config) return helpers.config;
var configFile = path.join(__dirname, 'test-config.json'),
stats = fs.statSync(configFile)
var configFile = path.join(dir || __dirname, 'fixtures', 'test-config.json'),
stats = fs.statSync(configFile),
config = JSON.parse(fs.readFileSync(configFile).toString());

@@ -35,3 +33,3 @@

catch (ex) {
util.puts('Config file test-config.json must be created with valid data before running tests');
util.puts('test/fixtures/test-config.json must be created with valid data before running tests');
process.exit(0);

@@ -44,3 +42,5 @@ }

for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
if (obj.hasOwnProperty(key)) {
size++;
}
}

@@ -77,12 +77,7 @@

helpers.assertRiak = function (transport) {
assert.instanceOf(transport, winston.transports.Riak);
helpers.assertWebhook = function (transport) {
assert.instanceOf(transport, winston.transports.Webhook);
assert.isFunction(transport.log);
};
helpers.assertMongoDB = function (transport) {
assert.instanceOf(transport, winston.transports.MongoDB);
assert.isFunction(transport.log);
};
helpers.testNpmLevels = function (transport, assertMsg, assertFn) {

@@ -89,0 +84,0 @@ return helpers.testLevels(winston.config.npm.levels, transport, assertMsg, assertFn);

@@ -9,8 +9,6 @@ /*

require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('winston'),
winston = require('../lib/winston'),
helpers = require('./helpers');

@@ -105,3 +103,3 @@

return logger.add(winston.transports.File, {
filename: path.join(__dirname, 'testfile2.log')
filename: path.join(__dirname, 'fixtures', 'testfile2.log')
});

@@ -122,3 +120,3 @@ },

new (winston.transports.Console)(),
new (winston.transports.File)({ filename: path.join(__dirname, 'filelog.log' )})
new (winston.transports.File)({ filename: path.join(__dirname, 'fixtures', 'filelog.log' )})
]

@@ -125,0 +123,0 @@ }),

@@ -9,10 +9,8 @@ /*

require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('winston'),
winston = require('../lib/winston'),
helpers = require('./helpers');
var config = helpers.loadConfig(),

@@ -35,6 +33,5 @@ tokenTransport = new (winston.transports.Loggly)({

},
"the log() method": helpers.testNpmLevels(tokenTransport, "should log messages to loggly", function (ign, err, result) {
"the log() method": helpers.testNpmLevels(tokenTransport, "should log messages to loggly", function (ign, err, logged) {
assert.isNull(err);
assert.isObject(result);
assert.equal(result.response, 'ok');
assert.isTrue(logged);
})

@@ -41,0 +38,0 @@ },

@@ -9,14 +9,14 @@ /*

require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var path = require('path'),
var fs = require('fs'),
path = require('path'),
vows = require('vows'),
http = require('http'),
assert = require('assert'),
winston = require('winston'),
winston = require('../lib/winston'),
helpers = require('./helpers');
vows.describe('winston').addBatch({
"The winston module": {
topic: function () {
winston.defaultTransports().console.level = 'silly';
winston.defaultTransports.console.level = 'silly';
return null;

@@ -28,7 +28,6 @@ },

assert.isFunction(winston.transports.Loggly);
//assert.isFunction(winston.transports.Riak);
assert.isObject(winston.defaultTransports().console);
assert.isObject(winston.defaultTransports.console);
assert.isFalse(winston.emitErrs);
assert.isObject(winston.config);
['Logger', 'defaultTransports', 'add', 'remove', 'extend']
['Logger', 'add', 'remove', 'extend']
.concat(Object.keys(winston.config.npm.levels))

@@ -39,2 +38,12 @@ .forEach(function (key) {

},
"it should": {
topic: function () {
fs.readFile(path.join(__dirname, '..', 'package.json'), this.callback);
},
"have the correct version set": function (err, data) {
assert.isNull(err);
data = JSON.parse(data.toString());
assert.equal(winston.version, data.version);
}
},
"the log() method": helpers.testNpmLevels(winston, "should respond without an error", function (err) {

@@ -67,4 +76,4 @@ assert.isNull(err);

assert.isFunction(winston.transports.Loggly);
//assert.isFunction(winston.transports.Riak);
assert.isObject(winston.defaultTransports().console);
assert.isFunction(winston.transports.Webhook);
assert.isObject(winston.defaultTransports.console);
assert.isFalse(winston.emitErrs);

@@ -74,3 +83,3 @@ assert.isObject(winston.config);

var newLevels = Object.keys(winston.config.syslog.levels);
['Logger', 'defaultTransports', 'add', 'remove', 'extend']
['Logger', 'add', 'remove', 'extend']
.concat(newLevels)

@@ -77,0 +86,0 @@ .forEach(function (key) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc