diff --git a/coco.js b/coco.js index cca38e4..5f6a34a 100644 --- a/coco.js +++ b/coco.js @@ -20,35 +20,35 @@ module.exports = // 客户端 uniapp cclog (...args) { console.log( - `%c ${new Date().toJSON()} [LG] ${routeNow()}`, + `%c ${new Date().toJSON()} [LOG] ${routeNow()}`, 'background: #808080; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', ...deepInspect(args) ) }, ccinfo (...args) { console.info( - `%c ${new Date().toJSON()} [IF] ${routeNow()}`, + `%c ${new Date().toJSON()} [INFO] ${routeNow()}`, 'background: #0000ff; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', ...deepInspect(args) ) }, ccgood (...args) { console.info( - `%c ${new Date().toJSON()} [OK] ${routeNow()}`, + `%c ${new Date().toJSON()} [GOOD] ${routeNow()}`, 'background: #2ecc71; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', ...deepInspect(args) ) }, ccwarn (...args) { console.warn( - `%c ${new Date().toJSON()} [WA] ${routeNow()}`, + `%c ${new Date().toJSON()} [WARN] ${routeNow()}`, 'background: #f39c12; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', ...deepInspect(args) ) }, ccerror (...args) { console.error( - `%c ${new Date().toJSON()} [ER] ${routeNow()}`, + `%c ${new Date().toJSON()} [ERROR] ${routeNow()}`, 'background: #c0392b; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', ...deepInspect(args) ) @@ -56,7 +56,7 @@ module.exports = ccdebug (...args) { if (process.env.NODE_ENV !== 'production') { console.debug( - `%c ${new Date().toJSON()} [DB] ${routeNow()}`, + `%c ${new Date().toJSON()} [DEBUG] ${routeNow()}`, 'background: #ff0000; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;', ...deepInspect(args) ) @@ -69,26 +69,26 @@ module.exports = // HBuilder 内置环境的 console 不支持颜色。为了检查是否支持颜色,测试 uniCloud 是否存在(不存在说明在自己的server环境里), // 或 require('supports-color'),相应的返回不同的函数。 cclog (...args) { - console.log(new Date().toJSON(), '[LG]', ...deepInspect(args)) + console.log(new Date().toJSON(), '[LOG]', ...deepInspect(args)) }, ccinfo (...args) { - console.info(new Date().toJSON(), '[IF]', ...deepInspect(args)) + console.info(new Date().toJSON(), '[INFO]', ...deepInspect(args)) }, ccgood (...args) { - console.info(new Date().toJSON(), '[OK]', ...deepInspect(args)) + console.info(new Date().toJSON(), '[GOOD]', ...deepInspect(args)) }, ccwarn (...args) { // console.warn will appear in pm2's error log - console.warn(new Date().toJSON(), '[WA]', ...deepInspect(args)) + console.warn(new Date().toJSON(), '[WARN]', ...deepInspect(args)) }, ccerror (...args) { // console.error will appear in pm2's error log - console.error(new Date().toJSON(), '[ER]', ...deepInspect(args)) + console.error(new Date().toJSON(), '[ERROR]', ...deepInspect(args)) }, ccdebug (...args) { if ('production' !== process.env.NODE_ENV) { // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV` - console.log(new Date().toJSON(), '[DB]', ...deepInspect(args)) + console.log(new Date().toJSON(), '[DEBUG]', ...deepInspect(args)) } }, } @@ -96,41 +96,41 @@ module.exports = // 后台服务器命令行。注意如果输出重定向到文件里,会有 ESC[34m2023-10-07T12:32:00.915ZESC[39m 这样的特殊标识。 // 在 pm2 里,为了防止特殊标志,可用 --no-color cclog (...args) { - console.log(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[LG]'), ...deepInspect(args, true)) + console.log(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[LOG]'), ...deepInspect(args, true)) }, ccinfo (...args) { - console.info(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[IF]'), ...deepInspect(args, true)) + console.info(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[INFO]'), ...deepInspect(args, true)) }, ccgood (...args) { - console.info(colors.bgWhite(new Date().toJSON()), colors.bgGreen('[OK]'), ...deepInspect(args, true)) + console.info(colors.bgWhite(new Date().toJSON()), colors.bgGreen('[GOOD]'), ...deepInspect(args, true)) }, ccwarn (...args) { // console.warn will appear in pm2's error log - console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow('[WA]'), ...deepInspect(args, true)) + console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow('[WARN]'), ...deepInspect(args, true)) }, ccerror (...args) { // console.error will appear in pm2's error log - console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed('[ER]'), ...deepInspect(args, true)) + console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed('[ERROR]'), ...deepInspect(args, true)) }, ccdebug (...args) { if ('production' !== process.env.NODE_ENV) { // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV` - console.log(colors.rainbow(new Date().toJSON()), colors.rainbow('[DB]'), ...deepInspect(args, true)) + console.log(colors.rainbow(new Date().toJSON()), colors.rainbow('[DEBUG]'), ...deepInspect(args, true)) } }, ccinput (headers, path, indata) { - console.log(colors.bgWhite(new Date().toJSON()), colors.bgCyan('[LG] (Request-Headers)'), colors.cyan(headers)) - console.log(colors.bgWhite(new Date().toJSON()), colors.bgBlue(`[IF] (IN) ${path}`), colors.blue(util.inspect(indata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了 + console.log(colors.bgWhite(new Date().toJSON()), colors.bgCyan('[LOG] (Request-Headers)'), colors.cyan(headers)) + console.info(colors.bgWhite(new Date().toJSON()), colors.bgBlue(`[INFO] (INDATA) ${path}`), colors.blue(util.inspect(indata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了 }, ccoutput (path, outdata) { - console.log(colors.bgWhite(new Date().toJSON()), colors.bgGreen(`[OK] (OUT) ${path}`), colors.green(util.inspect(outdata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了 + console.log(colors.bgWhite(new Date().toJSON()), colors.bgGreen(`[GOOD] (OUTDATA) ${path}`), colors.green(util.inspect(outdata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了 }, ccexcept (path, error) { outdata = { _state: 'WOBASE_EXCEPTION', error } - console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed(`[ER] (OUT) ${path}`), colors.red(util.inspect(outdata, { showHidden: false, depth: null, colors: true }))) + console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed(`[ERROR] (OUT) ${path}`), colors.red(util.inspect(outdata, { showHidden: false, depth: null, colors: true }))) }, ccunknown (path) { - console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow(`[WA] (OUT) ${path}`), colors.yellow({ _state: 'WOBASE_API_UNKNOWN', response: 401 })) + console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow(`[WARN] (OUT) ${path}`), colors.yellow({ _state: 'WOBASE_API_UNKNOWN', response: 401 })) } }