-
-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathlogger.ts
More file actions
41 lines (37 loc) · 1.11 KB
/
logger.ts
File metadata and controls
41 lines (37 loc) · 1.11 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
const warningMap = new Map<string, boolean>();
/**
* Log a warning message only once per run.
* This is used to avoid spamming the console with the same message.
*/
export function warnOnce(message: string): void {
if (!warningMap.has(message)) {
warningMap.set(message, true);
// oxlint-disable-next-line eslint(no-console), typescript-eslint(no-unsafe-member-access)
console.warn(yellow(prefix(message)));
}
}
/**
* Prefix message with `› [value]`.
*
* Example:
* ```
* › [@sentry/react-native/expo] This is a warning message
* ```
*/
export function prefix(value: string): string {
return `› ${bold('[@sentry/react-native/expo]')} ${value}`;
}
/**
* The same as `chalk.yellow`
* This code is part of the SDK, we don't want to introduce a dependency on `chalk` just for this.
*/
export function yellow(message: string): string {
return `\x1b[33m${message}\x1b[0m`;
}
/**
* The same as `chalk.bold`
* This code is part of the SDK, we don't want to introduce a dependency on `chalk` just for this.
*/
export function bold(message: string): string {
return `\x1b[1m${message}\x1b[22m`;
}