-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathdebug.ts
More file actions
34 lines (28 loc) · 978 Bytes
/
debug.ts
File metadata and controls
34 lines (28 loc) · 978 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
import type { ConsentLevel, Message } from '@imtbl/audience-core';
import { LOG_PREFIX } from './config';
export class DebugLogger {
private enabled: boolean;
constructor(enabled = false) {
this.enabled = enabled;
}
logEvent(method: string, message: Message): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.log(`${LOG_PREFIX} ${method}`, message);
}
logFlush(ok: boolean, count: number): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.log(`${LOG_PREFIX} flush ${ok ? 'ok' : 'failed'} (${count} messages)`);
}
logConsent(from: ConsentLevel, to: ConsentLevel): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.log(`${LOG_PREFIX} consent ${from} → ${to}`);
}
logWarning(msg: string): void {
if (!this.enabled) return;
// eslint-disable-next-line no-console
console.warn(`${LOG_PREFIX} ${msg}`);
}
}