mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
[update] verbosity new model
This commit is contained in:
parent
51a33b5415
commit
b9e2d3a03d
@ -1,30 +1,44 @@
|
|||||||
import settings from 'core/libs/settings'
|
import settings from 'core/libs/settings'
|
||||||
|
import { objectToArray } from 'core'
|
||||||
import stackTrace from 'stack-trace'
|
import stackTrace from 'stack-trace'
|
||||||
|
import path from 'path'
|
||||||
const verbosity_enabled = settings('verbosity')
|
const verbosity_enabled = settings('verbosity')
|
||||||
|
|
||||||
export const verbosity = {
|
export function verbosity(data, params){
|
||||||
log: (...cont) => {
|
if(!verbosity_enabled) return false
|
||||||
return verbosity_enabled ? console.log(...cont) : null
|
let optString = []
|
||||||
},
|
const frame = stackTrace.get()[1]
|
||||||
debug: (...cont) => {
|
const stackTraceData = {
|
||||||
const frame = stackTrace.get()[1]
|
line: `(:${frame.getLineNumber()})`,
|
||||||
// const line = frame.getLineNumber()
|
file: path.basename(frame.getFileName()),
|
||||||
// const file = path.basename(frame.getFileName())
|
method: `[${frame.getFunctionName()}]`,
|
||||||
const method = frame.getFunctionName()
|
}
|
||||||
|
|
||||||
return verbosity_enabled ? console.debug(`%c[${method}]`, 'color: #bada55', ...cont) : null
|
let opt = {
|
||||||
},
|
stackTrace: {
|
||||||
error: (...cont) => {
|
method: true,
|
||||||
const frame = stackTrace.get()[1]
|
line: false,
|
||||||
// const line = frame.getLineNumber()
|
file: false
|
||||||
// const file = path.basename(frame.getFileName())
|
},
|
||||||
const method = frame.getFunctionName()
|
color: "#bada55",
|
||||||
|
type: "log",
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params) {
|
||||||
|
opt = { ...opt, ...params }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
objectToArray(opt.stackTrace).forEach(e => {
|
||||||
|
if (typeof e !== "undefined" && e) {
|
||||||
|
if(e.value){
|
||||||
|
optString.push(`${stackTraceData[e.key]} >`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console[opt.type](`%c${optString}`, 'color: #bada55', data)
|
||||||
|
|
||||||
return verbosity_enabled ? console.error(`%c[${method}]`, 'color: #bada55', ...cont) : null
|
|
||||||
},
|
|
||||||
warn: (...cont) => {
|
|
||||||
return verbosity_enabled ? console.warn(...cont) : null
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default verbosity
|
export default verbosity
|
Loading…
x
Reference in New Issue
Block a user