https://github.com/byu-oit/express-logger
Default express logging middleware to match BYU Application Development logging standards
https://github.com/byu-oit/express-logger
Last synced: 3 months ago
JSON representation
Default express logging middleware to match BYU Application Development logging standards
- Host: GitHub
- URL: https://github.com/byu-oit/express-logger
- Owner: byu-oit
- License: apache-2.0
- Created: 2021-04-05T18:59:00.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2026-03-09T14:17:36.000Z (5 months ago)
- Last Synced: 2026-03-09T18:55:48.625Z (5 months ago)
- Language: TypeScript
- Size: 871 KB
- Stars: 0
- Watchers: 18
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Express Logger
[]()
[](https://codecov.io/gh/byu-oit/express-logger)
Default express logging middleware to match [CES Application Development logging standards](https://github.com/byu-oit/ces-dev-best-practices/blob/main/adr/application/0006-basic-logging-standards.md).
## Install
```
npm i @byu-oit/express-logger
```
## Usage
```typescript
import { LoggerMiddleware } from '@byu-oit/express-logger'
const app = Express()
app.use(LoggerMiddleware())
// ... add routes to express app
```
CommonJS Equivalent
```javascript
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:
```json
{
"level":"info",
"time":1617128842026,
"req":{
"id":"Root=1-abcde",
"method":"GET",
"url":"/persons/123456789",
"remoteAddress":"::1"
},"res":{
"statusCode":200
},
"responseTime":168,
"message":"request completed"
}
```
### Embedded Logger
This middleware will attach the Pino logger to the request object, so if needed you can access the logger like:
```typescript
app.use(LoggerMiddleware())
app.get('/foo', (req, res) => {
req.log.debug('Inside the /foo route')
res.send('hello world')
})
```
## Options
Any [`pinoHttp` options](https://github.com/pinojs/pino-http#pinohttpopts-stream) can be overridden, but for compliance with our logging standards, we recommend sticking to the defaults provided in this package.
### Example of overwriting a default
```typescript
app.use(LoggerMiddleware({
level: 'trace'
}))
```
**Note:** If you provide your own `logger` please use the [@byu-oit/logger](https://www.npmjs.com/package/@byu-oit/logger) to ensure you follow the logging standards.
```typescript
import DefaultLogger from '@byu-oit/logger'
const myLogger = DefaultLogger()
app.use(LoggerMiddleware({
logger: myLogger
}))
```