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

@inderes/logger

v1.5.4

Published

Shared package library to be used in our backend services, and possibly in the frontend also.

Downloads

1,422

Readme

@inderes/logger

Shared package library to be used in our backend services, and possibly in the frontend also.

Bases on Pino https://getpino.io

Quick start

Create a new logger instance with proper configuration:

const logger = new Logger({ context: 'MySweetShadow' });

logger.info('Fueled, these new shores burn');

logger.info('Dark past lies cold', { lyrics: 'Shadow, my sweet shadow' });

const error = new Error('To you, I look no more...');
logger.error('The end', error);
[
  {
    "level": "info",
    "time": "2023-02-02T07:16:16.209Z",
    "context": "MySweetShadow",
    "message": "Fueled, these new shores burn"
  },
  {
    "level": "info",
    "time": "2023-02-02T07:16:16.209Z",
    "context": "MySweetShadow",
    "data": { "lyrics": "Shadow, my sweet shadow" },
    "message": "Dark past lies cold"
  },
  {
    "level": "error",
    "time": "2023-02-02T07:16:16.209Z",
    "context": "MySweetShadow",
    "data": {
      "error": {
        "type": "Error",
        "message": "To you, I look no more...",
        "stack": "Error: To you, I look no more...\n    at Object.<anonymous> (file:///Users/pitkane/code/inderes/videosync-monorepo/apps/videosync-api/src/index.ts:87:19)"
      }
    },
    "message": "The end"
  }
]

Logger options

name

Assign name for the logger. Name is printed on every log line. This helps to identify the source of the logging. In example API might have integration modules or classes, which can identify themselves by assigning name for the class.

const logger = new Logger({ name: 'HulabaloozaIntegration' });

prettyPrint

Default: false. Normally the output is JSON. Setting this true will change to output into string, and removes some other normally outputted information. Useful for local development.

requestId

const logger = new Logger({ requestId: uuid() });

Useful if you need to track the logs. Eg. in fastify/express server, start of the request you create a logger, set the tracindId, and assign the logger to request context. All of the processing and log outputs of the single request (request context) will include the same requestId. So with one id you will get the whole trace of the request from start to finish.

Fastify does this automatically. The example below is one GET request to /api/v1/examples, and it has the same requestId the whole way of the request.

{"level":"info","time":"2022-07-27T08:16:45.654Z","name":"MySweetShadow","requestId":"ifK-HtSbgf9ZjQkMnA7W7","requestId":{"method":"GET","url":"/api/v1/examples","hostname":"localhost:3001","remoteAddress":"127.0.0.1","remotePort":55547},"message":"incoming request"}
{"level":"info","time":"2022-07-27T08:16:45.718Z","name":"MySweetShadow","requestId":"ifK-HtSbgf9ZjQkMnA7W7","moro":"jorma","message":"just testing logging"}
{"level":"info","time":"2022-07-27T08:16:45.718Z","name":"MySweetShadow","requestId":"ifK-HtSbgf9ZjQkMnA7W7","res":{"statusCode":200},"responseTime":64.16495898365974,"message":"request completed"}

defaultData

Object which is spread into every log object/line.

const logger = new Logger({ defaultData: { some: 'data' } });
logger.info('Hello world');
{
  "level": "info",
  "time": "2022-07-27T08:19:49.428Z",
  "payload": {
    "some": "data"
  },
  "message": "Hello world"
}

redactFields

Removes wanted or sensitive fields from the output log object. For example we don't want to log out passwords, which are automatically redacted.

const logger = new Logger({ redactFields: ['secretString'] });
logger.info('secrets', { username: 'super', secretString: 'secret' });
{
  "level": "info",
  "time": "2022-07-27T08:22:11.868Z",
  "payload": {
    "username": "super",
    "secretString": "[Redacted]"
  }
}

Publishing to npm

When doing changes to the package, you need to publish the package to npm. This is done with changesets. Changesets are used to create a changelog, and to publish the package to npm.

Create a changeset

npx changeset

If will ask you a series of questions, and then it will create a changeset file. This file is used to create the changelog, and to publish the package to npm.

Publish the package

After the changeset file is created, you need to commit it to git. Then you can publish the package to npm.

To bump the version:

npx changeset version

This will bump the version.

And finally publish the package to npm:

npx changeset publish