JSPM

  • Created
  • Published
  • Downloads 68783
  • Score
    100M100P100Q158228F
  • License MIT

simple HTTP logger for tinyhttp

Package Exports

  • @tinyhttp/logger
  • @tinyhttp/logger/package.json

Readme

@tinyhttp/logger

npm (scoped) npm

Simple HTTP logger for tinyhttp.

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 to http's METHODS
  • 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 list
  • ip - 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