@misterzik/espressojs 3.2.6 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ /*
2
+ * _| _| _| _| _|_|_|
3
+ * _| _| _|_| _|_| _| _|
4
+ * _| _| _| _| _| _| _|
5
+ * _| _| _| _| _| _|
6
+ * _| _| _| _|_|_|
7
+ * EspressoJS - Logger Utility
8
+ */
9
+
10
+ const winston = require("winston");
11
+ const path = require("path");
12
+
13
+ const logLevels = {
14
+ error: 0,
15
+ warn: 1,
16
+ info: 2,
17
+ http: 3,
18
+ debug: 4,
19
+ };
20
+
21
+ const logColors = {
22
+ error: "red",
23
+ warn: "yellow",
24
+ info: "green",
25
+ http: "magenta",
26
+ debug: "blue",
27
+ };
28
+
29
+ winston.addColors(logColors);
30
+
31
+ const logFormat = winston.format.combine(
32
+ winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
33
+ winston.format.colorize({ all: true }),
34
+ winston.format.printf(
35
+ (info) => `${info.timestamp} [${info.level}]: ${info.message}`
36
+ )
37
+ );
38
+
39
+ const fileFormat = winston.format.combine(
40
+ winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
41
+ winston.format.json()
42
+ );
43
+
44
+ const transports = [
45
+ new winston.transports.Console({
46
+ format: logFormat,
47
+ }),
48
+ new winston.transports.File({
49
+ filename: path.join(process.cwd(), "logs", "error.log"),
50
+ level: "error",
51
+ format: fileFormat,
52
+ }),
53
+ new winston.transports.File({
54
+ filename: path.join(process.cwd(), "logs", "combined.log"),
55
+ format: fileFormat,
56
+ }),
57
+ ];
58
+
59
+ const logger = winston.createLogger({
60
+ level: process.env.NODE_ENV === "production" ? "info" : "debug",
61
+ levels: logLevels,
62
+ transports,
63
+ exceptionHandlers: [
64
+ new winston.transports.File({
65
+ filename: path.join(process.cwd(), "logs", "exceptions.log"),
66
+ }),
67
+ ],
68
+ rejectionHandlers: [
69
+ new winston.transports.File({
70
+ filename: path.join(process.cwd(), "logs", "rejections.log"),
71
+ }),
72
+ ],
73
+ });
74
+
75
+ module.exports = logger;