Default express logging middleware to match CES Application Development logging standards.
npm i @byu-oit/express-logger
import { LoggerMiddleware } from '@byu-oit/express-logger'
const app = Express()
app.use(LoggerMiddleware())
// ... add routes to express app
CommonJS Equivalent
const { LoggerMiddleware } = require('@byu-oit/express-logger')
const app = Express()
app.use(LoggerMiddleware())
Any requests to the express server will then write logs that look like:
{
"level":"info",
"time":1617128842026,
"req":{
"id":"Root=1-abcde",
"method":"GET",
"url":"/persons/123456789",
"remoteAddress":"::1"
},"res":{
"statusCode":200
},
"responseTime":168,
"message":"request completed"
}
This middleware will attach the Pino logger to the request object, so if needed you can access the logger like:
app.use(LoggerMiddleware())
app.get('/foo', (req, res) => {
req.log.debug('Inside the /foo route')
res.send('hello world')
})
Any pinoHttp
options can be overridden, but for compliance with our logging standards, we recommend sticking to the defaults provided in this package.
app.use(LoggerMiddleware({
level: 'trace'
}))
Note: If you provide your own logger
please use the @byu-oit/logger to ensure you follow the logging standards.
import DefaultLogger from '@byu-oit/logger'
const myLogger = DefaultLogger()
app.use(LoggerMiddleware({
logger: myLogger
}))