From 505b66ab9a20fd9cfa0a62171801119eb10055db Mon Sep 17 00:00:00 2001 From: yedongfu Date: Tue, 30 May 2017 10:48:31 +0800 Subject: [PATCH 1/9] handle Error in arguments[0] ok --- debug-trace-browser.js | 4 ++-- debug-trace.js | 4 ++-- test.js | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) 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..d072c6e 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].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].stack ? arguments[0] : console.traceFormat(trace, name) + pad + arguments[0]; } console._trace = false; return fn.apply(this, arguments); 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')); From 9c170a2c75894e879148386c8f38f0e474915501 Mon Sep 17 00:00:00 2001 From: yedongfu Date: Wed, 7 Aug 2019 16:18:32 +0800 Subject: [PATCH 2/9] before update docker --- debug-trace.js | 6 +++--- package.json | 56 +++++++++++++++++++++++++------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/debug-trace.js b/debug-trace.js index d072c6e..e58c8aa 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' && !arguments[0].stack) { + } 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] = arguments[0].stack ? 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() { diff --git a/package.json b/package.json index 0f41549..b01881c 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": "debug-trace2", + "version": "2.0.4", + "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 From 31a6be99db2e8fe38b557d86b7cb701363695c45 Mon Sep 17 00:00:00 2001 From: yedongfu Date: Wed, 7 Aug 2019 16:20:08 +0800 Subject: [PATCH 3/9] docker no color --- debug-trace.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debug-trace.js b/debug-trace.js index e58c8aa..d62bcb3 100644 --- a/debug-trace.js +++ b/debug-trace.js @@ -74,7 +74,7 @@ console.traceFormat = function (call, method) { var str = console.format(call); var color = '99'; - if (!isatty) { + if (!isatty || process.env.IS_DOCKER) { return str; } diff --git a/package.json b/package.json index b01881c..3d1cfb4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug-trace2", - "version": "2.0.4", + "version": "2.0.5", "description": "Adds a handy `trace` flag to the console object to prepend the file and line number", "main": "./debug-trace", "browser": "./debug-trace-browser", From e76babf9bbf23335219eef65fdb809b8e8a2ed4e Mon Sep 17 00:00:00 2001 From: yedongfu Date: Tue, 20 Aug 2019 11:14:31 +0800 Subject: [PATCH 4/9] console.error begin a - --- debug-trace.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/debug-trace.js b/debug-trace.js index d62bcb3..4d78c6a 100644 --- a/debug-trace.js +++ b/debug-trace.js @@ -77,6 +77,9 @@ console.traceFormat = function (call, method) { if (!isatty || process.env.IS_DOCKER) { return str; } + if (method === 'error') { // 因为k8s无法区分node的error和out,所以加上这个特殊格式 + str = '-' + str + } if (console.traceOptions.colors !== false) { if (console.traceOptions.colors === undefined || console.traceOptions.colors[method] === undefined) { From 306f8712f39db13ae18ad9a570e547e2f1b57033 Mon Sep 17 00:00:00 2001 From: yedongfu Date: Tue, 20 Aug 2019 11:15:01 +0800 Subject: [PATCH 5/9] inc ver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3d1cfb4..6b43e52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug-trace2", - "version": "2.0.5", + "version": "2.0.6", "description": "Adds a handy `trace` flag to the console object to prepend the file and line number", "main": "./debug-trace", "browser": "./debug-trace-browser", From c6955046fbc5df52d854d2898fdcc0ddde206bec Mon Sep 17 00:00:00 2001 From: yedongfu Date: Tue, 20 Aug 2019 11:41:36 +0800 Subject: [PATCH 6/9] add | --- debug-trace.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debug-trace.js b/debug-trace.js index 4d78c6a..c1306fb 100644 --- a/debug-trace.js +++ b/debug-trace.js @@ -78,7 +78,7 @@ console.traceFormat = function (call, method) { return str; } if (method === 'error') { // 因为k8s无法区分node的error和out,所以加上这个特殊格式 - str = '-' + str + str = '|' + str } if (console.traceOptions.colors !== false) { diff --git a/package.json b/package.json index 6b43e52..74b7566 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug-trace2", - "version": "2.0.6", + "version": "2.0.7", "description": "Adds a handy `trace` flag to the console object to prepend the file and line number", "main": "./debug-trace", "browser": "./debug-trace-browser", From b8b8157231c6a1ef052a42bc60b543ad8a1721ad Mon Sep 17 00:00:00 2001 From: yedongfu Date: Thu, 22 Aug 2019 16:14:33 +0800 Subject: [PATCH 7/9] update error log --- debug-trace.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debug-trace.js b/debug-trace.js index c1306fb..fd1e1ca 100644 --- a/debug-trace.js +++ b/debug-trace.js @@ -78,7 +78,7 @@ console.traceFormat = function (call, method) { return str; } if (method === 'error') { // 因为k8s无法区分node的error和out,所以加上这个特殊格式 - str = '|' + str + str += '|' } if (console.traceOptions.colors !== false) { diff --git a/package.json b/package.json index 74b7566..510f261 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug-trace2", - "version": "2.0.7", + "version": "2.0.8", "description": "Adds a handy `trace` flag to the console object to prepend the file and line number", "main": "./debug-trace", "browser": "./debug-trace-browser", From 3069e4ce2fb24e25aa5eb5c4965173bb13e5d8c2 Mon Sep 17 00:00:00 2001 From: yedongfu Date: Thu, 22 Aug 2019 16:16:06 +0800 Subject: [PATCH 8/9] update error --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 510f261..b655752 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "debug-trace2", - "version": "2.0.8", + "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", From 75c6f5c3162169b124c363b4ebf8ca49dd88c53f Mon Sep 17 00:00:00 2001 From: yedongfu Date: Thu, 22 Aug 2019 16:16:10 +0800 Subject: [PATCH 9/9] update error --- pub.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pub.js 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]})