Updated loger

This commit is contained in:
2024-11-14 18:03:26 +01:00
parent 0f583206b3
commit c868edcae4

View File

@@ -1,21 +1,63 @@
import { colorCustom as c } from "./Functions/colors.js" import chalk from "chalk"
import { logTimeFormatter } from "./Functions/intlFormaters.js" import { logTimeFormatter } from "./Functions/intlFormaters.js"
const colors = {
red: "#f38ba8",
lavender: "#b4befe",
green: "#a6e3a1",
pink: "#f5c2e7"
}
type Colors = keyof typeof colors
const AllLogs = { const AllLogs = {
info: { m: "INFO", c: null }, info: { m: "INFO", c: null },
error: { m: "ERROR", c: "#ff6666" }, error: { m: "ERROR", c: "#ff6666" },
warn: { m: "WARN", c: "#ffcc99" }, warn: { m: "WARN", c: "#ffcc99" },
debug: { m: "DEBUG", c: "#66ff66" } debug: { m: "DEBUG", c: "#66ff66" },
custom: { m: "CUSTOM", c: null }
} as const } as const
type LogType = keyof typeof AllLogs type LogType = keyof typeof AllLogs
export function log(m: string, t: LogType = "info"): void { type CustomColorProps = {
type: "preset"
color: Colors
} | {
type: "custom"
color: string
}
export function log(m: string, t: LogType = "info", c?: CustomColorProps): void {
const date = new Date() const date = new Date()
const time = logTimeFormatter(date) const time = logTimeFormatter(date)
const logType = AllLogs[t].m const logType = AllLogs[t].m
const logColor = AllLogs[t].c const logColor = AllLogs[t].c
const message = `[${logType}] ${time} | ${m}` const message = `[${logType}] ${time} | ${m}`
console.log(logColor ? c(message, logColor) : message) if (t === "info") {
console.log(message)
return
}
if (t === "custom") {
if (!c) {
console.error("Custom log type requires a color.")
return
}
if (c.type === "preset") {
const color = colors[c.color]
console.log(cc(message, color))
} else {
console.log(cc(message, c.color))
}
return
}
console.log(cc(message, logColor!))
}
function cc(text: string, color: string) {
return chalk.hex(color)(text)
} }