Skip to content

Commit 11d4c58

Browse files
committed
Logger Components; (#3)
1 parent c8459d0 commit 11d4c58

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/config/logger.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import winston from 'winston';
2+
3+
const customLevels = {
4+
levels: {
5+
fatal: 0,
6+
error: 1,
7+
warning: 2,
8+
info: 3,
9+
http: 4,
10+
debug: 5,
11+
},
12+
colors: {
13+
fatal: 'magenta',
14+
error: 'red',
15+
warning: 'yellow',
16+
info: 'green',
17+
http: 'cyan',
18+
debug: 'blue',
19+
}
20+
};
21+
22+
winston.addColors(customLevels.colors);
23+
24+
const devLogger = winston.createLogger({
25+
levels: customLevels.levels,
26+
level: 'debug',
27+
transports: [
28+
new winston.transports.Console({
29+
format: winston.format.combine(
30+
winston.format.colorize({ all: true }),
31+
winston.format.simple()
32+
)
33+
})
34+
]
35+
});
36+
37+
const prodLogger = winston.createLogger({
38+
levels: customLevels.levels,
39+
level: 'info',
40+
transports: [
41+
new winston.transports.Console({
42+
format: winston.format.combine(
43+
winston.format.timestamp(),
44+
winston.format.json()
45+
)
46+
}),
47+
new winston.transports.File({
48+
filename: 'errors.log',
49+
level: 'error',
50+
format: winston.format.json()
51+
})
52+
]
53+
});
54+
55+
const logger = process.env.NODE_ENV === 'production' ? prodLogger : devLogger;
56+
57+
export default logger;

src/middlewares/loggerTest.middleware.js

Whitespace-only changes.

src/routes/logger.routes.js

Whitespace-only changes.

0 commit comments

Comments
 (0)