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

@usvc/middleware-request-logger

v0.0.1

Published

Morgan based logger for usage in a microservices architecture.

Downloads

6

Readme

@usvc/middleware-request-logger

Morgan based logger for usage in a microservices architecture.

The output logs will include the following properties:

| Key | Description | | --- | --- | | level | This will always be "access" | | method | The method of the HTTP request | | url | The requested URL | | status | The status code of the request | | contentLength | The content length | | responseTimeMs | The response time in milliseconds | | httpVersion | The HTTP version | | referrer | The referrer (if applicable) | | remoteHostname | The remote hostname (if found) | | remoteAddress | The remote IP address | | serverHostname | The server hostname as specified in the createMiddleware method | | time | ISO timestamp of the request | | userAgent | User agent of the request |

Scope

  • [x] Creates an Express compatible request logger middleware
  • [x] Allow for token extension
  • [x] Allow for specification of a custom logger and log level

Installation

npm i @usvc/middleware-request-logger;
# OR
yarn add @usvc/middleware-request-logger;

Usage

// es5:
const {createMiddleware} = require('@usvc/middleware-request-logger');
// es6:
import {createMiddleware} from '@usvc/middleware-request-logger';

Basic

const express = require('express');
// require as ^
const app = express();
app.use(createMiddleware());
app.listen(...);

Full Configuration

const express = require('express');
// require as ^
const app = express();
app.use(createMiddleware({

}));
app.listen(...);

API Documentaiton

createMiddleware(:options)

Creates the request logger middleware and returns an Express compatible middleware that you can app.use(...).

Parameters

| Key | Defaults To | Description | | --- | --- | --- | | additionalTokens | [] | Additional tokenizers. Each item in the array should be of the form {id: 'some-property', fn: (req, res) => (/*your code here*/)}. | | hostname | os.hostname() || process.env.HOSTNAME || 'unknown' | The host name to use for the server in the logs | | logger | console | The logger to be used. | | level | info | The level of the logger to be used. |

getZipkinTokenizers()

This function returns an array of tokenizers that you can use in the additionalTokenizers option in createMiddleware().

These tokenizers depend on there being a .context property in the Request object passed by Express. This is automatically done if you are using the Zipkin tracer as defined in @usvc/tracer.

Using the returned tokenizers will result in the following additional keys in the log:

| Key | Description | | --- | --- | | traceId | The trace ID | | spanId | The span ID | | parentSpanId | The parent span ID | | sampled | Indication whether the request was sampled or not |

Examples

Usage with ES5

Goto: ./example/es5

Or run: npm run eg:es5

Usage with ES6

Goto: ./example/es6

Or run: npm run eg:es6

Usage with Winston

Goto: ./example/winston

Or run: npm run eg:winston

Development

See the development instructions on the main repository's README.

License

This package is licensed under the MIT license.

View the license at LICENSE.

Changelog

WIP

Contributors

| Name | Email | Website | About Me | | --- | --- | --- | --- | | Joseph | dev-at-joeir-dot-net | https://github.com/zephinzer | N/A |

Cheers