I need to log error information to a morgan log, but I'm unsure how to do this, there don't seem to be any examples to look at.
import express from 'express'
import morgan from 'morgan'
const router = express.Router()
morgan.token('something', (req, res) => req.something)
const options = {
stream: rfs('api.log', {
interval: '2d',
size: '10M',
path: path.join(__dirname, '/../../../', 'logs')
})
}
router.use((req, res, next) => {
req.something = '123 abc'
next()
})
router.use(morgan(`:date[iso] :something`, options))
router.use('/', (req, res) => {
res.send('hello')
})
router.use('/', (err, req, res) => {
// we have an err object here!
res.send('error')
})
So the above will log 123 abc when res.send() is called.
How do I get info from the error object into the log..?
I need to log error information to a morgan log, but I'm unsure how to do this, there don't seem to be any examples to look at.
So the above will log
123 abcwhenres.send()is called.How do I get info from the error object into the log..?