-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
47 lines (41 loc) · 983 Bytes
/
logger.ts
File metadata and controls
47 lines (41 loc) · 983 Bytes
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
38
39
40
41
42
43
44
45
46
47
type LogLevel = "LOG" | "WARN" | "ERROR";
export type Identifier = string | string[];
function formatIdentifier(identifier: Identifier): string {
if (Array.isArray(identifier)) {
return identifier.map((id) => `[${id}]`).join(" ");
}
return `[${identifier}]`;
}
function formatMessage(
level: LogLevel,
identifier: Identifier,
message: string
): string {
return `[${level}] ${formatIdentifier(identifier)} ${message}`;
}
export function log(
identifier: Identifier,
message: string,
...args: any[]
): void {
console.log(formatMessage("LOG", identifier, message), ...args);
}
export function warn(
identifier: Identifier,
message: string,
...args: any[]
): void {
console.warn(formatMessage("WARN", identifier, message), ...args);
}
export function error(
identifier: Identifier,
message: string,
...args: any[]
): void {
console.error(formatMessage("ERROR", identifier, message), ...args);
}
export default {
log,
warn,
error,
};