mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +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 { objectToArray } from 'core'
|
||||
import stackTrace from 'stack-trace'
|
||||
import path from 'path'
|
||||
const verbosity_enabled = settings('verbosity')
|
||||
|
||||
export const verbosity = {
|
||||
log: (...cont) => {
|
||||
return verbosity_enabled ? console.log(...cont) : null
|
||||
},
|
||||
debug: (...cont) => {
|
||||
const frame = stackTrace.get()[1]
|
||||
// const line = frame.getLineNumber()
|
||||
// const file = path.basename(frame.getFileName())
|
||||
const method = frame.getFunctionName()
|
||||
export function verbosity(data, params){
|
||||
if(!verbosity_enabled) return false
|
||||
let optString = []
|
||||
const frame = stackTrace.get()[1]
|
||||
const stackTraceData = {
|
||||
line: `(:${frame.getLineNumber()})`,
|
||||
file: path.basename(frame.getFileName()),
|
||||
method: `[${frame.getFunctionName()}]`,
|
||||
}
|
||||
|
||||
return verbosity_enabled ? console.debug(`%c[${method}]`, 'color: #bada55', ...cont) : null
|
||||
},
|
||||
error: (...cont) => {
|
||||
const frame = stackTrace.get()[1]
|
||||
// const line = frame.getLineNumber()
|
||||
// const file = path.basename(frame.getFileName())
|
||||
const method = frame.getFunctionName()
|
||||
let opt = {
|
||||
stackTrace: {
|
||||
method: true,
|
||||
line: false,
|
||||
file: false
|
||||
},
|
||||
color: "#bada55",
|
||||
type: "log",
|
||||
}
|
||||
|
||||
return verbosity_enabled ? console.error(`%c[${method}]`, 'color: #bada55', ...cont) : null
|
||||
},
|
||||
warn: (...cont) => {
|
||||
return verbosity_enabled ? console.warn(...cont) : null
|
||||
},
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
export default verbosity
|
Loading…
x
Reference in New Issue
Block a user