-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathlogger.ts
More file actions
59 lines (53 loc) · 1.36 KB
/
logger.ts
File metadata and controls
59 lines (53 loc) · 1.36 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
import { sanitize } from './sanitizeLog';
/**
* BitGo Logger with automatic sanitization for all environments
*/
class BitGoLogger {
/**
* Sanitizes arguments for all environments
*/
private sanitizeArgs(args: unknown[]): unknown[] {
return args.map((arg) => {
if (typeof arg === 'object' && arg !== null) {
return sanitize(arg);
}
return arg;
});
}
/**
* Logs a message with automatic sanitization
*/
log(...args: unknown[]): void {
const sanitized = this.sanitizeArgs(args);
// eslint-disable-next-line no-console
console.log(...sanitized);
}
/**
* Logs an error message with automatic sanitization
*/
error(...args: unknown[]): void {
const sanitized = this.sanitizeArgs(args);
// eslint-disable-next-line no-console
console.error(...sanitized);
}
/**
* Logs a warning message with automatic sanitization
*/
warn(...args: unknown[]): void {
const sanitized = this.sanitizeArgs(args);
// eslint-disable-next-line no-console
console.warn(...sanitized);
}
/**
* Logs an info message with automatic sanitization
*/
info(...args: unknown[]): void {
const sanitized = this.sanitizeArgs(args);
// eslint-disable-next-line no-console
console.info(...sanitized);
}
}
/**
* Singleton logger instance
*/
export const logger = new BitGoLogger();