输出日志时,添加背景色

This commit is contained in:
陆柯 2022-06-09 11:24:12 +08:00
parent 9525930dfb
commit 39ba7a4361

View File

@ -22,24 +22,24 @@ export default {
// 输出命令行提示,可用来取代 console.log/info/warn/error // 输出命令行提示,可用来取代 console.log/info/warn/error
cclog (...args) { cclog (...args) {
const pageName = this.thisPage()?.route || 'VueApp' const pageName = this.thisPage()?.route || 'VueApp'
console.log('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:blue', ...args) console.log('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:blue;background:lightgrey', ...args)
}, },
ccinfo (...args) { ccinfo (...args) {
const pageName = this.thisPage()?.route || 'VueApp' const pageName = this.thisPage()?.route || 'VueApp'
console.info('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:green', ...args) console.info('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:green;background:lightgrey', ...args)
}, },
ccwarn (...args) { ccwarn (...args) {
const pageName = this.thisPage().route || 'VueApp' const pageName = this.thisPage().route || 'VueApp'
console.warn('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:orange', ...args) console.warn('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:orange;background:lightgrey', ...args)
}, },
ccerror (...args) { ccerror (...args) {
const pageName = this.thisPage()?.route || 'VueApp' const pageName = this.thisPage()?.route || 'VueApp'
console.error('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:red', ...args) console.error('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:red;background:lightgrey', ...args)
}, },
ccdebug (...args) { ccdebug (...args) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
const pageName = this.thisPage()?.route || 'VueApp' const pageName = this.thisPage()?.route || 'VueApp'
console.debug('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:cyan', ...args) console.debug('%c ' + JSON.stringify({ time: new Date().toJSON(), page: pageName }), 'color:cyan;background:lightgrey', ...args)
} }
}, },
@ -232,7 +232,7 @@ export default {
JSON.stringify({ basendType, apiWho, apiTodo, apiWhat, url }) + JSON.stringify({ basendType, apiWho, apiTodo, apiWhat, url }) +
' %c ' + ' %c ' +
JSON.stringify(result), JSON.stringify(result),
'color:blue', 'color:blue;background:lightgrey',
'background:skyblue', 'background:skyblue',
'background:magenta' 'background:magenta'
) // 不知为何,直接用 result 会输出一个奇怪的对象,要主动添加 JSON.stringify 才按照期望输出。 ) // 不知为何,直接用 result 会输出一个奇怪的对象,要主动添加 JSON.stringify 才按照期望输出。