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 1.1.4 to 2.0.0

example.js

206

out/lib/caterpillar.js
// Generated by CoffeeScript 1.6.2
var ConsoleFormatter, ConsoleTransport, Formatter, Logger, Transport, cliColor, _ref, _ref1;
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;
_ref = require(__dirname + '/formatter'), cliColor = _ref.cliColor, Formatter = _ref.Formatter, ConsoleFormatter = _ref.ConsoleFormatter;
extendr = require('extendr');
Logger = require(__dirname + '/logger').Logger;
stream = require('stream');
_ref1 = require(__dirname + '/transport'), Transport = _ref1.Transport, ConsoleTransport = _ref1.ConsoleTransport;
Transform = (function(_super) {
__extends(Transform, _super);
Transform.prototype.config = null;
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.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.setConfig = function(opts) {
extendr.deepExtend(this.config, opts);
this.emit('config', this.config);
return this;
};
Transform.prototype.getConfig = function() {
return this.config;
};
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.format = function(entry) {
return entry;
};
return Transform;
})(stream.Transform);
Logger = (function(_super) {
__extends(Logger, _super);
function Logger() {
_ref = Logger.__super__.constructor.apply(this, arguments);
return _ref;
}
Logger.prototype.config = {
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._transform = function(chunk, encoding, next) {
return next(null, chunk);
};
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;
};
Logger.prototype.getLevelInfo = function(level) {
var levelName, levelNumber, result;
result = {
levelNumber: null,
levelName: null
};
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');
levelName = this.getLevelName(levelNumber);
}
}
result.levelNumber = levelNumber;
result.levelName = levelName;
return result;
};
Logger.prototype.getLineInfo = function() {
var err, line, lines, parts, result, _i, _len;
result = {
line: -1,
method: 'unknown',
file: 'unknown'
};
err = new Error();
lines = err.stack.split('\n');
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
if (line.indexOf(__dirname) !== -1 || line.indexOf(' at ') === -1) {
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;
};
Logger.prototype.format = function() {
var args, entry, key, level, value, _ref1, _ref2;
level = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
entry = {};
entry.args = args;
entry.date = new Date().toISOString();
_ref1 = this.getLevelInfo(level);
for (key in _ref1) {
if (!__hasProp.call(_ref1, key)) continue;
value = _ref1[key];
entry[key] = value;
}
_ref2 = this.getLineInfo(level);
for (key in _ref2) {
if (!__hasProp.call(_ref2, key)) continue;
value = _ref2[key];
entry[key] = value;
}
return entry;
};
Logger.prototype.log = function() {
var args, entry, entryString, level;
level = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
entry = this.format.apply(this, [level].concat(__slice.call(args)));
entryString = JSON.stringify(entry);
this.write(entryString);
return this;
};
return Logger;
})(Transform);
module.exports = {
cliColor: cliColor,
Formatter: Formatter,
ConsoleFormatter: ConsoleFormatter,
Logger: Logger,
Transport: Transport,
ConsoleTransport: ConsoleTransport
Transform: Transform,
Logger: Logger
};

246

out/lib/formatter.js
// Generated by CoffeeScript 1.6.2
var ConsoleFormatter, Formatter, cliColor, err, util, _ref,
var Filter, Human, cliColor, create, err, extendr, stream, util,
__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; };
extendr = require('extendr');
stream = require('stream');
util = require('util');

@@ -15,4 +20,6 @@

Formatter = (function() {
Formatter.prototype.config = {
Human = (function(_super) {
__extends(Human, _super);
Human.prototype.config = {
colors: {

@@ -27,33 +34,44 @@ 0: 'red',

7: 'green'
},
level: 7
}
};
function Formatter(config) {
var key, value, _ref, _ref1;
function Human(opts) {
this.format = __bind(this.format, this);
this._transform = __bind(this._transform, this);
this.setConfig = __bind(this.setConfig, this); this.setConfig(opts);
Human.__super__.constructor.apply(this, arguments);
}
config || (config = {});
_ref = this.config;
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
value = _ref[key];
if ((_ref1 = config[key]) == null) {
config[key] = value;
}
Human.prototype.pipe = function(child) {
if (typeof child.setConfig === "function" ? child.setConfig(this.config) : void 0) {
this.on('config', child.setConfig);
}
this.config = config;
}
return Human.__super__.pipe.apply(this, arguments);
};
Formatter.prototype.getLevel = function() {
var _ref;
Human.prototype.setConfig = function(opts) {
this.config = extendr.deepExtend({}, this.config, opts);
return this;
};
return (_ref = this.config.level) != null ? _ref : null;
Human.prototype.getConfig = function() {
return this.config;
};
Formatter.prototype.setLevel = function(level) {
this.config.level = level;
return this;
Human.prototype._transform = function(chunk, encoding, next) {
var entry, message;
entry = JSON.parse(chunk.toString());
message = this.format(entry);
return next(null, message);
};
Formatter.prototype.padLeft = function(padding, size, msg) {
Human.prototype.getColor = function(levelCode) {
var color;
color = this.config.colors ? this.config.colors[levelCode] : false;
return color;
};
Human.prototype.padLeft = function(padding, size, msg) {
var i, _i, _ref;

@@ -71,3 +89,3 @@

Formatter.prototype.padRight = function(padding, size, msg) {
Human.prototype.padRight = function(padding, size, msg) {
var i, _i, _ref;

@@ -85,8 +103,5 @@

Formatter.prototype.details = function(levelCode, levelName, args) {
var color, date, file, index, line, message, method, parts, value, _i, _len, _ref;
Human.prototype.formatArguments = function(args) {
var index, parts, text, value, _i, _len;
date = this.getDate();
_ref = this.getLineInfo(), file = _ref.file, line = _ref.line, method = _ref.method;
color = this.getColor(levelCode);
parts = [];

@@ -97,35 +112,10 @@ for (index = _i = 0, _len = args.length; _i < _len; index = ++_i) {

}
message = parts.join(' ');
return {
date: date,
file: file,
line: line,
method: method,
color: color,
levelName: levelName,
message: message
};
text = parts.join(' ');
return text;
};
Formatter.prototype.format = function(levelCode, levelName, args) {
var className, date, line, message, _ref;
Human.prototype.formatDate = function(now) {
var date, hours, minutes, month, ms, result, seconds, year;
_ref = this.details(levelCode, levelName, args), date = _ref.date, className = _ref.className, line = _ref.line, levelName = _ref.levelName, message = _ref.message;
if (this.config.level === 7) {
return message = ("[" + date + "] [" + className + ": " + line + "] ") + this.padLeft(' ', 10, "" + levelName + ":") + (" " + message);
} else {
return message = this.padLeft(' ', 10, "" + levelName + ":") + (" " + message);
}
};
Formatter.prototype.getColor = function(levelCode) {
var color;
return color = this.config.colors ? this.config.colors[levelCode] : false;
};
Formatter.prototype.getDate = function() {
var date, hours, minutes, month, ms, now, seconds, year;
now = new Date();
now = new Date(now);
year = now.getFullYear();

@@ -138,63 +128,21 @@ month = this.padLeft('0', 2, now.getMonth() + 1);

ms = this.padLeft('0', 3, now.getMilliseconds());
return "" + year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds + "." + ms;
};
Formatter.prototype.getLineInfo = function() {
var e, line, lines, parts, result, _i, _len;
result = {
line: -1,
method: 'unknown'
};
try {
throw new Error();
} catch (_error) {
e = _error;
lines = e.stack.split('\n');
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
if (line.indexOf(__dirname) !== -1 || line.indexOf(' at ') === -1) {
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;
}
}
result = "" + year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds + "." + ms;
return result;
};
return Formatter;
Human.prototype.format = function(entry) {
var colorFormatter, debugFormatter, debugString, levelName, messageFormatter, messageString, result, seperator;
})();
ConsoleFormatter = (function(_super) {
__extends(ConsoleFormatter, _super);
function ConsoleFormatter() {
_ref = ConsoleFormatter.__super__.constructor.apply(this, arguments);
return _ref;
}
ConsoleFormatter.prototype.format = function(levelCode, levelName, args) {
var color, date, debugFormatter, debugString, file, line, message, messageFormatter, messageString, method, seperator, _ref1;
_ref1 = this.details(levelCode, levelName, args), date = _ref1.date, file = _ref1.file, line = _ref1.line, method = _ref1.method, color = _ref1.color, levelName = _ref1.levelName, message = _ref1.message;
if (!message) {
return message;
} else {
color = color && (cliColor != null ? cliColor[color] : void 0) || function(str) {
entry.color = this.getColor(entry.levelCode);
entry.timestamp = this.formatDate(entry.date);
entry.text = this.formatArguments(entry.args);
result = null;
if (entry.text) {
colorFormatter = entry.color && (cliColor != null ? cliColor[entry.color] : void 0) || function(str) {
return str;
};
levelName = color(levelName + ':');
debugFormatter = false;
messageFormatter = color && (cliColor != null ? cliColor.bold : void 0);
messageString = "" + levelName + " " + message;
messageFormatter = colorFormatter && (cliColor != null ? cliColor.bold : void 0);
levelName = colorFormatter(entry.levelName + ':');
messageString = "" + levelName + " " + entry.text;
if (messageFormatter) {

@@ -205,21 +153,77 @@ messageString = messageFormatter(messageString);

seperator = '\n → ';
debugString = "[" + date + "] [" + file + ":" + line + "] [" + method + "]";
debugString = "[" + entry.timestamp + "] [" + entry.file + ":" + entry.line + "] [" + entry.method + "]";
if (debugFormatter) {
debugString = lineFormatter(debugString);
}
return message = "" + messageString + seperator + debugString;
result = "" + messageString + seperator + debugString + "\n";
} else {
return message = messageString;
result = messageString + '\n';
}
}
return result;
};
return ConsoleFormatter;
return Human;
})(Formatter);
})(stream.Transform);
Filter = (function(_super) {
__extends(Filter, _super);
Filter.prototype.config = {
level: 6
};
function Filter(opts) {
this._transform = __bind(this._transform, this);
this.setConfig = __bind(this.setConfig, this); this.setConfig(opts);
Filter.__super__.constructor.apply(this, arguments);
}
Filter.prototype.pipe = function(child) {
if (typeof child.setConfig === "function" ? child.setConfig(this.config) : void 0) {
this.on('config', child.setConfig);
}
return Filter.__super__.pipe.apply(this, arguments);
};
Filter.prototype.setConfig = function(opts) {
this.config = extendr.deepExtend({}, this.config, opts);
return this;
};
Filter.prototype.getConfig = function() {
return this.config;
};
Filter.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);
};
Filter.prototype.format = function(entry) {
if (entry.levelCode > this.config.level) {
return null;
}
return entry;
};
return Filter;
})(stream.Transform);
create = function(opts) {
return new Human(opts);
};
module.exports = {
cliColor: cliColor,
Formatter: Formatter,
ConsoleFormatter: ConsoleFormatter
Human: Human,
Filter: Filter
};
// Generated by CoffeeScript 1.6.2
var ConsoleTransport, Logger, Transport, _ref,
var Logger, extendr, stream,
__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;
_ref = require(__dirname + '/transport'), Transport = _ref.Transport, ConsoleTransport = _ref.ConsoleTransport;
extendr = require('extendr');
Logger = (function() {
stream = require('stream');
Logger = (function(_super) {
__extends(Logger, _super);
Logger.prototype.config = {
autoFlush: true,
transports: null,
level: 7,
levels: {

@@ -31,85 +34,40 @@ emergency: 0,

Logger.prototype.messages = [];
function Logger(opts) {
this.setConfig = __bind(this.setConfig, this); this.setConfig(opts);
Logger.__super__.constructor.apply(this, arguments);
}
Logger.prototype.formatter = null;
Logger.prototype.transports = [];
function Logger(config) {
var key, levels, transport, value, _i, _len, _ref1, _ref2, _ref3, _ref4, _ref5;
this.messages = [];
this.transports = [];
config || (config = {});
_ref1 = this.config;
for (key in _ref1) {
if (!__hasProp.call(_ref1, key)) continue;
value = _ref1[key];
if ((_ref2 = config[key]) == null) {
config[key] = value;
}
Logger.prototype.pipe = function(child) {
if (typeof child.setConfig === "function" ? child.setConfig(this.config) : void 0) {
this.on('config', child.setConfig);
}
levels = {};
_ref3 = config.levels;
for (key in _ref3) {
if (!__hasProp.call(_ref3, key)) continue;
value = _ref3[key];
if ((_ref4 = levels[key]) == null) {
levels[key] = value;
}
}
config.levels = levels;
if (!config.transports) {
config.transports = new ConsoleTransport;
}
if (!(config.transports instanceof Array)) {
config.transports = [config.transports];
}
_ref5 = config.transports;
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
transport = _ref5[_i];
if (transport instanceof Transport) {
this.transports.push(transport);
} else if (transport) {
this.transports.push(new ConsoleTransport(transport));
}
}
delete config.transports;
if (config.level) {
this.setLevel(config.level);
}
this.config = config;
}
return Logger.__super__.pipe.apply(this, arguments);
};
Logger.prototype.getLevel = function() {
var _ref1;
Logger.prototype.setConfig = function(opts) {
this.config = extendr.deepExtend({}, this.config, opts);
return this;
};
return (_ref1 = this.config.level) != null ? _ref1 : null;
Logger.prototype.getConfig = function() {
return this.config;
};
Logger.prototype.setLevel = function(level) {
var transport, _i, _len, _ref1;
this.config.level = level;
_ref1 = this.transports;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
transport = _ref1[_i];
transport.setLevel(level);
}
return this;
Logger.prototype._transform = function(chunk, encoding, next) {
return next(null, chunk);
};
Logger.prototype.getLevelCode = function(name) {
var _ref1;
var _ref;
return (_ref1 = this.config.levels[name]) != null ? _ref1 : null;
return (_ref = this.config.levels[name]) != null ? _ref : null;
};
Logger.prototype.getLevelName = function(code) {
var key, value, _ref1;
var key, value, _ref;
_ref1 = this.config.levels;
for (key in _ref1) {
if (!__hasProp.call(_ref1, key)) continue;
value = _ref1[key];
_ref = this.config.levels;
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
value = _ref[key];
if (value === code) {

@@ -122,6 +80,9 @@ return key;

Logger.prototype.log = function() {
var args, level, levelCode, levelName;
Logger.prototype.getLevelInfo = function(level) {
var levelCode, levelName, result;
level = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
result = {
levelCode: null,
levelName: null
};
if (typeof level === 'number') {

@@ -137,36 +98,66 @@ levelCode = level;

levelName = this.getLevelName(levelCode);
args.unshift(level);
}
}
if (this.config.autoFlush) {
this.write(levelCode, levelName, args);
} else {
this.messages.push({
levelCode: levelCode,
levelName: levelName,
args: args
});
result.levelCode = levelCode;
result.levelName = levelName;
return result;
};
Logger.prototype.getLineInfo = function() {
var err, line, lines, parts, result, _i, _len;
result = {
line: -1,
method: 'unknown',
file: 'unknown'
};
err = new Error();
lines = err.stack.split('\n');
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
if (line.indexOf(__dirname) !== -1 || line.indexOf(' at ') === -1) {
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 this;
return result;
};
Logger.prototype.flush = function() {
var args, levelCode, levelName, _i, _len, _ref1, _ref2;
Logger.prototype.format = function() {
var args, entry, key, level, value, _ref, _ref1;
_ref1 = this.messages;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
_ref2 = _ref1[_i], levelCode = _ref2.levelCode, levelName = _ref2.levelName, args = _ref2.args;
this.write(levelCode, levelName, args);
level = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
entry = {};
entry.args = args;
entry.date = new Date().toISOString();
_ref = this.getLevelInfo(level);
for (key in _ref) {
if (!__hasProp.call(_ref, key)) continue;
value = _ref[key];
entry[key] = value;
}
return this;
_ref1 = this.getLineInfo(level);
for (key in _ref1) {
if (!__hasProp.call(_ref1, key)) continue;
value = _ref1[key];
entry[key] = value;
}
return entry;
};
Logger.prototype.write = function(levelCode, levelName, args) {
var transport, _i, _len, _ref1;
Logger.prototype.log = function() {
var args, entry, level;
_ref1 = this.transports;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
transport = _ref1[_i];
transport.write(levelCode, levelName, args);
}
level = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
entry = this.format.apply(this, [level].concat(__slice.call(args)));
this.write(JSON.stringify(entry));
return this;

@@ -177,3 +168,3 @@ };

})();
})(stream.Transform);

@@ -180,0 +171,0 @@ module.exports = {

{
"name": "caterpillar",
"version": "1.1.4",
"description": "Caterpillar is a simple but powerful console logger for node.js. It supports grouping of messages, filtering log levels, colors, times, modules, custom formatters and custom transports.",
"version": "2.0.0",
"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.",
"homepage": "https://github.com/bevry/caterpillar",
"keywords": [
"console",
"log",
"logger",
"logging",
"debug"
"caterpillar",
"console", "log", "logger", "logging", "debug",
"stream", "transform"
],

@@ -28,10 +26,14 @@ "author": "Bevry Pty Ltd <us@bevry.me> (http://bevry.me)",

"engines" : {
"node": ">=0.4"
"node": ">=0.10"
},
"dependencies": {},
"optionalDependencies": {
"cli-color": "~0.2.2"
"dependencies": {
"extendr": "~2.0.1"
},
"devDependencies": {
"coffee-script": "~1.6.2"
"caterpillar-filter": "2.x",
"caterpillar-human": "2.x",
"coffee-script": "~1.6.2",
"joe": "~1.2.0",
"joe-reporter-console": "~1.2.1",
"chai": "~1.5.0"
},

@@ -41,3 +43,6 @@ "directories": {

},
"scripts": {
"test": "node ./out/test/caterpillar-test.js"
},
"main": "./out/lib/caterpillar.js"
}
# Caterpillar
Caterpillar is a simple but powerful intuitive console logger for [Node.js](http://nodejs.org/). It supports grouping of messages, filtering log levels, colors, times, modules, custom formatters and custom transports.
[![Build Status](https://secure.travis-ci.org/bevry/caterpillar.png?branch=master)](http://travis-ci.org/bevry/caterpillar)
[![NPM version](https://badge.fury.io/js/caterpillar.png)](https://npmjs.org/package/caterpillar)
[![Flattr this project](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](http://flattr.com/thing/344188/balupton-on-Flattr)
Caterpillar is the ultimate logging system for Node.js, based on [transform streams](http://nodejs.org/api/stream.html#stream_class_stream_transform) you can log to it and pipe the output off to different locations, including [some pre-made ones](http://npmjs.org/keyword/caterpillar-transform). Caterpillar also supports log levels according to the [RFC standard](http://www.faqs.org/rfcs/rfc3164.html), as well as line, method, and file fetching for messages.
## Example
### Running Normally
Running the [console example](https://github.com/bevry/caterpillar/blob/master/example/console.coffee#files) with `coffee examples/console.coffee`
## Install
### Backend
1. [Install Node.js](http://bevry.me/node/install)
2. `npm install --save caterpillar`
### Frontend
1. [See Browserify](http://browserify.org/)
## Usage
### Example with the [Filter](https://github.com/bevry/caterpillar-filter) and [Human](https://github.com/bevry/caterpillar-filter) transforms
``` javascript
// Import
var level = process.argv.indexOf('-d') === -1 ? 6 : 7;
var logger = new (require('./').Logger)({level:level});
var filter = new (require('caterpillar-filter').Filter)();
var human = new (require('caterpillar-human').Human)();
// Pipe logger output to filter, then filter output to stdout
logger.pipe(filter).pipe(human).pipe(process.stdout);
// Log messages
logger.log('emergency', 'this is level 0');
logger.log('emerg', 'this is level 0');
logger.log('alert', 'this is level 1');
logger.log('critical', 'this is level 2');
logger.log('crit', 'this is level 2');
logger.log('error', 'this is level 3');
logger.log('err', 'this is level 3');
logger.log('warning', 'this is level 4');
logger.log('warn', 'this is level 4');
logger.log('notice', 'this is level 5');
logger.log('note', 'this is level 5');
logger.log('info', 'this is level 6');
logger.log('default', 'this is level 6');
logger.log('debug', 'this is level 7');
logger.log('this is level 6, the default level');
logger.log('you','can','also','use','as','many','arguments','as','you','want',1,[2,3],{four:5});
```
Result with log level 6 (info):
<img src="https://github.com/bevry/caterpillar/raw/master/media/caterpillar-normal.png"/>
### Running in Debug Mode (log level 7)
Result with log level 7 (debug):
Running the [console example](https://github.com/bevry/caterpillar/blob/master/example/console.coffee#files) with `coffee examples/console.coffee -d`
<img src="https://github.com/bevry/caterpillar/raw/master/media/caterpillar-normal.png"/>
When you set the log level to level 7 (debug level), then the `ConsoleFormatter` will also output a debug line, containing the time, file, function and line number of what triggered the log message
<img src="https://github.com/bevry/caterpillar/raw/master/media/caterpillar-debug.png"/>
### Transform API, extends [stream.Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform)
``` javascript
new (require('caterpillar').Transform)(config)
```
## Using
- Methods
- `constructor(config?)` create our new filter instance with the config, config is optional
- `pipe(child)` pipe our stream to the child, also sync our config to it
- `setConfig(config)` set the configuration and emit the `config` event
- `getConfig()` get the configuration
- `format(entry)` format the caterpillar logger entry
- Configuration
- none by default
- Events
- `config(config)` emitted once our configuration has updated
Refer to the [console example](https://github.com/bevry/caterpillar/blob/master/example/console.coffee#files) for usage
### Logger API, extends Transform API
## Install
``` javascript
new (require('caterpillar').Logger)(config)
```
1. [Install Node.js](http://bevry.me/node/install)
- Methods
- `constructor(config?)` create our new filter instance with the config, config is optional
- `log(args...)` write a log message, the first argument is suppose to be the level (will use the default level if it isn't)
- `format(level, args...)` create a log entry ready for writing to the logger stream, output is as follows:
1. Install Caterpillar
``` javascript
{
"args": ["this is emergency and is level 0"],
"date": "2013-04-25T10:18:25.722Z",
"levelNumber": 0,
"levelName": "emergency",
"line": "59",
"method": "Task.fn",
"file": "/Users/balupton/Projects/caterpillar/out/test/caterpillar-test.js"
}
```
```
npm install caterpillar
```
- `getLevelNumber(name)` get the level number for the level name
- `getLevelName(number)` get the level name for the level number
- `getLevelInfo(nameOrNumber)` get the level name and number for either a level name or number
- `getLineInfo()` get the file, method, and line that the `log` method was called on
- Configuration
- `levels` the level names and their associated number, also includes `default` for when no level was specified, defaults to:
``` javascript
{
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
}
```
- Events
- only those inherited
## History
You can discover the history inside the [History.md](https://github.com/bevry/caterpillar/blob/master/History.md#files) file
## License
Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/)

@@ -52,8 +153,7 @@ <br/>Copyright &copy; 2012+ [Bevry Pty Ltd](http://bevry.me)

## Thanks
Uses the following:
- [RFC3164](http://www.faqs.org/rfcs/rfc3164.html) for the level codes and names
- [Mariusz Nowak's](https://github.com/medikoo) [CLI-Color](https://github.com/medikoo/cli-color)

@@ -60,0 +160,0 @@ Inspired by the following:

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