console.log({_at, ...})

This commit is contained in:
Luk
2024-02-05 09:50:07 +08:00
parent 98ac10723f
commit 7c0b1bce15
7 changed files with 240 additions and 130 deletions

31
coco-unicloud.js Normal file
View File

@@ -0,0 +1,31 @@
function deepStringify (args = []) {
return JSON.stringify(args, null, 2) // used in web browser console, to avoid clicking to expand by hand.
}
module.exports = {
// HBuilder 内置环境的 云空间 console 不支持颜色。为了检查是否支持颜色,测试 uniCloud 是否存在不存在说明在自己的server环境里
// 或 require('supports-color'),相应的返回不同的函数。
cclog (...args) {
console.log(new Date().toJSON(), '[LOG]', deepStringify(args))
},
ccinfo (...args) {
console.info(new Date().toJSON(), '[INFO]', deepStringify(args))
},
ccgood (...args) {
console.info(new Date().toJSON(), '[GOOD]', deepStringify(args))
},
ccwarn (...args) {
// console.warn will appear in pm2's error log
console.warn(new Date().toJSON(), '[WARN]', deepStringify(args))
},
ccerror (...args) {
// console.error will appear in pm2's error log
console.error(new Date().toJSON(), '[ERROR]', deepStringify(args))
},
ccdebug (...args) {
if ('production' !== process.env.NODE_ENV) {
// 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
console.log(new Date().toJSON(), '[DEBUG]', deepStringify(args))
}
},
}