Skip to content

Commit

Permalink
fix(debugging): Allow no colour (for INFO logs, which were transparen…
Browse files Browse the repository at this point in the history
…t in light mode)
  • Loading branch information
SkepticMystic committed Apr 12, 2024
1 parent 2e2d1a0 commit 1b2c41d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
export const LOG_LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"] as const;
export type LogLevels = (typeof LOG_LEVELS)[number];

const LEVEL_COLOURS: Record<LogLevels, string> = {
const LEVEL_COLOURS: Record<LogLevels, string | null> = {
DEBUG: "#999",
INFO: "#fff",
INFO: null,
WARN: "#f90",
ERROR: "#f00",
};

const build_prefix = (level: LogLevels) => [
`%c[BC:${level}][${new Date().toISOString().split("T")[1]}]`,
`color: ${LEVEL_COLOURS[level]};`,
"\n",
];
const build_prefix = (level: LogLevels) => {
const colour = LEVEL_COLOURS[level];

const prefix = `[BC:${level}][${new Date().toISOString().split("T")[1]}]`;

return [
colour ? `%c${prefix}` : prefix,
colour ? `color: ${LEVEL_COLOURS[level]};` : "",
"\n",
];
};

class Logger {
level_i!: number;
Expand Down

0 comments on commit 1b2c41d

Please sign in to comment.