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

osnmarket-xpress-logger

v1.5.4

Published

osn market xpress logger

Downloads

72

Readme

Xpress Logger

Simple logger for logging applications with the ability to replace sensitive data in logs.

Installation

You can install the osnmarket-xpress-logger package via npm:

yarn add osnmarket-xpress-logger@latest

Or with npm

npm install osnmarket-xpress-logger@latest

Usage

import express from 'express';
import { writeLog } from 'osnmarket-xpress-logger';

const app = express();

app.use((req, res, next) => {
  // Log request details
  writeLog({
    crypt: ['client_id', 'client_secret'], // Specify sensitive keys to replace
    appName: 'your-app-name',
    req,
    res,
    manualLog: { // this overrides the default req, res logging keys retrieval to specify your own
      logFrom: req.ip,
      userIp: req?.socket?.remoteAddress,
      method: req.method,
      payload: JSON.stringify(req.body),
      headers: JSON.stringify(req.headers),
      logTarget: req.originalUrl,
      userAgent: req.headers['user-agent'],
      logStatus: res.statusCode,
      logStatusCode: res?.statusMessage?.toUpperCase(),
    },
    logLevel: 'INFO', // default log level
    action: 'INCOMING REQUEST'
    logConsole: false // it displays logs directly on console instead of writing it on file
    constantFileName: false // is at default false but can be set to true if you want the same file name all the time
  });
  next();
});

// Your Express app routes...

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

Which something like this

{ "log.level":"info", "@timestamp": "2024-03-05T09:59:41.230Z", "event.type": "AUDIT", "client.ip": "::1", "source.name": "::1", "user.name": "anonymousUser", "event.category": "INFO", "event.action": "INCOMING REQUEST", "http.request.method": "POST", "http.request.body.content": "{\"client_id\":\"***************\",\"client_secret\":\"***************\"}", "http.request.headers": "{\"content-type\":\"application/json\",\"user-agent\":\"PostmanRuntime/7.36.3\",\"accept\":\"*/*\",\"postman-token\":\"2596c2e1-23a1-4f67-af20-a8e406dde134\",\"host\":\"localhost:3000\",\"accept-encoding\":\"gzip, deflate, br\",\"connection\":\"keep-alive\",\"content-length\":\"98\"}", "url.path": "/auth/v1/token", "user_agent.original": "PostmanRuntime/7.36.3", "process.thread.id": 47575, "http.response.status": "OK", "http.response.status_code": 200 }

When in dev enviroment the logs format change to this

log.level:info|@timestamp:2024-03-05T10:01:24.432Z|event.type:AUDIT|client.ip:::1|source.name:::1|user.name:anonymousUser|event.category:INFO|event.action:INCOMING REQUEST|http.request.method:POST|http.request.body.content:"{\"client_id\":\"***************\",\"client_secret\":\"***************\"}"|http.request.headers:"{\"content-type\":\"application/json\",\"user-agent\":\"PostmanRuntime/7.36.3\",\"accept\":\"*/*\",\"postman-token\":\"c1e0ac21-61f0-4258-9142-34e8c677d24f\",\"host\":\"localhost:3000\",\"accept-encoding\":\"gzip, deflate, br\",\"connection\":\"keep-alive\",\"content-length\":\"98\"}"|url.path:/auth/v1/token|user_agent.original:PostmanRuntime/7.36.3|process.thread.id:48111|http.response.status:OK|http.response.status_code:200

Options

  • crypt: An array of sensitive keys to replace their values with asterisks in logs.
  • appName: Name of your application.
  • req: Entry req entity.
  • res: Outgoing res entity.
  • manualLog: Your own keys entity.
    • logFrom: IP address of the requester.
    • userIp: IP address of the user.
    • method: HTTP method.
    • payload: Request body payload.
    • headers: Request headers.
    • logTarget: Requested URL.
    • userAgent: User agent.
    • logStatus: HTTP response status code.
    • logStatusCode: HTTP response status message.
  • logLevel: Log level.
  • action: Action being logged.
  • logConsole: Displays logs directly on console instead of writing it on file.
  • constantFileName: Keeps the same filename all the time.