aboutsummaryrefslogtreecommitdiff
path: root/packages/tools/src/vercel/logger.ts
blob: f1752e1f82378435a2ddffaeaa74ab771f7d15ba (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
export interface Logger {
	debug: (message: string, data?: unknown) => void
	info: (message: string, data?: unknown) => void
	warn: (message: string, data?: unknown) => void
	error: (message: string, data?: unknown) => void
}

export const createLogger = (verbose: boolean): Logger => {
	if (!verbose) {
		return {
			debug: () => {},
			info: () => {},
			warn: () => {},
			error: () => {},
		}
	}

	return {
		debug: (message: string, data?: unknown) => {
			console.log(
				`[supermemory] ${message}`,
				data ? JSON.stringify(data, null, 2) : "",
			)
		},
		info: (message: string, data?: unknown) => {
			console.log(
				`[supermemory] ${message}`,
				data ? JSON.stringify(data, null, 2) : "",
			)
		},
		warn: (message: string, data?: unknown) => {
			console.warn(
				`[supermemory] ${message}`,
				data ? JSON.stringify(data, null, 2) : "",
			)
		},
		error: (message: string, data?: unknown) => {
			console.error(
				`[supermemory] ${message}`,
				data ? JSON.stringify(data, null, 2) : "",
			)
		},
	}
}