npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@well-known-components/http-requests-logger-component

v2.1.0

Published

Logs each http request.

Downloads

488

Readme

HTTP requests logger component

This component logs each incoming request and response. When a request is initiated in the service, the component will log it and when it gets resolved, it will log the response.

Usage

Set up

The HTTP requests logger component is pretty straightforward to use, just import the component and initialize it with the log and the server components before any router:

import { instrumentHttpServerWithRequestLogger } from '@well-known-components/http-requests-logger'
import { createConfigComponent } from '@well-known-components/env-config-provider'
import { createServerComponent } from '@well-known-components/http-server'
import { createLogComponent } from '@well-known-components/logger'

const config = createConfigComponent(process.env, defaultValues)
const server = await createServerComponent<GlobalContext>({ config, logs }, { cors, compression: {} })
const logs = await createLogComponent()
instrumentHttpServerWithRequestLogger({ server, logger: logs })

Although only the server and the log components are required for this component to work, it is recommended to be used alongside the tracer and http-tracer components to make it possible to track and match each of the input and output requests.

import { instrumentHttpServerWithRequestLogger } from '@well-known-components/http-requests-logger'
import { createConfigComponent } from '@well-known-components/env-config-provider'
import { createServerComponent } from '@well-known-components/http-server'
import { createLogComponent } from '@well-known-components/logger'
import { createHttpTracerComponent } from '@well-known-components/http-tracer-component'
import { createTracerComponent } from '@well-known-components/tracer-component'

const tracer = createTracerComponent()
const config = createConfigComponent(process.env, defaultValues)
const server = await createServerComponent<GlobalContext>({ config, logs }, { cors, compression: {} })
const logs = await createLogComponent()
createHttpTracerComponent({ server, tracer })
instrumentHttpServerWithRequestLogger({ server, logger: logs })

This set up, alongside the default configurations, will produce the following logs:

[0-ae513d7468d8df8d9418e2bbee9d3c5b-0000000000000000-0] 2023-03-05T16:47:20.334Z [INFO] (http-in): [GET: /v1/items?contractAddress=0xa8dcccf8beeefdf07157dceeb4351afe8c4edf1a&itemId=0]
[0-ae513d7468d8df8d9418e2bbee9d3c5b-0000000000000000-0] 2023-03-05T16:47:21.431Z [INFO] (http-out): [GET: /v1/items?contractAddress=0xa8dcccf8beeefdf07157dceeb4351afe8c4edf1a&itemId=0][200]

Notice: Although the example has the input and the output logs one next to the other, the service might resolve other requests at the same time, interpolating the request and response logs.

Configuration

The component allows the following configurations via a config parameter:

  • verbosity: The verbosity on which the logs will be outputted. Defaults to INFO.
  • inputLog: A customizable function that defines how the input log will be outputted. Defaults to outputting [$method: $path$search$hash].
  • outputLog: A customizable function that defines how the output log will be outputted. Defaults to outputting [$method: $path$search$hash][$status].
  • skipInput: A flag to disable the outputting of the input log.
  • skipOutput: A flag to disable the outputting of the output log.
  • skip: A flexible parameter to define how to skip the logging of endpoints. Defaults to skipping the /health/live endpoint.