forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleLog.ts
More file actions
32 lines (27 loc) · 750 Bytes
/
ConsoleLog.ts
File metadata and controls
32 lines (27 loc) · 750 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
import { ILog } from "./ILog.js";
export class ConsoleLog implements ILog {
public trace(message: string): void {
this.log("debug", message);
}
public info(message: string): void {
this.log("info", message);
}
public warn(message: string): void {
this.log("warn", message);
}
public error(message: string): void {
this.log("error", message);
}
private log(level: string, message: string) {
if (console) {
const msg = `Exceptionless:${new Date().toISOString()} [${level}] ${message}`;
// @ts-expect-error TS7053
const logFn = console[level] as (msg: string) => void;
if (logFn) {
logFn(msg);
} else if (console["log"]) {
console["log"](msg);
}
}
}
}