diff --git a/debug-trace-browser.js b/debug-trace-browser.js index 2ef7bad..f8da404 100644 --- a/debug-trace-browser.js +++ b/debug-trace-browser.js @@ -24,7 +24,7 @@ if (typeof Error.captureStackTrace === 'function') { var fn = console[name]; console[name] = function () { if (console._trace || console.traceOptions.always) { - if (typeof arguments[0] === 'object') { + if (typeof arguments[0] === 'object' && !arguments[0].stack) { arguments[0] = JSON.stringify(arguments[0], null, ' '); } // when using the debug module: dig one level deeper in the stack @@ -35,7 +35,7 @@ if (typeof Error.captureStackTrace === 'function') { trace.debug = true; } trace.debug = trace.debug || false; - arguments[0] = console.traceFormat(trace, name) + arguments[0]; + arguments[0] = arguments[0].stack ? arguments[0] : console.traceFormat(trace, name) + arguments[0]; } console._trace = false; return fn.apply(this, arguments); diff --git a/debug-trace.js b/debug-trace.js index 3077f12..fd1e1ca 100644 --- a/debug-trace.js +++ b/debug-trace.js @@ -35,7 +35,7 @@ module.exports = function debugTrace(options) { if (console._trace || console.traceOptions.always) { if (Buffer.isBuffer(arguments[0])) { arguments[0] = arguments[0].inspect() - } else if (typeof arguments[0] === 'object') { + } else if (typeof arguments[0] === 'object' && arguments[0] && !arguments[0].stack) { arguments[0] = JSON.stringify(arguments[0], null, ' '); } var pad = (arguments[0] && !console.traceOptions.right || !isatty ? ' ' : ''); @@ -47,7 +47,7 @@ module.exports = function debugTrace(options) { trace.debug = true; } trace.debug = trace.debug || false; - arguments[0] = console.traceFormat(trace, name) + pad + arguments[0]; + arguments[0] = arguments[0] && arguments[0].stack ? arguments[0] : console.traceFormat(trace, name) + pad + arguments[0]; } console._trace = false; return fn.apply(this, arguments); @@ -64,7 +64,7 @@ module.exports = function debugTrace(options) { console.traceFormat = function (call, method) { var options = {}; - call.filename = call.getFileName().replace(console.traceOptions.cwd, ''); + call.filename = (call.getFileName() || '').replace(console.traceOptions.cwd, ''); call.method = method; call.functionName = call.getFunctionName() || 'anonymous' call.getDate = function getDate() { @@ -74,9 +74,12 @@ console.traceFormat = function (call, method) { var str = console.format(call); var color = '99'; - if (!isatty) { + if (!isatty || process.env.IS_DOCKER) { return str; } + if (method === 'error') { // 因为k8s无法区分node的error和out,所以加上这个特殊格式 + str += '|' + } if (console.traceOptions.colors !== false) { if (console.traceOptions.colors === undefined || console.traceOptions.colors[method] === undefined) { diff --git a/package.json b/package.json index 0f41549..b655752 100644 --- a/package.json +++ b/package.json @@ -1,29 +1,29 @@ { - "name": "debug-trace", - "version": "2.0.0", - "description": "Adds a handy `trace` flag to the console object to prepend the file and line number", - "main": "./debug-trace", - "browser": "./debug-trace-browser", - "dependencies": { - "callsite": "~1.0.0" - }, - "repository": { - "type": "git", - "url": "https://github.com/intesso/debug-trace" - }, - "keywords": [ - "debug", - "trace", - "callsite", - "formatted console", - "format console", - "line number", - "function name" - ], - "author": "Andi Neck", - "license": "MIT", - "bugs": { - "url": "https://github.com/intesso/debug-trace/issues" - }, - "homepage": "https://github.com/intesso/debug-trace" -} + "name": "@ivy/debug", + "version": "2.0.9", + "description": "Adds a handy `trace` flag to the console object to prepend the file and line number", + "main": "./debug-trace", + "browser": "./debug-trace-browser", + "dependencies": { + "callsite": "~1.0.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/intesso/debug-trace" + }, + "keywords": [ + "debug", + "trace", + "callsite", + "formatted console", + "format console", + "line number", + "function name" + ], + "author": "Andi Neck", + "license": "MIT", + "bugs": { + "url": "https://github.com/intesso/debug-trace/issues" + }, + "homepage": "https://github.com/intesso/debug-trace" +} \ No newline at end of file diff --git a/pub.js b/pub.js new file mode 100644 index 0000000..1175189 --- /dev/null +++ b/pub.js @@ -0,0 +1,17 @@ +'use strict'; +let fs = require('fs'); +var execSync = require('child_process').execSync; +let path = process.argv[2] || '.'; +let f = path + '/package.json'; +let olds = fs.readFileSync(f).toString(); +let p = JSON.parse(olds) +let oldv = p.version; +let vers = p.version.split('.'); +let v3 = parseInt(vers[2])+1; +p.version = `${vers[0]}.${vers[1]}.${v3}`; +let news = JSON.stringify(p, null, 4); +fs.writeFileSync(f, news); +console.log(`old version: ${oldv}, new version: ${p.version}`); +let cmd = `npm publish ${path} --registry=http://npm.ivydad.com`; +console.log(cmd); +execSync(cmd, {stdio:[0,1,2]}) diff --git a/test.js b/test.js index 38f6c69..0331109 100644 --- a/test.js +++ b/test.js @@ -72,4 +72,7 @@ process.stdout.write(' '); console.traced.log(['Works', 'with', 'Array']); process.stdout.write(' '); -console.traced.log('Works with Buffer', Buffer('FooBar')); \ No newline at end of file +console.traced.log('Works with Buffer', Buffer('FooBar')); + +process.stdout.write(' '); +console.traced.log(new Error('an error'));