summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/utilities/console.ts
blob: e04a390b88220bbf98cef1b07cfb8af603ec010a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { isProdEnv } from ".";

type LoggerType = "info" | "warning" | "error";

export function LOG(type: LoggerType, msg: string, ...payload: any[]) {
  if (!isProdEnv) {
    let logger = console.log;
    if (type === "warning") {
      logger = console.warn;
    } else if (type === "error") {
      logger = console.error;
    }
    logger(`[${type}] ${msg}`, ...payload);
  }
}

export function ENSURE(condition: boolean, msg: string, ...payload: any[]) {
  if (condition) {
    LOG("error", msg, payload);
  }
}

export function GROUP(
  header: string,
  content: (logger: typeof console.log) => void
) {
  if (!isProdEnv) {
    console.group(header);
    content(console.log);
    console.groupEnd();
  }
}

export const ASSERT = console.assert;