wo-core-coco/coco-unicloud.js
2024-02-05 09:50:07 +08:00

31 lines
1.3 KiB
JavaScript
Raw Permalink 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.

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))
}
},
}