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

logsplit

v0.1.0

Published

Keep your logs focused by splitting up large log objects

Downloads

5

Readme

Logsplit

Build Status

Logsplit

Takes large objects and splits them into small chunks for separate logging, with easily followable references.

Example

const createLogSplitter = require("logsplit");
const logsplit = createLogSplitter(console.log);

const message = {
  author: "Tommy Brunn",
  packages: [
    {
      name: "express-physical",
      url: "https://github.com/Nevon/express-physical"
      // additional fields making this object very large
    }
  ]
};

console.log(logsplit(message));

// `logsplit` returns this object, which contains a reference to the extracted
// large object:
// {
//     author: 'Tommy Brunn',
//     packages: 'Log-Reference-e44ab504-2202-4879-87ba-66c30ab7cf4f'
// }

// Additionally, the extracted object gets logged separately:
// {
//     $reference: 'Log-Reference-e44ab504-2202-4879-87ba-66c30ab7cf4f',
//     $item: [
//         {
//             name: 'express-physical',
//             url: 'https://github.com/Nevon/express-physical'
//             // additional fields making this object very large
//         }
//     ]
// }

Motivation

For debugging purposes, I find it very useful to log all data that was used in my system. For example, request and response bodies in a web service. However, due to limitations in logging tools, it's not always desirable to log the entire payload in a single message.

As it is impossible to know up front what parts of your data will be important until after you need it, Logsplit helps you to log a high level message while separately logging the details for when you need them.

Installation

npm install logsplit --save
# yarn add logsplit

Usage

createLogSplitter takes a logging function and an optional options object, and returns a function (logsplit).

const createLogSplitter = require("logsplit");

const logFunction = message =>
  console.info(`Extracted log item ${message.$reference}: %j`, message);
const options = {
  // maximum approximate object size for extraction
  maxByteSize: 1500,
  // generate the reference string to replace the large object with
  createReference: item => `Log-Reference-${uuid()}`
};

const logsplit = createLogSplitter(logFunction, options);

console.log(logsplit(message));

Express Middleware

Logsplit can be used as an Express middleware for doing request/response body logging. If you are interested in this use case, open an issue.

License

See LICENSE for more details.

Attributions