Package Exports
- @tinyhttp/logger
- @tinyhttp/logger/package.json
Readme
@tinyhttp/logger
Simple HTTP logger for tinyhttp.
Install
pnpm i @tinyhttp/loggerAPI
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'sMETHODStimestamp.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'
const app = new App()
app
.use(logger({ methods: ['GET', 'POST'], timestamp: { format: 'HH:mm:ss' }, output: { callback: console.log, color: false } }))
.get('/', (req, res) => void res.send('Hello world'))
.post('/', (req, res) => void res.send('Sent POST'))
.listen(3000)Alternatives
License
MIT © v1rtl