-
Notifications
You must be signed in to change notification settings - Fork 878
/
logger.ts
37 lines (33 loc) · 1.1 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
import { Logger } from "tslog";
const logLevelsByEnv: Record<string, number> = {
"debug": 0,
"production": 3,
"test": 7,
};
export const logOptions = {
type: "pretty" as "json" | "pretty" | "hidden",
name: "Crawler",
hideLogPositionForProduction: true,
prettyLogTemplate: "{{name}} {{logLevelName}} ",
prettyLogStyles: {
logLevelName: {
SILLY: ["bold", "white"],
TRACE: ["bold", "whiteBright"],
DEBUG: ["bold", "green"],
INFO: ["bold", "blue"],
WARN: ["bold", "yellow"],
ERROR: ["bold", "red"],
FATAL: ["bold", "redBright"],
},
name: ["bold", "green"],
dateIsoStr: "white",
filePathWithLine: "white",
nameWithDelimiterPrefix: ["white", "bold"],
nameWithDelimiterSuffix: ["white", "bold"],
errorName: ["bold", "bgRedBright", "whiteBright"],
fileName: ["yellow"],
},
minLevel: 0,
};
logOptions.minLevel = process.env.NODE_ENV ? logLevelsByEnv[process.env.NODE_ENV] : 3;
export const getLogger = () => new Logger(logOptions);