Added new logger

This commit is contained in:
2024-11-14 18:44:07 +01:00
parent c868edcae4
commit d938dd9d3e
16 changed files with 81 additions and 129 deletions

View File

@@ -14,8 +14,7 @@ const AllLogs = {
info: { m: "INFO", c: null },
error: { m: "ERROR", c: "#ff6666" },
warn: { m: "WARN", c: "#ffcc99" },
debug: { m: "DEBUG", c: "#66ff66" },
custom: { m: "CUSTOM", c: null }
debug: { m: "DEBUG", c: "#66ff66" }
} as const
type LogType = keyof typeof AllLogs
@@ -28,34 +27,28 @@ type CustomColorProps = {
color: string
}
export function log(m: string, t: LogType = "info", c?: CustomColorProps): void {
export function log(m: string, t: LogType, c?: CustomColorProps): void {
const date = new Date()
const time = logTimeFormatter(date)
const logType = AllLogs[t].m
const logColor = AllLogs[t].c
const message = `[${logType}] ${time} | ${m}`
if (t === "info") {
console.log(message)
return
}
if (t === "custom") {
if (!c) {
console.error("Custom log type requires a color.")
if (!c) {
if (t === "info") {
console.log(message)
return
}
if (c.type === "preset") {
const color = colors[c.color]
console.log(cc(message, color))
} else {
console.log(cc(message, c.color))
}
console.log(cc(message, logColor!))
return
}
console.log(cc(message, logColor!))
if (c.type === "preset") {
const color = colors[c.color]
console.log(cc(message, color))
} else {
console.log(cc(message, c.color))
}
}
function cc(text: string, color: string) {