From 4ae28e48b52e9469de9bc52167b7e363220172d5 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 18 Sep 2019 17:57:05 +0800 Subject: [PATCH] feat: disable console log for pkg --- lib/config.js | 1 + lib/pkg.js | 9 ++++++++- lib/utils/logger.js | 14 ++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/config.js b/lib/config.js index 3df78baa8..1eb624166 100644 --- a/lib/config.js +++ b/lib/config.js @@ -27,6 +27,7 @@ module.exports = { }, get value() { return { + isPackage: envs.isPackage, connect: { port: envs.PORT || 1200, // 监听端口 socket: envs.SOCKET || null, // 监听 Unix Socket, null 为禁用 diff --git a/lib/pkg.js b/lib/pkg.js index 160e52668..f02cacb6b 100644 --- a/lib/pkg.js +++ b/lib/pkg.js @@ -3,7 +3,14 @@ const config = require('./config'); module.exports = { init: (conf) => { - config.set(conf); + config.set( + Object.assign( + { + isPackage: true, + }, + conf + ) + ); app = require('./app'); }, request: (path) => diff --git a/lib/utils/logger.js b/lib/utils/logger.js index cc07dea17..3c1db4f65 100644 --- a/lib/utils/logger.js +++ b/lib/utils/logger.js @@ -21,11 +21,13 @@ const logger = winston.createLogger({ // If we're not in production then log to the `console` with the format: // `${info.level}: ${info.message} JSON.stringify({ ...rest }) ` // -logger.add( - new winston.transports.Console({ - format: winston.format.combine(winston.format.colorize(), winston.format.simple()), - silent: process.env.NODE_ENV === 'test', - }) -); +if (!config.isPackage) { + logger.add( + new winston.transports.Console({ + format: winston.format.combine(winston.format.colorize(), winston.format.simple()), + silent: process.env.NODE_ENV === 'test', + }) + ); +} module.exports = logger;