Comparing version 1.0.1 to 1.1.0
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 2 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
28758
10
624
1
160
2
3
2
1
+ Addedsource-map-support@^0.4.0
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-support@0.4.18(transitive)