-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
55 lines (41 loc) · 1.05 KB
/
app.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require('dotenv').config()
const express = require('express')
const app = express()
const expressWinston = require('express-winston')
const { transports, format } = require('winston')
require('winston-mongodb')
const logger = require('./logger')
app.use(expressWinston.logger({
winstonInstance: logger,
statusLevels: true
}))
app.get('/', (req, res) => {
logger.info('This is an info log')
res.sendStatus(200)
})
app.get('/400', (req, res) => {
logger.warn('This is an warn log')
res.sendStatus(400)
})
app.get('/500', (req, res) => {
res.sendStatus(500)
})
app.get('/error', (req, res) => {
throw new Error('This is a custom error')
})
const myFormat = format.printf(({ level, meta, timestamp }) => {
return `${timestamp} ${level}: ${meta.message}`
})
app.use(expressWinston.errorLogger({
transports: [
new transports.File({
filename: 'logsInternalErrors.log'
})
],
format: format.combine(
format.json(),
format.timestamp(),
myFormat
)
}))
app.listen(4000)