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

log-debug

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

log-debug - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

.travis.yml

275

index.js

@@ -1,65 +0,244 @@

var log = true;
require('source-map-support').install();
var util = require('util');
var colors = require('colors/safe');
GLOBAL.$log = module.exports = {
var LOG_COLORS = {
INFO: 'blue',
DEBUG: 'cyan',
'WARN ': 'yellow',
TRACE: 'magenta',
ERROR: 'red'
};
var Logger = (function () {
/**
* Start logguer
*
* @param stdout
* @param stderr
*/
start:function(){
log = true;
},
function Logger(stdout, stderr, noColors) {
this.logEnable = true;
this.noColors = false;
this.stderr = stderr || process.stderr;
this.stdout = stdout || process.stdout;
this.previousStd = this.stdout;
if (noColors != undefined) {
this.setNoColors(noColors);
}
}
/**
* Stop logguer
* Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf() (the arguments are all passed to util.format()).
* @param args
* @returns {any}
*/
stop:function(){
log = false;
},
Logger.prototype.debug = function (data) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
if (!this.logEnable)
return this;
return this.write(this.stdout, 'DEBUG', data, args);
};
/**
* Print a trace in the console.
* @returns {*}
*
* @param args
* @returns {any}
*/
debug:function(){
if(log){
var o = [colors.blue('[INFO]')];
for(var key in arguments){
o.push(arguments[key]);
}
return console.log.apply(console, o);
Logger.prototype.info = function (data) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
},
if (!this.logEnable)
return this;
return this.write(this.stdout, 'INFO', data, args);
};
/**
*
* @returns {*}
* @param args
* @returns {any}
*/
warn:function(){
if(log){
var o = [colors.yellow('[WARN]')];
for(var key in arguments){
o.push(arguments[key]);
}
return console.warn.apply(console, o);
Logger.prototype.warn = function (data) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
},
if (!this.logEnable)
return this;
return this.write(this.stderr, 'WARN ', data, args);
};
/**
* Prints to stderr with newline. Multiple arguments can be passed, with the first used as the primary
* message and all additional used as substitution values similar to printf() (the arguments are all
* passed to util.format()).
* @param args
* @returns {any}
*/
Logger.prototype.error = function (data) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
if (!this.logEnable)
return this;
return this.write(this.stderr, "ERROR", data, args);
};
/**
*
* @returns {*}
* @param data
* @param args
* @returns {any}
*/
error:function(){
if(log){
var o = [colors.red('[ERROR]')];
for(var key in arguments){
o.push(arguments[key]);
if(arguments[key] instanceof Error){
o.push(arguments[key].stack)
Logger.prototype.trace = function (data) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
if (!this.logEnable)
return this;
var stack = '\n' + this.colorize(Logger.createStack(), LOG_COLORS.TRACE) + "\n";
args.push(stack); //push StackTrace
return this.write(this.stderr, "TRACE", data, args);
};
/**
*
* @returns {Logger}
*/
Logger.prototype.withTrace = function () {
if (!this.logEnable)
return this;
this.previousStd.write(this.colorize(Logger.createStack(), "gray") + '\n\n');
return this;
};
/**
*
* @returns {Logger}
*/
Logger.prototype.withLine = function () {
if (!this.logEnable)
return this;
var stackTrace = Logger.createStack();
var line = '\tat (' + stackTrace.split('\n')[0].split('(')[1];
this.previousStd.write(this.colorize(line, "gray") + '\n\n');
return this;
};
/**
*
*/
Logger.prototype.start = function () {
this.logEnable = true;
};
/**
*
*/
Logger.prototype.stop = function () {
this.logEnable = false;
};
/**
*
* @param value
* @returns {Logger}
*/
Logger.prototype.setNoColors = function (value) {
this.noColors = value;
return this;
};
/**
*
* @param std
* @returns {Logger}
*/
Logger.prototype.setStdout = function (std) {
this.stdout = std;
return this;
};
/**
*
* @param std
* @returns {Logger}
*/
Logger.prototype.setStderr = function (std) {
this.stderr = std;
return this;
};
/**
*
* @param std
* @param name
* @param data
* @param args
* @returns {Logger}
*/
Logger.prototype.write = function (std, name, data, args) {
this.previousStd = std;
name = this.colorize('[' + name + ']', LOG_COLORS[name]);
var message = Logger.createMessage(data, args);
this.previousStd.write(name + message);
return this;
};
/**
*
* @param name
* @param data
* @param args
* @returns {string}
*/
Logger.createMessage = function (data, args) {
var message = '';
switch (typeof data) {
case "string":
if (args.length && util.inspect(data)) {
message += ' ' + util.format.apply(util, [data].concat(args));
}
}
return console.error.apply(console, o);
else {
message += ' ' + data;
}
break;
default:
args.unshift(data);
for (var i = 0; i < args.length; i++) {
if (typeof args[i] == "object") {
if (args[i] instanceof Error) {
message += ' ' + args[i].toString() + ' ' + args[i].stack.replace(args[i].toString(), '');
}
else {
message += ' ' + util.format('%j', args[i]);
}
}
else {
message += ' ' + args[i];
}
}
break;
}
}
};
return message + "\n";
};
/**
* Create stack trace the lines of least Logger.
* @returns {string}
*/
Logger.createStack = function () {
var stack = new Error().stack.replace('Error\n', '');
var array = stack.split('\n');
if (array[0].indexOf("Logger.") > -1) {
array.splice(0, 1);
}
if (array[0].indexOf("Logger.") > -1) {
array.splice(0, 1);
}
return array.join('\n');
};
/**
*
* @param title
* @param color
* @returns {any}
*/
Logger.prototype.colorize = function (title, color) {
return this.noColors ? title : colors[color](title);
};
return Logger;
})();
var $log = new Logger();
$log.Logger = Logger;
module.exports = $log;
//# sourceMappingURL=index.js.map
{
"name": "log-debug",
"version": "1.0.1",
"version": "1.1.0",
"description": "Logger like Angular.js for node",
"main": "index.js",
"scripts": {},
"scripts": {
"build": "typings install && tsc",
"preinstall": "typings install",
"install": "tsc",
"pretest": "typings install && tsc",
"test": "mocha"
},
"repository": {

@@ -13,3 +19,4 @@ "type": "git",

"log",
"debug"
"debug",
"typescript"
],

@@ -22,5 +29,11 @@ "author": "Romakita",

"homepage": "https://github.com/romakita/log-debug",
"devDependencies": {
"chai": "^2.1.0",
"mocha": "^2.4.5",
"typescript": "^1.7.5"
},
"dependencies": {
"colors": "^1.1.0"
"colors": "^1.1.0",
"source-map-support": "^0.4.0"
}
}

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