mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-07-30 22:46:27 -05:00
feat: 🔊 Logger update
This commit is contained in:
parent
a8759b3a4e
commit
860e2c8c7b
|
|
@ -1,6 +1,9 @@
|
|||
import { getVersion } from "../utils";
|
||||
import { defaultProcessRawData, processDataBuilder } from "../data/mdb"
|
||||
import { CommonMusicDataField, readJSONOrXML, readXML } from "../data/mdb";
|
||||
import Logger from "../utils/logger"
|
||||
|
||||
const logger = new Logger("MusicList")
|
||||
|
||||
export const playableMusic: EPR = async (info, data, send) => {
|
||||
const version = getVersion(info);
|
||||
|
|
@ -10,8 +13,8 @@ export const playableMusic: EPR = async (info, data, send) => {
|
|||
music = (await defaultProcessRawData('data/mdb/custom.xml')).music
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
console.error("Fallback: Using default MDB method.")
|
||||
logger.error(e.stack);
|
||||
logger.error("Fallback: Using default MDB method.")
|
||||
music = [];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import { playableMusic } from "./handlers/MusicList"
|
|||
import { getPlayer, check, regist, savePlayer } from "./handlers/profiles";
|
||||
import { updatePlayerInfo } from "./handlers/webui";
|
||||
import { isAsphyxiaDebugMode, isRequiredCoreVersion } from "./utils";
|
||||
import Logger from "./utils/logger";
|
||||
|
||||
const logger = new Logger("main")
|
||||
|
||||
export function register() {
|
||||
if(!isRequiredCoreVersion(1, 20)) {
|
||||
|
|
@ -65,9 +68,7 @@ export function register() {
|
|||
|
||||
R.Unhandled(async (info, data, send) => {
|
||||
if (["eventlog"].includes(info.module)) return;
|
||||
console.error(`Received Unhandled Response on ${info.method} by ${info.model}/${info.module}`)
|
||||
if (isAsphyxiaDebugMode()){
|
||||
console.error(`Received Request: ${JSON.stringify(data, null, 4)}`)
|
||||
}
|
||||
logger.error(`Received Unhandled Response on ${info.method} by ${info.model}/${info.module}`)
|
||||
logger.debugError(`Received Request: ${JSON.stringify(data, null, 4)}`)
|
||||
})
|
||||
}
|
||||
25
gitadora@asphyxia/utils/logger.ts
Normal file
25
gitadora@asphyxia/utils/logger.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { isAsphyxiaDebugMode } from ".";
|
||||
|
||||
export default class Logger {
|
||||
public category: string | null;
|
||||
|
||||
public constructor(category?: string) {
|
||||
this.category = (category == null) ? null : `[${category}]`
|
||||
}
|
||||
|
||||
public error(...args: any[]) {
|
||||
this.argsHandler(console.error, ...args)
|
||||
}
|
||||
public debugError(...args: any[]) {
|
||||
if (isAsphyxiaDebugMode()) {
|
||||
this.argsHandler(console.warn, ...args)
|
||||
}
|
||||
}
|
||||
private argsHandler(target: Function, ...args: any[]) {
|
||||
if (this.category == null) {
|
||||
target(...args)
|
||||
} else {
|
||||
target(this.category, ...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user