Minimal and flexible HTTP logger
Install
pnpm i @tinyhttp/logger
API
import { logger } from '@tinyhttp/logger'
logger(options)
Returns the middleware to log HTTP requests.
Options
methods
- a list of HTTP methods to log. Defaults tohttp
'sMETHODS
timestamp.format
- timestamp format. Gets consumed by dayjs library. If a string specified, used as a format, otherwise just enables it.output.callback
- function that recieves the log generated by the logger.output.color
- property that determines if the logger will generate a message with color. usefull for logging into the console, disable it if logging into file / http / etc...emoji
- enable emojis for HTTP status code. See http-status-emojis for a full listip
- log IP address
Example
import { App } from '@tinyhttp/app'
import { logger } from '@tinyhttp/logger'
new App()
.use(
logger({
methods: ['GET', 'POST'],
timestamp: { format: 'HH:mm:ss' },
output: { callback: console.log, color: false }
})
)
.get('/', (req, res) => res.send('Hello world'))
.post('/', (req, res) => res.send('Sent POST'))
.listen(3000)
Alternatives
- Pino - super fast, all natural json logger.
- Zoya - Truly highly composable logging utility.
- Morgan - HTTP request logger middleware for node.js
- concurrency-logger - Log HTTP requests/responses separately, visualize their concurrency and report logs/errors in context of a request
- Volleyball - Tiny HTTP logger for Express showing asynchronous requests and responses