summaryrefslogtreecommitdiff
path: root/packages/integrations/sitemap/src/utils/logger.ts
blob: 3292bbdfc6bba7c0e2a611429d342e8505e51a5e (plain) (blame)
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
// @internal
export interface ILogger {
	info(msg: string): void;
	success(msg: string): void;
	warn(msg: string): void;
	error(msg: string): void;
}

// @internal
export class Logger implements ILogger {
	private colors = {
		reset: '\x1b[0m',
		fg: {
			red: '\x1b[31m',
			green: '\x1b[32m',
			yellow: '\x1b[33m',
		},
	} as const;

	private packageName: string;

	constructor(packageName: string) {
		this.packageName = packageName;
	}

	private log(msg: string, prefix = '') {
		// eslint-disable-next-line no-console
		console.log(`%s${this.packageName}:%s ${msg}\n`, prefix, prefix ? this.colors.reset : '');
	}

	info(msg: string) {
		this.log(msg);
	}

	success(msg: string) {
		this.log(msg, this.colors.fg.green);
	}

	warn(msg: string) {
		this.log(`Skipped!\n${msg}`, this.colors.fg.yellow);
	}

	error(msg: string) {
		this.log(`Failed!\n${msg}`, this.colors.fg.red);
	}
}