GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tinyhttp/logger: 🪵 Minimal and flexible HTTP logger

BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
.vscode
.vscode
 
 
src
src
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
biome.json
biome.json
 
 
bun.lock
bun.lock
 
 
commitlint.config.mjs
commitlint.config.mjs
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

@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.

About

🪵 Minimal and flexible HTTP logger

Topics

esmhttpjavascriptloggerloggingnodejstinyhttp

Resources

Readme
MIT license
Activity
Custom properties

Stars

10 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

Generated from tinyhttp/repo-template
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.