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

logchain

v1.0.1

Published

Logging secured by blockchain ๐Ÿ“œโ›“๏ธ

Downloads

565

Readme

Logchain

Pipeline status Coverage report

Dependencies License Package

Logging secured by blockchain ๐Ÿ“œโ›“๏ธ

Logs get chained

The current log line contains the signature of the previous line with your secret.

  • detect lines deleted / lost
  • detect logs tampering

Philosophy

The package is intended to be a lightweight util for generating incorruptible logs.

For this pupose we rely as much as possible on standard packages: few dependencies, high quality.

The formatters are easily extensible by simply deriving from Basic.

Usage

Install

npm install logchain

Choose your log type

Many types of logs are supported out-of-the-box:

  • Basic raw text, relying on the standard formatter
  • Json structured log lines with static & dynamic fields

You can write a custom formatter in 20-ish lines.

Init once in main

import { LogChainer } from "logchain"

// Initialize a default chainer.
const chainer = new LogChainer()

// Register the formatter to the logger.
chainer.initLogging()

Have a look at the comprehensive guide of constructor parameters.

Use everywhere with standard logging

Standard console methods are overriden once per program.

console.log("the basic log")
console.debug("the debug")
console.info("the info")
console.warn("the warning")
console.error("the error")

Check your logs integrity afterwards

import { LogChainer } from "logchain"

const aLogChain = [
	"2020-06-03T22:00:17.566Z LOG basicChaining.test.js:28 the basic log |43d85615af018369",
	"2020-06-03T22:00:17.567Z DEBU basicChaining.test.js:29 the debug |2cdcac6830d7d094",
	"2020-06-03T22:00:17.568Z INFO basicChaining.test.js:30 the info |72f847d26583d23d",
	"2020-06-03T22:00:17.568Z WARN basicChaining.test.js:31 the warning |095e94f80e612f95",
	"2020-06-03T22:00:17.569Z ERRO basicChaining.test.js:32 the error |618c0f4dd07a3942"
]

const chainer = new LogChainer({secret: "9b06b72c717e8d9f8c1393e11f2635c5"})
const result = chainer.verify(aLogChain)

if(result.value)
{
	console.log("All right")
}
else
{
	console.log("Last good line", result.prevLine)
	console.log("First bad line", result.line)
}

Constructor parameters

They are passed as an object.

import { LogChainer } from "logchain"

const chainer = new LogChainer({verbosity: 3, secret: "mySignatureKey"})

| Param Type | Default value | Description | | ----- | ------------- | ----------- | | formatterCls class | formatters.Basic | Type of logging to perform, raw text, json, custom | | template string | see below | Placeholder string used by raw-text loggers | | secret string | random of 128 chars | Signature key to compute the line signature | | seed string | random of 64 chars | Random string to sign into the first log line | | stream stream | stdout | Where the logs are sent, file/console/custom stream | | verbosity int | 0 | Number [0..5] mapped to a logging.level |

Logchain record logging fields

We make the record with some handy fields:

| Name | Description | | ---- | ----------- | | fileLine | Widespread filename:lineno | | levelLetter | First letter of the logging level names | | msg | The text being logged | | process | The PID as int | | processName | The process name | | signature | The digital signature of the previous line. Include it in all your lines to benefit from the chaining | | timestamp | ISO8601 precise to the milliseconds |


Contributing

Install

The code is hosted on Gitlab ๐ŸฆŠ

Simply clone and submit pull requests.

Testing

The unit tests are located in test and discovered by jest.

# Run all
npm test

Releasing

The process is triggered by a tag added to a commit. The tag must match the pattern release_<VERSION> and VERSION has to comply to semver.

A CI/CD job handles the new tag event and publishes the package to npmjs.

Thanks

Freepik from www.flaticon.com for the icon.

Shu for the npm module name.