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

@neylion/log

v1.0.2

Published

Logger package

Downloads

2

Readme

ney-log

A logger package (built with backend APIs in mind) designed to handle logs and put together relevant metadata. The package itself does not actually log anywhere, but requires you to add delegate methods that it can call upon when a new log has been received.

Adding to project

  • Install: npm install @neylion/log
  • Initialize (before any calls to log):
    • Importing: const { init } = require("@neylion/log");
    • Initializing: init(logDelegates);
  • Log:
    • Importing: const { log } = require("@neylion/log");
    • Logging: log.error("Message", errorObject, { metadata1: "Useful context", metadata2: "useful context" })

Log Levels

Level | Method | General guidelines when to use ------|----------------|-------------------------------- fatal | log.fatal(...) | Something critical went wrong that is likely to warrent immediate attention. error | log.error(...) | Unexpected error was encountered that is likely something you should look into fixing. warn | log.warn(...) | Something unexpected/suboptimal happened that is likely something you should look into but does not require immediate attention. info | log.info(...) | Something happened that is likely to be good to know. debug | log.debug(...) | Something happend that is likely not of much interest but might be useful when debugging the application more thoroughly.

Log Delegates

When initializing the logger, you are required to provide an array of methods (delegates) that will do the actual logging. These delegates will be called, when a new log has been processed, with all the data relevant to that specific log.

Here are two small examples on how you can set up your own log delegate method:

Simply logging the whole logData object as json

function consoleLogger(logData){
  console.log(logData);
}

Logging message after customizing it

function consoleLogger(logData){
  // Customize message the way you want it
  let message = `${logData.direction} ${logData.message} | CorrId: ${logData.correlationId}`;
  // Add direction if it exists
  message = logData.direction ? `${logData.direction} ${message}` : message;
  console.log(`${logData.level} ${message}`);
}

If you use typescript you can import the interface "ILogData" to be able to more easily handle the logData parameter. If using plain javascript, see the following section for a list of what the object contains

Log Data

The packages processes a lot of useful information and makes them available to the log delegates through the parameter sent to them. Here are all the properties available on the object:

Property | Type | Explanation ---------|------|------------ level | string | Log level (see section about log levels) direction | string or undefined | undefined when using the regular "log" object but is automatically set if you use the "logInbound" or "logOutbound" objects instead. Useful for being able to tell which logs that relate to the pipe in to the internal code, and which relate to the pipe between internal code and external calls. message | string | The message passed to the log method. logDetails | object | Object passed to log method containing useful context to the specific log entry null (guarded to make sure it always returns empty object even if it is omitted in log). error | object or undefined | Error timestamp | string | Timestamp of log in format: hh:mm:ss.sss requestContext | object | If you use the package @neylion/request-context, useful request context is available on this object. See the following table for more details on this object.

requestContext properties

Property | Type | Explanation ---------|------|------------ msSinceStart | number or undefined | Milliseconds since request start. startTimestamp | string or undefined | Request start timestamp in format: hh:mm:ss.sss correlationId | string or undefined | See explanation callingClient | string or undefined | See explanation method | string or undefined | See explanation path | string or undefined | See explanation