wo-core-coco/coco-browser.js
2024-06-24 09:49:28 +08:00

66 lines
2.1 KiB
JavaScript

function routeNow () {
const pageNow = globalThis.getCurrentPages()[globalThis.getCurrentPages().length - 1]
return pageNow?.route || 'VueApp'
}
function deepStringify (args = []) {
return JSON.stringify(args, null, 2) // used in web browser console, to avoid clicking to expand by hand.
}
// function prettyPrint (title, text, color) {
// console.log(
// `%c ${title} %c ${text} %c`,
// `background:${color};border:1px solid ${color}; padding: 1px; border-radius: 2px 0 0 2px; color: #fff;`,
// `border:1px solid ${color}; padding: 1px; border-radius: 0 2px 2px 0; color: ${color};`,
// 'background:transparent'
// )
// }
module.exports =
{
cclog (...args) {
console.log(
`%c ${new Date().toJSON()} [LOG] ${routeNow()}`,
'background: #808080; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccinfo (...args) {
console.info(
`%c ${new Date().toJSON()} [INFO] ${routeNow()}`,
'background: #0000ff; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccgood (...args) {
console.info(
`%c ${new Date().toJSON()} [GOOD] ${routeNow()}`,
'background: #2ecc71; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccwarn (...args) {
console.warn(
`%c ${new Date().toJSON()} [WARN] ${routeNow()}`,
'background: #f39c12; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccerror (...args) {
console.error(
`%c ${new Date().toJSON()} [ERROR] ${routeNow()}`,
'background: #c0392b; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccdebug (...args) {
if (process.env.NODE_ENV !== 'production') {
console.debug(
`%c ${new Date().toJSON()} [DEBUG] ${routeNow()}`,
'background: purple; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
}
},
}