console-stamp
Advanced tools
Comparing version 3.0.0-rc3.0 to 3.0.0-rc4.0
34
index.js
@@ -1,29 +0,25 @@ | ||
/* | ||
* node-console-stamp | ||
* (c) 2013-2019 Ståle Lytskjold Raknes <https://github.com/starak/node-console-stamp> | ||
* MIT license | ||
*/ | ||
const { checkLogLevel, generateConfig, generatePrefix, selectOutputStream } = require( './lib/utils.js' ); | ||
const { checkLogLevel, generateConfig, generatePrefix, selectOutputStream, FakeStream } = require( './lib/utils.js' ); | ||
module.exports = consoleStamp = ( con, options = {} ) => { | ||
if(con.__patched){ | ||
if ( con.__patched ) { | ||
con.reset(); | ||
} | ||
const customConsoleStream = new FakeStream(); | ||
const customConsole = new console.Console( customConsoleStream, customConsoleStream ); | ||
// Fix the lack of debug alias in pre 8.0 node | ||
if(typeof con.debug === "undefined"){ | ||
con.debug = (...arg) => con.org.log ? con.org.log(...arg) : con.log(...arg); | ||
if ( typeof con.debug === "undefined" ) { | ||
con.debug = ( ...arg ) => con.org.log ? con.org.log( ...arg ) : con.log( ...arg ); | ||
} | ||
const config = generateConfig( options ); | ||
const include = config.include.filter(m => typeof con[m] === 'function'); | ||
const include = config.include.filter( m => typeof con[m] === 'function' ); | ||
const org = {}; | ||
Object.keys(con).forEach(m => org[m] = con[m]); | ||
Object.keys( con ).forEach( m => org[m] = con[m] ); | ||
con.org = org; | ||
include.forEach( method => { | ||
const stream = selectOutputStream(method, config); | ||
const stream = selectOutputStream( method, config ); | ||
const trg = con[method]; | ||
@@ -34,4 +30,9 @@ | ||
if ( checkLogLevel( config, method ) ) { | ||
stream.write( `${generatePrefix(method, config)} ` ); | ||
target.apply( context, arguments ); | ||
customConsole.log.apply( context, arguments); | ||
stream.write( `${generatePrefix( method, config, customConsoleStream.last_msg )} ` ); | ||
if(config.use_custom_message || /\:msg\b/.test( config.format )) { | ||
stream.write('\n'); | ||
}else{ | ||
target.apply( context, arguments ); | ||
} | ||
} | ||
@@ -51,4 +52,5 @@ } | ||
delete con.reset; | ||
customConsoleStream.end(); | ||
}; | ||
}; |
const date = require('../tokens/date.js'); | ||
const {label} = require('../tokens/label.js'); | ||
const msg = require( '../tokens/msg' ); | ||
@@ -12,2 +13,3 @@ module.exports = { | ||
label, | ||
msg | ||
}, | ||
@@ -23,3 +25,4 @@ level: "log", | ||
extend: {}, | ||
groupCount: 0 | ||
}; | ||
groupCount: 0, | ||
use_custom_message: false, | ||
}; |
@@ -1,3 +0,4 @@ | ||
const df = require( './defaults.js' ); | ||
const df = require( './defaults' ); | ||
const chalk = require( 'chalk' ); | ||
const { Writable } = require( 'stream' ); | ||
@@ -41,3 +42,3 @@ function checkLogLevel( { levels, level }, method ) { | ||
function generatePrefix( method, { tokens, defaultTokens, format: prefix, tokensKeys } ) { | ||
function generatePrefix( method, { tokens, defaultTokens, format: prefix, tokensKeys }, msg ) { | ||
tokensKeys | ||
@@ -47,5 +48,5 @@ .sort( ( a, b ) => b.length - a.length ) | ||
const token = tokens[key]; | ||
const re = new RegExp( `:${key}(\\([^)]+\\))?(\\.\\w+)*`, 'g' ); | ||
const re = new RegExp( `:${key}(\\([^)]*\\))?(\\.\\w+)*`, 'g' ); | ||
prefix = prefix.replace( re, ( match, params ) => { | ||
let ret = token( { method, defaultTokens, params: parseParams( params ), tokens } ); | ||
let ret = token( { method, defaultTokens, params: parseParams( params ), tokens, msg } ); | ||
match.replace( params, '' ).split( '.' ).slice( 1 ).forEach( decorator => { | ||
@@ -57,3 +58,2 @@ ret = chalk`{${decorator} ${ret}}`; | ||
} ); | ||
} ); | ||
@@ -77,2 +77,18 @@ | ||
class FakeStream extends Writable { | ||
constructor() { | ||
super(); | ||
this._last_message = ''; | ||
} | ||
get last_msg() { | ||
return this._last_message.replace( /\n$/, '' ); | ||
} | ||
_write( chunk, enc, cb ) { | ||
this._last_message = chunk.toString(); | ||
cb(); | ||
} | ||
} | ||
module.exports = { | ||
@@ -84,2 +100,3 @@ checkLogLevel, | ||
selectOutputStream, | ||
FakeStream | ||
}; |
134
package.json
{ | ||
"name": "console-stamp", | ||
"main": "index.js", | ||
"version": "3.0.0-rc3.0", | ||
"scripts": { | ||
"test": "tap -R spec test/*.js", | ||
"test:watch": "nodemon --exec npm test", | ||
"preversion": "npm test" | ||
"name": "console-stamp", | ||
"main": "index.js", | ||
"version": "3.0.0-rc4.0", | ||
"scripts": { | ||
"test": "tap -R spec test/*.js", | ||
"test:watch": "nodemon --exec npm test", | ||
"t:w": "npm run test:watch", | ||
"preversion": "npm test", | ||
"examples": "node examples/index || true" | ||
}, | ||
"engines": { | ||
"node": ">=6.4.0" | ||
}, | ||
"author": { | ||
"name": "Ståle Raknes", | ||
"email": "stale@raknes.net", | ||
"url": "http://github.com/starak" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Ståle Raknes", | ||
"url": "http://github.com/starak" | ||
}, | ||
"engines": { | ||
"node": ">=6.4.0" | ||
{ | ||
"name": "Jotham Read", | ||
"url": "https://github.com/jotham" | ||
}, | ||
"author": { | ||
"name": "Ståle Raknes", | ||
"email": "stale@raknes.net", | ||
"url": "http://github.com/starak" | ||
{ | ||
"name": "Christiaan Westerbeek", | ||
"url": "https://github.com/devotis" | ||
}, | ||
"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" | ||
}, | ||
{ | ||
"name": "Leon Lucardie", | ||
"url": "https://github.com/Gameleon12" | ||
}, | ||
{ | ||
"name": "Steffan Donal", | ||
"url": "https://github.com/SteffanDonal" | ||
}, | ||
{ | ||
"name": "Sören Schwert", | ||
"url": "https://github.com/sisou" | ||
}, | ||
{ | ||
"name": "Fkscorpion", | ||
"url": "https://github.com/Fkscorpion" | ||
}, | ||
{ | ||
"name": "Alexis Tyler", | ||
"url": "https://github.com/OmgImAlexis" | ||
} | ||
], | ||
"description": "Patch NodeJS console methods in order to add timestamp information by pattern", | ||
"keywords": [ | ||
"console", | ||
"timestamp", | ||
"log", | ||
"jslog", | ||
"debug" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/starak/node-console-stamp.git" | ||
{ | ||
"name": "Leon Lucardie", | ||
"url": "https://github.com/Gameleon12" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"chalk": "^2.4.2", | ||
"dateformat": "^3.0.3" | ||
{ | ||
"name": "Steffan Donal", | ||
"url": "https://github.com/SteffanDonal" | ||
}, | ||
"devDependencies": { | ||
"moment": "^2.24.0", | ||
"nodemon": "^1.18.9", | ||
"tap": "^12.5.1" | ||
{ | ||
"name": "Sören Schwert", | ||
"url": "https://github.com/sisou" | ||
}, | ||
{ | ||
"name": "Fkscorpion", | ||
"url": "https://github.com/Fkscorpion" | ||
}, | ||
{ | ||
"name": "Alexis Tyler", | ||
"url": "https://github.com/OmgImAlexis" | ||
} | ||
], | ||
"description": "Patch NodeJS console methods in order to add timestamp information by pattern", | ||
"keywords": [ | ||
"console", | ||
"timestamp", | ||
"log", | ||
"jslog", | ||
"debug" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/starak/node-console-stamp.git" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"chalk": "^2.4.2", | ||
"dateformat": "^3.0.3" | ||
}, | ||
"devDependencies": { | ||
"moment": "^2.24.0", | ||
"nodemon": "^1.18.9", | ||
"tap": "^12.5.1" | ||
} | ||
} |
const console_stamp = require( './index' ); | ||
const chalk = require( "chalk" ); | ||
const { padRight } = require('./lib/utils'); | ||
@@ -14,3 +13,3 @@ const map = { | ||
console_stamp( console, { | ||
format: '(->).yellow :date(HH:MM.ss.l).gray :label(9)', | ||
format: '(->).yellow :date(HH:MM.ss.l).gray :label(8) :msg blabla', | ||
tokens: { | ||
@@ -20,2 +19,5 @@ label: ( obj ) => { | ||
return chalk`{${map[obj.method] || 'reset'} ${obj.defaultTokens.label( obj )}}`; | ||
}, | ||
msg: ( {method, msg} ) => { | ||
return chalk`{${map[method] || 'reset'} ${msg}}`; | ||
} | ||
@@ -25,5 +27,6 @@ } | ||
console.debug( `Debug msg` ); | ||
console.log( 'Log msg' ); | ||
console.info( 'Info msg' ); | ||
console.info( 'Info msg %d', 42 ); | ||
console.warn( 'Warn msg' ); | ||
console.error( 'Error msg' ); |
@@ -12,2 +12,2 @@ function padRight ( str, len = 0 ) { | ||
label | ||
}; | ||
}; |
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
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
203168
18
4882
3
1