Socket
Socket
Sign inDemoInstall

console-stamp

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-stamp - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

4

defaults.json

@@ -5,2 +5,4 @@ {

"exclude": [],
"disable": [],
"level": "log",
"label": true,

@@ -12,2 +14,2 @@ "colors": {

}
}
}

@@ -16,2 +16,28 @@ /*jshint node:true, bitwise:false */

var levelPriorities = {
log: 4,
info: 3,
warn: 2,
error: 1,
assert: 2,
dir: 4
};
function getAllowedLogFunctions( level ) {
var logFunctions = [],
levelPriority = levelPriorities[level];
for ( var logFunction in levelPriorities ) {
if ( !levelPriorities.hasOwnProperty( logFunction ) ) {
continue;
}
if ( levelPriority >= levelPriorities[logFunction] ) {
logFunctions.push( logFunction );
}
}
return logFunctions;
}
module.exports = function ( con, options, prefix_metadata ) {

@@ -36,6 +62,11 @@

var dateFormat = options.formatter || defaultDateFormat;
var dateFormat = options.formatter || defaultDateFormat,
allowedLogFunctions = getAllowedLogFunctions( options.level );
options.disable = options.disable.concat( options.include.filter( function ( m ) {
return !~options.exclude.indexOf( m ) && !~allowedLogFunctions.indexOf( m );
} ) );
options.include = options.include.filter( function filter( m ) {
return !~options.exclude.indexOf( m );
return !~options.exclude.indexOf( m ) && !~options.disable.indexOf( m );
} );

@@ -126,2 +157,10 @@

options.disable.forEach( function ( f ) {
original_functions.push( [f, con[f]] );
con[f] = function () { };
} );
con.restoreConsole = function () {

@@ -128,0 +167,0 @@ original_functions.forEach( function ( pair ) {

{
"name": "console-stamp",
"main": "main",
"version": "0.2.2",
"version": "0.2.3",
"author": {

@@ -26,2 +26,6 @@ "name": "Ståle Raknes",

"url": "https://github.com/Gameleon12"
},
{
"name": "Steffan Donal",
"url": "https://github.com/SteffanDonal"
}

@@ -28,0 +32,0 @@ ],

@@ -17,7 +17,7 @@ # console-stamp

npm install console-stamp
npm install console-stamp
### Patching the console
require("console-stamp")(console, [options]);
require("console-stamp")(console, [options]);

@@ -29,7 +29,7 @@ #### console

From version 2.0 the second parameter is an object with several options. As a backward compatibillity feature this parameter can be a string containing the pattern.
From version 2.0 the second parameter is an object with several options. As a backward compatibillity feature this parameter can be a string containing the pattern.
* **options.pattern** {String}<br>A string with date format based on [Javascript Date Format](http://blog.stevenlevithan.com/archives/date-time-format)<br>**Default**: "ddd mmm dd yyyy HH:MM:ss"
* **options.formatter** {Function}<br>A custom date formatter that should return a formmatted date string.
* **options.formatter** {Function}<br>A custom date formatter that should return a formmatted date string.

@@ -42,4 +42,8 @@ * **options.label** {Boolean}<br>If true it will show the label (LOG | INFO | WARN | ERROR)<br>**Default**: true

* **options.disable** {Array}<br>An array containing the methods to disable in the patch<br>**Default**: [] \(none)
* **options.level** {String}<br>A string choosing the most verbose logging function to allow. Ordered/grouped as such: "log dir", "info", "warn assert", "error"<br>**Default**: log
* **options.metadata** {String/Object/Function}<br>Types can be String, Object (interpreted with util.inspect), or Function. See the test-metadata.js for examples.<br>**Note** that metadata can still be sent as the third parameter (as in vesion 1.6) as a backward compatibillity feature, but this is deprecated. <br>**Default**: undefined
* **options.colors** {Object}<br>An object representing a color theme. More info [here](https://www.npmjs.com/package/chalk).

@@ -55,33 +59,33 @@

...
stamp: ["black", "bgYellow", "underline"]
...
...
stamp: ["black", "bgYellow", "underline"]
...
Or chain Chalk functions like this:
...
stamp: require("chalk").red.bgYellow.underline;
...
...
stamp: require("chalk").red.bgYellow.underline;
...
Note also that by sending the parameter `--no-color` when you start your node app, will prevent any colors from console.
$ node my-app.js --no-color
$ node my-app.js --no-color
### Example
// Patch console.x methods in order to add timestamp information
require( "console-stamp" )( console, { pattern : "dd/mm/yyyy HH:MM:ss.l" } );
// Patch console.x methods in order to add timestamp information
require( "console-stamp" )( console, { pattern : "dd/mm/yyyy HH:MM:ss.l" } );
console.log("Hello World!");
// -> [26/06/2015 14:02:48.062] [LOG] Hello World!
console.log("Hello World!");
// -> [26/06/2015 14:02:48.062] [LOG] Hello World!
var port = 8080;
console.log("Server running at port %d", port);
// -> [26/06/2015 16:02:35.325] [LOG] Server running at port 8080
var port = 8080;
console.log("Server running at port %d", port);
// -> [26/06/2015 16:02:35.325] [LOG] Server running at port 8080
&nbsp;
console.log( "This is a console.log message" );
console.log( "This is a console.log message" );
console.info( "This is a console.info message" );

@@ -95,21 +99,21 @@ console.warn( "This is a console.warn message" );

[26/06/2015 12:44:31.777] [LOG] This is a console.log message
[26/06/2015 12:44:31.777] [INFO] This is a console.info message
[26/06/2015 12:44:31.779] [WARN] This is a console.warn message
[26/06/2015 12:44:31.779] [ERROR] This is a console.error message
[26/06/2015 12:44:31.779] [DIR] { bar: 'This is a console.dir message' }
[26/06/2015 12:44:31.777] [INFO] This is a console.info message
[26/06/2015 12:44:31.779] [WARN] This is a console.warn message
[26/06/2015 12:44:31.779] [ERROR] This is a console.error message
[26/06/2015 12:44:31.779] [DIR] { bar: 'This is a console.dir message' }
and
require( "console-stamp" )( console, {
metadata: function () {
return ("[" + process.memoryUsage().rss + "]");
},
colors: {
stamp: "yellow",
label: "white",
metadata: "green"
}
} );
console.log( "This is a console.log message" );
require( "console-stamp" )( console, {
metadata: function () {
return ("[" + process.memoryUsage().rss + "]");
},
colors: {
stamp: "yellow",
label: "white",
metadata: "green"
}
} );
console.log( "This is a console.log message" );
console.info( "This is a console.info message" );

@@ -119,3 +123,3 @@ console.warn( "This is a console.warn message" );

console.dir( {bar: "This is a console.dir message"} );
Result:

@@ -131,3 +135,3 @@

moment.locale('ja');
require( "console-stamp" )( console, {

@@ -138,4 +142,4 @@ formatter:function(){

} );
console.log( "This is a console.log message" );
console.log( "This is a console.log message" );
console.info( "This is a console.info message" );

@@ -145,3 +149,3 @@ console.warn( "This is a console.warn message" );

console.dir( {bar: "This is a console.dir message"} );
Result:

@@ -157,3 +161,3 @@

Types can be string, object (interpreted with util.inspect), or function.
Types can be string, object (interpreted with util.inspect), or function.
See the [test-metadata.js](https://github.com/starak/node-console-stamp/blob/master/test-metadata.js) for examples.

@@ -164,3 +168,3 @@

require("console-stamp")(console, {
pattern:"HH:MM:ss.l",
pattern:"HH:MM:ss.l",
metadata:'[' + process.pid + ']'

@@ -180,3 +184,3 @@ });

require("console-stamp")(console, {
pattern:"HH:MM:ss.l",
pattern:"HH:MM:ss.l",
metadata: function(){ return '[' + (process.memoryUsage().rss) + ']'; });

@@ -183,0 +187,0 @@

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc