-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathlogger.ts
More file actions
71 lines (63 loc) · 1.64 KB
/
logger.ts
File metadata and controls
71 lines (63 loc) · 1.64 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
60
61
62
63
64
65
66
67
68
69
70
71
import { sanitize } from './sanitizeLog';
/**
* BitGo Logger with automatic sanitization in test/staging environments
*/
class BitGoLogger {
/**
* Determines if sanitization should be applied based on NODE_ENV
*/
private shouldSanitize(): boolean {
const env = process.env.NODE_ENV;
return env === 'test' || env === 'staging';
}
/**
* Sanitizes arguments if in test/staging environment
*/
private sanitizeArgs(args: unknown[]): unknown[] {
if (!this.shouldSanitize()) {
return args;
}
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();