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.1.5 to 0.1.6

test-metadata.js

36

main.js

@@ -15,3 +15,3 @@ /*globals module:false, require:false, process:false*/

module.exports = function ( con, pattern ) {
module.exports = function ( con, pattern, prefix_metadata ) {

@@ -24,2 +24,8 @@ "use strict";

if ( typeof prefix_metadata === 'object' ) {
var util = require('util');
}
var original_functions = [];
var slice = Array.prototype.slice;

@@ -29,2 +35,4 @@

original_functions.push( [ f, con[f] ] );
var org = con[f];

@@ -34,9 +42,17 @@

var date = "[" + dateFormat( pattern ) + "] [" + f.toUpperCase() + "] ",
args = slice.call( arguments );
var prefix = "[" + dateFormat( pattern ) + "] [" + f.toUpperCase() + "] ",
args = slice.call( arguments );
if ( typeof prefix_metadata === 'function' ) {
prefix = prefix + prefix_metadata( f, args ) + ' ';
} else if ( typeof prefix_metadata === 'object' ) {
prefix = prefix + util.inspect( prefix_metadata ) + ' ';
} else if ( typeof prefix_metadata !== 'undefined' ) {
prefix = prefix + prefix_metadata + ' ';
}
if ( f === "error" || f === "warn" || ( f === "assert" && !args[0] ) ) {
process.stderr.write( date );
}else if(f !== "assert"){
process.stdout.write( date );
process.stderr.write( prefix );
} else if ( f !== "assert" ) {
process.stdout.write( prefix );
}

@@ -49,4 +65,12 @@

con.restoreConsole = function () {
original_functions.forEach( function ( pair ) {
con[pair[0]] = pair[1];
delete con.__ts__;
} );
delete con.restoreConsole;
};
con.__ts__ = true;
};
{
"name": "console-stamp",
"main": "main",
"version": "0.1.5",
"version": "0.1.6",
"author": {
"name": "Ståle Raknes",
"email": "stale@raknes.net",
"url": "http://github.net/starak"
"url": "http://github.com/starak"
},
"contributors":[
{
"name": "Ståle Raknes",
"url": "http://github.com/starak"
},
{
"name": "Jotham Read",
"url": "https://github.com/jotham"
},
{
"name": "Christiaan Westerbeek",
"url": "https://github.com/devotis"
}
],
"description": "Patch NodeJS console methods in order to add timestamp information by pattern",

@@ -15,2 +30,3 @@ "keywords": [

"log",
"jslog",
"debug"

@@ -17,0 +33,0 @@ ],

@@ -15,10 +15,10 @@ # console-stamp

require("console-stamp")(console, "HH:MM:ss.l");
console.log("Hello World!");
// -> [14:02:48.062] [LOG] Hello World!
var port = 8080;
console.log("Server running at port %d", port);
// -> [16:02:35.325] [LOG] Server running at port 8080
### Example

@@ -66,3 +66,2 @@

See more about timestamp patterns at [felixges][felixge] excellent [dateformat][dateformat]

@@ -73,1 +72,27 @@

[FGRibreau]: https://github.com/FGRibreau/node-nice-console
### Adding Metadata ###
Types can be String, Object (interpreted with util.inspect), or Function. See the test-metadata.js for examples.
### String example
require("console-stamp")(console, "HH:MM:ss.l", '[' + process.pid + ']');
console.log('Metadata applied.');
Result:
[18:10:30.875] [LOG] [7785] Metadata applied.
### Function example
var util = require("util");
require("console-stamp")(console, "HH:MM:ss.l", function(){ return '[' + (process.memoryUsage().rss) + ']'; });
console.log('Metadata applied.');
Result:
[18:10:30.875] [LOG] [14503936] Metadata applied.
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