forked from clerk/javascript
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.ts
41 lines (39 loc) · 1.07 KB
/
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
37
38
39
40
41
/* eslint-disable turbo/no-undeclared-env-vars */
import { default as chalk } from 'chalk';
const getRandomChalkColor = () => {
const colors = [
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
'redBright',
'greenBright',
'yellowBright',
'blueBright',
'magentaBright',
'cyanBright',
];
return colors[Math.floor(Math.random() * colors.length)];
};
type CreateLoggerOptions = { prefix: string; color?: string };
export const createLogger = (opts: CreateLoggerOptions) => {
const { color, prefix } = opts;
const prefixColor = color || getRandomChalkColor();
return {
info: (msg: string) => {
if (
process.env.E2E_DEBUG === 'true' ||
process.env.E2E_DEBUG === '1' ||
process.env.ACTIONS_STEP_DEBUG ||
process.env.ACTIONS_RUNNER_DEBUG
) {
console.info(`${chalk[prefixColor](`[${prefix}]`)} ${msg}`);
}
},
child: (childOpts: CreateLoggerOptions) => {
return createLogger({ prefix: `${prefix} :: ${childOpts.prefix}`, color: prefixColor });
},
};
};