From e555f55bb34bd9ad3717dc4897d1314b5e10136a Mon Sep 17 00:00:00 2001 From: lemanzhang Date: Sat, 27 Apr 2019 15:24:37 +0800 Subject: [PATCH] fix: resolved Tencent/TSW#317 --- bin/proxy/master.js | 9 +++------ bin/tsw/util/logger/logger.config.js | 5 ++--- bin/tsw/util/logger/logger.js | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bin/proxy/master.js b/bin/proxy/master.js index 594b966d..7697b642 100644 --- a/bin/proxy/master.js +++ b/bin/proxy/master.js @@ -16,7 +16,6 @@ const cpuUtil = require('util/cpu.js'); const fs = require('fs'); const serverOS = require('util/isWindows.js'); const mail = require('util/mail/mail.js'); -const { debugOptions } = process.binding('config'); const methodMap = {}; const workerMap = {}; const cpuMap = []; @@ -94,13 +93,11 @@ process.on('unhandledRejection', (errorOrReason, currPromise) => { startServer(); - // 通过cluster启动master && worker function startServer() { - let useWorker = true; - - if (debugOptions.inspectorEnabled) { + const useInspectFlag = process.execArgv.join().includes('inspect'); + if (useInspectFlag) { useWorker = false; } @@ -161,7 +158,7 @@ function startServer() { require('runtime/md5.checker.js').check(); }, 30 * 60000); - if (cluster.isMaster && debugOptions.inspectorEnabled) { + if (cluster.isMaster && useInspectFlag) { logger.setLogLevel('info'); logger.info('inspectorEnabled, start listening'); process.emit('message', { diff --git a/bin/tsw/util/logger/logger.config.js b/bin/tsw/util/logger/logger.config.js index 8da66e8d..bcc76c5e 100644 --- a/bin/tsw/util/logger/logger.config.js +++ b/bin/tsw/util/logger/logger.config.js @@ -7,8 +7,7 @@ */ 'use strict'; - -const { debugOptions } = process.binding('config'); +const useInspectFlag = process.execArgv.join().includes('inspect'); this.levelMap = { 'debug': 10, @@ -23,7 +22,7 @@ this.logLevel = null; this.getLogLevel = function() { - if (debugOptions && debugOptions.inspectorEnabled) { + if (useInspectFlag) { return this.levelMap['debug']; } diff --git a/bin/tsw/util/logger/logger.js b/bin/tsw/util/logger/logger.js index 28416aa1..363da307 100644 --- a/bin/tsw/util/logger/logger.js +++ b/bin/tsw/util/logger/logger.js @@ -13,7 +13,6 @@ const util = require('util'); const contextMod = require('context.js'); const callInfo = require('./callInfo.js'); const { isWin32Like } = require('util/isWindows.js'); -const { debugOptions } = process.binding('config'); const tnm2 = require('api/tnm2'); const canIuse = /^[0-9a-zA-Z_-]{0,64}$/; const cache = global[__filename] || { @@ -301,10 +300,11 @@ Logger.prototype = { }, writeLog: function(type, str, obj) { - const level = this.type2level(type); const log = this.getLog(); const allow = filter(level, str, obj); + const useInspectFlag = process.execArgv.join().includes('inspect'); + let logStr = null; if (log || allow === true || level >= config.getLogLevel()) { @@ -322,7 +322,7 @@ Logger.prototype = { return this; } - if (debugOptions && debugOptions.inspectorEnabled) { + if (useInspectFlag) { // Chrome写入原始日志 this.fillInspect(logStr, level); // 控制台写入高亮日志