-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.ts
36 lines (31 loc) · 809 Bytes
/
logger.ts
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
import { Options } from './options';
type LogFn = (message: string) => void;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const NullLogFn: LogFn = (message: string) => {
// Log nothing
};
const StdoutLogFn: LogFn = (message: string): void => {
console.log(message);
};
const StderrLogFn: LogFn = (message: string): void => {
console.error(message);
};
export interface Logger {
error: LogFn;
info: LogFn;
debug: LogFn;
}
export const getLogger = (options: Options): Logger => {
if (options.silent) {
return {
error: NullLogFn,
info: NullLogFn,
debug: NullLogFn,
};
}
return {
error: StderrLogFn,
info: StdoutLogFn,
debug: options.verbose ? StdoutLogFn : NullLogFn,
};
};