Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caterpillar

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caterpillar - npm Package Compare versions

Comparing version 2.0.6 to 2.0.7

example-browser.html

28

example.js
// Import
var level = process.argv.indexOf('-d') === -1 ? 6 : 7;
var logger = require('./').createLogger({level:level});
var filter = require('caterpillar-filter').createFilter();
var human = require('caterpillar-human').createHuman();
var level = process.argv.indexOf('-d') === -1 ? 6 : 7;
var logger = require('caterpillar').createLogger({level:level});
var filter = require('caterpillar-filter').createFilter();
var human = require('caterpillar-human').createHuman();
// Pipe logger output to filter, then filter output to stdout
logger.pipe(filter).pipe(human).pipe(process.stdout);
// Where to output?
if ( process.title === 'browser' ) {
// Include the browser compatibility layer
var browser = require('caterpillar-browser').createBrowser();
// If we are debugging, then write the original logger data to debug.log
if ( level === 7 ) {
logger.pipe(require('fs').createWriteStream('./debug.log'));
// Pipe to filter to human to browser
logger.pipe(filter).pipe(human).pipe(browser);
}
else {
// Pipe to filter to human to stdout
logger.pipe(filter).pipe(human).pipe(process.stdout);
// If we are debugging, then write the original logger data to debug.log
if ( level === 7 ) {
logger.pipe(require('fs').createWriteStream('./debug.log'));
}
}
// Log messages

@@ -16,0 +26,0 @@ logger.log('emergency', 'this is level 0');

// Generated by CoffeeScript 1.6.3
var Logger, Transform, extendr, stream, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice;
(function() {
var Logger, Transform, extendr, stream, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice;
extendr = require('extendr');
extendr = require('extendr');
stream = require('readable-stream');
stream = require('stream');
Transform = (function(_super) {
__extends(Transform, _super);
if ((stream.Transform != null) === false) {
stream = require('readable-stream');
}
Transform.prototype.config = null;
Transform = (function(_super) {
__extends(Transform, _super);
function Transform(opts) {
this._transform = __bind(this._transform, this);
this.setConfig = __bind(this.setConfig, this);
this.config = extendr.deepClone(this.config);
this.setConfig(opts);
Transform.__super__.constructor.apply(this, arguments);
}
Transform.prototype.config = null;
Transform.prototype.pipe = function(child) {
if (typeof child.setConfig === "function" ? child.setConfig(this.config) : void 0) {
this.on('config', child.setConfig);
function Transform(opts) {
this._transform = __bind(this._transform, this);
this.setConfig = __bind(this.setConfig, this);
this.pipe = __bind(this.pipe, this);
this.config = extendr.deepClone(this.config);
this.setConfig(opts);
Transform.__super__.constructor.apply(this, arguments);
}
return Transform.__super__.pipe.apply(this, arguments);
};
Transform.prototype.setConfig = function(opts) {
extendr.deepExtend(this.config, opts);
this.emit('config', this.config);
return this;
};
Transform.prototype.pipe = function(child) {
if (typeof child.setConfig === "function" ? child.setConfig(this.config) : void 0) {
this.on('config', child.setConfig);
}
return Transform.__super__.pipe.apply(this, arguments);
};
Transform.prototype.getConfig = function() {
return this.config;
};
Transform.prototype.setConfig = function(opts) {
extendr.deepExtend(this.config, opts);
this.emit('config', this.config);
return this;
};
Transform.prototype._transform = function(chunk, encoding, next) {
var entry, message;
entry = JSON.parse(chunk.toString());
message = this.format(entry);
if (message) {
message = JSON.stringify(message);
}
return next(null, message);
};
Transform.prototype.getConfig = function() {
return this.config;
};
Transform.prototype.format = function(entry) {
return entry;
};
Transform.prototype._transform = function(chunk, encoding, next) {
var entry, message;
entry = JSON.parse(chunk.toString());
message = this.format(entry);
if (message) {
message = JSON.stringify(message);
}
return next(null, message);
};
return Transform;
Transform.prototype.format = function(entry) {
return entry;
};
})(stream.Transform);
return Transform;
Logger = (function(_super) {
__extends(Logger, _super);
})(stream.Transform);
function Logger() {
this.log = __bind(this.log, this);
_ref = Logger.__super__.constructor.apply(this, arguments);
return _ref;
}
Logger = (function(_super) {
__extends(Logger, _super);
Logger.prototype.config = {
lineOffset: 0,
levels: {
emergency: 0,
alert: 1,
critical: 2,
error: 3,
warning: 4,
notice: 5,
info: 6,
debug: 7,
emerg: 0,
crit: 2,
err: 3,
warn: 4,
note: 5,
"default": 6
function Logger() {
this.log = __bind(this.log, this);
_ref = Logger.__super__.constructor.apply(this, arguments);
return _ref;
}
};
Logger.prototype._transform = function(chunk, encoding, next) {
return next(null, chunk);
};
Logger.prototype.config = {
lineOffset: 0,
levels: {
emergency: 0,
alert: 1,
critical: 2,
error: 3,
warning: 4,
notice: 5,
info: 6,
debug: 7,
emerg: 0,
crit: 2,
err: 3,
warn: 4,
note: 5,
"default": 6
}
};
Logger.prototype.getLevelNumber = function(name) {
var _ref1;
return (_ref1 = this.config.levels[name]) != null ? _ref1 : null;
};
Logger.prototype._transform = function(chunk, encoding, next) {
return next(null, chunk);
};
Logger.prototype.getLevelName = function(number) {
var key, value, _ref1;
_ref1 = this.config.levels;
for (key in _ref1) {
if (!__hasProp.call(_ref1, key)) continue;
value = _ref1[key];
if (value === number) {
return key;
Logger.prototype.getLevelNumber = function(name) {
var _ref1;
return (_ref1 = this.config.levels[name]) != null ? _ref1 : null;
};
Logger.prototype.getLevelName = function(number) {
var key, value, _ref1;
_ref1 = this.config.levels;
for (key in _ref1) {
if (!__hasProp.call(_ref1, key)) continue;
value = _ref1[key];
if (value === number) {
return key;
}
}
}
return null;
};
return null;
};
Logger.prototype.getLevelInfo = function(level) {
var levelName, levelNumber, result;
result = {
levelNumber: null,
levelName: null,
defaulted: false
};
if (typeof level === 'number') {
levelNumber = level;
levelName = this.getLevelName(levelNumber);
} else {
levelName = level;
levelNumber = this.getLevelNumber(levelName);
levelName = this.getLevelName(levelNumber);
if (levelNumber == null) {
levelNumber = this.getLevelNumber('default');
Logger.prototype.getLevelInfo = function(level) {
var levelName, levelNumber, result;
result = {
levelNumber: null,
levelName: null,
defaulted: false
};
if (typeof level === 'number') {
levelNumber = level;
levelName = this.getLevelName(levelNumber);
result.defaulted = true;
} else {
levelName = level;
levelNumber = this.getLevelNumber(levelName);
levelName = this.getLevelName(levelNumber);
if (levelNumber == null) {
levelNumber = this.getLevelNumber('default');
levelName = this.getLevelName(levelNumber);
result.defaulted = true;
}
}
}
result.levelNumber = levelNumber;
result.levelName = levelName;
return result;
};
result.levelNumber = levelNumber;
result.levelName = levelName;
return result;
};
Logger.prototype.getLineInfo = function() {
var err, line, lines, offset, parts, result, _i, _len, _ref1;
result = {
line: -1,
method: 'unknown',
file: 'unknown'
Logger.prototype.getLineInfo = function() {
var err, line, lines, offset, parts, result, _i, _len, _ref1;
result = {
line: -1,
method: 'unknown',
file: 'unknown'
};
err = new Error();
lines = ((_ref1 = err.stack) != null ? _ref1.split('\n') : void 0) || [];
offset = this.config.lineOffset;
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
if (line.indexOf(__dirname) !== -1 || line.indexOf(' at ') === -1) {
continue;
}
if (offset !== 0) {
--offset;
continue;
}
parts = line.split(':');
if (parts[0].indexOf('(') === -1) {
result.method = 'unknown';
result.file = parts[0].replace(/^.+?\s+at\s+/, '');
} else {
result.method = parts[0].replace(/^.+?\s+at\s+/, '').replace(/\s+\(.+$/, '');
result.file = parts[0].replace(/^.+?\(/, '');
}
result.line = parts[1];
break;
}
return result;
};
err = new Error();
lines = ((_ref1 = err.stack) != null ? _ref1.split('\n') : void 0) || [];
offset = this.config.lineOffset;
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
if (line.indexOf(__dirname) !== -1 || line.indexOf(' at ') === -1) {
continue;
Logger.prototype.format = function() {
var args, entry, level, levelInfo, lineInfo;
level = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
entry = {};
entry.date = new Date().toISOString();
levelInfo = this.getLevelInfo(level);
lineInfo = this.getLineInfo(level);
if (levelInfo.defaulted && level !== 'default') {
args.unshift(level);
}
if (offset !== 0) {
--offset;
continue;
}
parts = line.split(':');
if (parts[0].indexOf('(') === -1) {
result.method = 'unknown';
result.file = parts[0].replace(/^.+?\s+at\s+/, '');
} else {
result.method = parts[0].replace(/^.+?\s+at\s+/, '').replace(/\s+\(.+$/, '');
result.file = parts[0].replace(/^.+?\(/, '');
}
result.line = parts[1];
break;
}
return result;
};
delete levelInfo.defaulted;
entry.args = args;
extendr.extend(entry, levelInfo, lineInfo);
return entry;
};
Logger.prototype.format = function() {
var args, entry, level, levelInfo, lineInfo;
level = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
entry = {};
entry.date = new Date().toISOString();
levelInfo = this.getLevelInfo(level);
lineInfo = this.getLineInfo(level);
if (levelInfo.defaulted && level !== 'default') {
args.unshift(level);
}
delete levelInfo.defaulted;
entry.args = args;
extendr.extend(entry, levelInfo, lineInfo);
return entry;
};
Logger.prototype.log = function() {
var args, entry, entryString;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
entry = this.format.apply(this, args);
this.emit('log', entry);
entryString = JSON.stringify(entry);
this.write(entryString);
return this;
};
Logger.prototype.log = function() {
var args, entry, entryString;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
entry = this.format.apply(this, args);
this.emit('log', entry);
entryString = JSON.stringify(entry);
this.write(entryString);
return this;
};
return Logger;
return Logger;
})(Transform);
})(Transform);
module.exports = {
Transform: Transform,
Logger: Logger,
createTransform: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Transform, args, function(){});
},
createLogger: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Logger, args, function(){});
}
};
module.exports = {
Transform: Transform,
Logger: Logger,
createTransform: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Transform, args, function(){});
},
createLogger: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Logger, args, function(){});
}
};
}).call(this);
{
"title": "Caterpillar",
"name": "caterpillar",
"version": "2.0.6",
"version": "2.0.7",
"description": "Caterpillar is the ultimate logging system for Node.js, based on transform streams you can log to it and pipe the output off to different locations, including some pre-made ones. Caterpillar also supports log levels according to the RFC standard, as well as line, method, and file fetching for messages. You can even use it in web browsers with caterpillar-browser.",
"homepage": "https://github.com/bevry/caterpillar",
"license": {
"type": "MIT"
},
"badges": {
"travis": true,
"npm": true,
"gittip": "bevry",
"flattr": "344188/balupton-on-Flattr",
"paypal": "QB8GQPZAH84N6"
},
"keywords": [

@@ -35,2 +45,3 @@ "caterpillar",

},
"browsers": true,
"dependencies": {

@@ -43,6 +54,8 @@ "extendr": "~2.1.0",

"caterpillar-human": "2.x",
"coffee-script": "~1.6.2",
"caterpillar-browser": "2.x",
"coffee-script": "~1.6.3",
"joe": "~1.3.0",
"joe-reporter-console": "~1.2.1",
"chai": "~1.8.1"
"chai": "~1.8.1",
"projectz": "~0.3.0"
},

@@ -53,15 +66,7 @@ "directories": {

"scripts": {
"test": "node ./out/test/caterpillar-test.js"
"test": "node ./out/test/caterpillar-test.js",
"browserify": "browserify -e example.js > example-browser.js",
"webpack": "webpack --progress --colors ./example.js example-browser.js"
},
"main": "./out/lib/caterpillar.js",
"license": {
"type": "MIT"
},
"badges": {
"travis": true,
"npm": true,
"gittip": "bevry",
"flattr": "344188/balupton-on-Flattr",
"paypal": "QB8GQPZAH84N6"
}
"main": "./out/lib/caterpillar.js"
}

@@ -12,6 +12,6 @@

[![Build Status](http://img.shields.io/travis-ci/bevry/caterpillar.png?branch=master)](http://travis-ci.org/bevry/caterpillar "Check this project's build status on TravisCI")
[![NPM version](https://badge.fury.io/js/caterpillar.png)](https://npmjs.org/package/caterpillar "View this project on NPM")
[![NPM version](http://badge.fury.io/js/caterpillar.png)](https://npmjs.org/package/caterpillar "View this project on NPM")
[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip")
[![Flattr donate button](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](https://www.paypalobjects.com/en_AU/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")

@@ -28,6 +28,11 @@ <!-- /BADGES -->

### [Node](http://nodejs.org/), [Browserify](http://browserify.org/)
### [Node](http://nodejs.org/)
- Use: `require('caterpillar')`
- Install: `npm install --save caterpillar`
### [Browserify](http://browserify.org/)
- Use: `require('caterpillar')`
- Install: `npm install --save caterpillar`
- CDN URL: `//wzrd.in/bundle/caterpillar@2.0.7`
### [Ender](http://ender.jit.su/)

@@ -46,15 +51,25 @@ - Use: `require('caterpillar')`

// Import
var level = process.argv.indexOf('-d') === -1 ? 6 : 7;
var logger = require('caterpillar').createLogger({level:level});
var filter = require('caterpillar-filter').createFilter();
var human = require('caterpillar-human').createHuman();
var level = process.argv.indexOf('-d') === -1 ? 6 : 7;
var logger = require('caterpillar').createLogger({level:level});
var filter = require('caterpillar-filter').createFilter();
var human = require('caterpillar-human').createHuman();
// Pipe logger output to filter, then filter output to stdout
logger.pipe(filter).pipe(human).pipe(process.stdout);
// Where to output?
if ( process.title === 'browser' ) {
// Include the browser compatibility layer
var browser = require('caterpillar-browser').createBrowser();
// If we are debugging, then write the original logger data to debug.log
if ( level === 7 ) {
logger.pipe(require('fs').createWriteStream('./debug.log'));
// Pipe to filter to human to browser
logger.pipe(filter).pipe(human).pipe(browser);
}
else {
// Pipe to filter to human to stdout
logger.pipe(filter).pipe(human).pipe(process.stdout);
// If we are debugging, then write the original logger data to debug.log
if ( level === 7 ) {
logger.pipe(require('fs').createWriteStream('./debug.log'));
}
}
// Log messages

@@ -173,3 +188,3 @@ logger.log('emergency', 'this is level 0');

## History
[Discover the change history by heading on over to the `History.md` file.](https://github.com/bevry/caterpillar/blob/master/History.md#files)
[Discover the change history by heading on over to the `HISTORY.md` file.](https://github.com/bevry/caterpillar/blob/master/HISTORY.md#files)

@@ -194,4 +209,4 @@ <!-- /HISTORY -->

[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip")
[![Flattr donate button](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](https://www.paypalobjects.com/en_AU/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")

@@ -205,3 +220,3 @@ ### Contributors

[Become a contributor!](https://github.com/bevry/caterpillar/blob/master/Contributing.md#files)
[Become a contributor!](https://github.com/bevry/caterpillar/blob/master/CONTRIBUTING.md#files)

@@ -208,0 +223,0 @@ <!-- /BACKERS -->

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc