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

@inctasoft/simple-log-ts

v4.4.1

Published

JSON log of objects, including Maps and Sets. Optional correlation_id

Downloads

51

Readme

SonarCloud results

simple-log-ts

npm install @inctasoft/simple-log-ts
  • debug, info, warn, error and crit methods.
  • JSON format, useful for log ingesting services
  • Error, Map Set objects are trnsformed into JSON and also printed
  • In case of circular references, output is still JSON, and the message property will contain a string with the value of util.inspect(data, ...inspectOptions). inspectOptions by default is {} but can be overwritten in Log's constructor
  • Optional correlation_id can be passed to constructor. Useful for correlating logs from different services. Pass printCorrelation: false in Log's constructor to skip it.

Usage

  • Empty config
import { Log } from "@inctasoft/simple-log-ts";

const log = new Log();
log.error("something hapened", new Error('some err msg'));

results in:

{"timestamp":"2023-10-11T21:50:47.405Z","level":"ERROR","message":"something hapened","correlation":"undefined","[Error]":{"stack":"Error: some err msg\n    at Object..(the err stack)","message":"some err msg"}}```
  • Log complex objects, provide correlation_id
import { Log } from "@inctasoft/simple-log-ts";
process.env.LOGLEVEL = 'DEBUG' // default level is WARN, un-silence debug method
const log = new Log({ correlation_id: 'some_guid' });
log.debug({
    a: 1, b: 'xyz', my_set: new Set(['foo', 'bar']), nested: {
        my_arr: [
            'elem1',
            new Map([['mapKey', {
                prop1: 1,
                prop2: new Date()
            }]])]
    }
});

results in:

{"timestamp":"2023-10-12T00:14:44.139Z","level":"DEBUG","message":{"a":1,"b":"xyz","my_set":["foo","bar"],"nested":{"my_arr":["elem1",{"mapKey":{"prop1":1,"prop2":"2023-10-12T00:14:44.139Z"}}]}},"correlation":"some_guid"}
  • If you are interested in which transformed objects were of Map or Set types, provide printMapSetTypes: true
  • Error objects are always printed as {"[Error]": {stack:"...", message: "..."}}
  • If you are not into using correlation_id, provide printCorrelation: false
import { Log } from "@inctasoft/simple-log-ts";

const log = new Log({ printMapSetTypes: true, printCorrelation: false});
log.error({
    a: 1, b: 'xyz', my_set: new Set(['foo', 'bar']), nested: {
        my_arr: [
            'elem1',
            new Map([['mapKey', {
                prop1: 1,
                prop2: new Date()
            }]])]
    }
}, new Error("oops something unexpected happened"));

results in:

{"timestamp":"2023-10-12T01:57:31.983Z","level":"ERROR","message":{"a":1,"b":"xyz","my_set":{"[Set]":["foo","bar"]},"nested":{"my_arr":["elem1",{"[Map]":{"mapKey":{"prop1":1,"prop2":"2023-10-12T01:57:31.983Z"}}}]}},"[Error]":{"stack":"Error: oops something unexpected happened\n    at Object..(the err stack)","message":"oops something unexpected happened"}}
  • Circular reference handlig
import { Log } from "../src/log";

const obj: any = {};
obj.a = [obj];
obj.b = {};
obj.b.inner = obj.b;
obj.b.obj = obj;

new Log().warn(obj)

results in:

{"timestamp":"2023-10-14T05:59:48.714Z","level":"WARN","message":"<ref *1> {\n  a: [ [Circular *1] ],\n  b: <ref *2> { inner: [Circular *2], obj: [Circular *1] }\n}","correlation":"undefined"}

Log levels

| process.env.LOGLEVEL | active methods | notes | |---|---|---| | DEBUG| debug,info,warn,error,crit| | | INFO | info,warn,error,crit|| | WARN | warn,error,crit| default, if no LOGLEVEL is present | | ERROR| error,crit| Both crit and error use console.error and accept optional second Error argument | | SILENT (or any other value)| crit | Lets you silence all logs, if not using crit method(as it is always active, no matter of LOGLEVEL value) |