wo-base-netinfo/tool4log.js
2022-05-03 14:20:43 +08:00

42 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const colors = require('colors')
// HBuilder 内置环境的 console 不支持颜色。为了检查是否支持颜色,可测试 uniCloud 是否存在不存在说明在自己的server环境里或 require('supports-color'),相应的返回不同的 ccXXX 函数。
module.exports = typeof uniCloud === 'undefined' ? {
cclog(...args) {
console.log({timeiso: new Date().toJSON()}, ...args)
},
ccinfo(...args) {
console.info({timeiso: new Date().toJSON()}, ...args)
},
ccerror(...args) { // console.error will appear in pm2's error log
console.error({timeiso: new Date().toJSON()}, ...args)
},
ccwarn(...args) { // console.warn will appear in pm2's error log
console.warn({timeiso: new Date().toJSON()}, ...args)
},
ccdebug(...args) {
if ('development'===process.env.NODE_ENV) { // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
console.log({timeiso: new Date().toJSON()}, ...args)
}
}
} : {
cclog(...args) {
console.log(colors.blue({timeiso: new Date().toJSON()}), ...args)
},
ccinfo(...args) {
console.info(colors.green({timeiso: new Date().toJSON()}), ...args)
},
ccerror(...args) { // console.error will appear in pm2's error log
console.error(colors.red({timeiso: new Date().toJSON()}), ...args)
},
ccwarn(...args) { // console.warn will appear in pm2's error log
console.warn(colors.yellow({timeiso: new Date().toJSON()}), ...args)
},
ccdebug(...args) {
if ('development'===process.env.NODE_ENV) { // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
console.log(colors.rainbow({timeiso: new Date().toJSON()}), ...args)
}
}
}