mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
updated verbosity module with fixed method
This commit is contained in:
parent
6454287277
commit
125d732b4f
@ -41,6 +41,7 @@
|
||||
"axios": "^0.20.0",
|
||||
"babel-core": "^6.26.3",
|
||||
"classnames": "^2.2.6",
|
||||
"colors": "^1.4.0",
|
||||
"concat-stream": "^2.0.0",
|
||||
"cookie_js": "^1.4.0",
|
||||
"dotenv": "^8.2.0",
|
||||
|
@ -2,49 +2,88 @@ import settings from 'core/libs/settings'
|
||||
import { objectToArray } from 'core'
|
||||
import stackTrace from 'stack-trace'
|
||||
import path from 'path'
|
||||
import colors from 'colors'
|
||||
const verbosity_enabled = settings('verbosity')
|
||||
|
||||
export function verbosity(data, params){
|
||||
export function verbosity(data, params, stackTraceParams){
|
||||
if(!verbosity_enabled) return false
|
||||
let renderOpt = []
|
||||
let initData;
|
||||
initData = data
|
||||
|
||||
let opt = {
|
||||
stackTrace: {
|
||||
method: true,
|
||||
line: false,
|
||||
file: false,
|
||||
time: true
|
||||
},
|
||||
color: "#bada55",
|
||||
type: "log",
|
||||
color: "green",
|
||||
type: "log"
|
||||
}
|
||||
let optStackTrace = {
|
||||
activeColor: true,
|
||||
line: false,
|
||||
method: true,
|
||||
file: false,
|
||||
time: true
|
||||
}
|
||||
|
||||
const frame = stackTrace.get()[1]
|
||||
|
||||
const stackTraceData = {
|
||||
time: new Date().toLocaleTimeString(),
|
||||
line: `(:${frame.getLineNumber()})`,
|
||||
file: path.basename(frame.getFileName()),
|
||||
method: `%c [${frame.getFunctionName()}]`
|
||||
method: `[${frame.getFunctionName()}]`
|
||||
}
|
||||
|
||||
if (params) {
|
||||
opt = { ...opt, ...params }
|
||||
}
|
||||
|
||||
objectToArray(opt.stackTrace).forEach(e => {
|
||||
if (typeof e !== "undefined" && e) {
|
||||
if(e.value){
|
||||
renderOpt.push(stackTraceData[e.key])
|
||||
}
|
||||
if (typeof(params) !== "undefined" || params != null) {
|
||||
objectToArray(params).forEach((e) => {
|
||||
if(typeof(e.value) !== "undefined"){
|
||||
opt[e.key] = e.value
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
renderOpt? renderOpt.push(" >") : null
|
||||
|
||||
if (Array.isArray(data)){
|
||||
return console[opt.type](renderOpt.toString(), `color: ${opt.color}`, ...data)
|
||||
if (typeof(stackTraceParams) !== "undefined" || stackTraceParams != null) {
|
||||
objectToArray(stackTraceParams).forEach((e) => {
|
||||
if(typeof(e.value) !== "undefined"){
|
||||
console.log(e.key,e.value)
|
||||
optStackTrace[e.key] = e.value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return console[opt.type](`%c${renderOpt}`, `color: ${opt.color}`, data)
|
||||
if (opt.color) {
|
||||
colors.enable()
|
||||
}
|
||||
|
||||
const stackTraceKeys = Object.keys(optStackTrace)
|
||||
const stackTraceLength = stackTraceKeys.length
|
||||
let modifyCount = 0
|
||||
let tmp
|
||||
|
||||
for (let i = 0; i < stackTraceLength; i++) {
|
||||
const key = stackTraceKeys[i]
|
||||
const value = optStackTrace[stackTraceKeys[i]]
|
||||
const divisor = (i == (stackTraceLength - 1)? " | " : " > ")
|
||||
// console.log(`[${key}] is the ${i == stackTraceLength? "last opt" : `n[${i}]` }`)
|
||||
// console.log(i, "/", stackTraceLength -1)
|
||||
if(typeof(stackTraceData[key]) !== "undefined" && value){
|
||||
if (Array.isArray(initData)) {
|
||||
if (modifyCount == 0) {
|
||||
tmp = (`${stackTraceData[key]}`[opt.color] + divisor)
|
||||
}else{
|
||||
tmp = (`${stackTraceData[key]}`[opt.color] + divisor + tmp)
|
||||
}
|
||||
if (i == (stackTraceLength - 1)){
|
||||
data.unshift(tmp)
|
||||
}
|
||||
}else{
|
||||
data = (`${stackTraceData[key]}`[opt.color] + divisor + data)
|
||||
}
|
||||
modifyCount++
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(initData)) {
|
||||
return console[opt.type](...data)
|
||||
}
|
||||
return console[opt.type](data)
|
||||
}
|
||||
|
||||
export default verbosity
|
Loading…
x
Reference in New Issue
Block a user