New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@tinyhttp/logger

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/logger

Minimal and flexible HTTP logger.

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
54K
-27.05%
Maintainers
1
Weekly downloads
 
Created
Source

@tinyhttp/logger

npm GitHub Workflow Status Coverage

Minimal and flexible HTTP logger

Install

pnpm i @tinyhttp/logger

API

import { logger } from '@tinyhttp/logger'

logger(options)

Returns the middleware for logging HTTP requests.

Options

  • methods: a list of HTTP methods to log. Defaults to http's METHODS.
  • timestamp.format: timestamp format. It is consumed by the dayjs library. If a string is specified, it is used as a format; otherwise just enabled.
  • output.callback: a function that receives the log generated by the logger.
  • output.color: a property that determines whether the logger will generate a message with color. Useful for logging into the console; disable if logging into a file or other colorless environments.
  • emoji: enable emojis for HTTP status codes. See http-status-emojis for a full list.
  • ip: 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)

To Log a level, use the enum LogLevel

import { App } from '@tinyhttp/app'
import { logger, LogLevel } from '@tinyhttp/logger'

new App()
  .use(
    logger({
      methods: ['GET', 'POST'],
      timestamp: { format: 'HH:mm:ss' },
      output: { callback: console.log, color: false, level: LogLevel.warn }
    })
  )
  .get('/', (req, res) => res.send('Hello world'))
  .listen(3000)

This also includes a simple file logger. To stream to a file, simply supply the filename in the options. Supported file names innclude ./file.log or ./log/tiny.log

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, filename: './log/tiny.log' }
    })
  )
  .get('/', (req, res) => res.send('Hello world'))
  .listen(3000)

Alternatives

  • Pino HTTP - high-speed HTTP logger for Node.js
  • chrona - Simple HTTP request logger middleware for express.js inspired from koa-logger, written in typescript.

Keywords

tinyhttp

FAQs

Package last updated on 03 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts