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

written-in-stone

v0.0.3

Published

Logs events and other data to a database.

Downloads

1

Readme

Persistent write-only logging of requests, events, cycles, and loads to a database, it's basically written in stone.

TOC: Overview, Setup, Quick start, Advanced, Contribute

Overview

Supports two engines: MongoDB (default and recommended), and MySQL (alpha, limited functionality).

Setup

Install via npm:

npm install written-in-stone --save

Then, as listed in samples/log.js init the logger:

const WrittenInStone = require('written-in-stone');
const stonePlate = new WrittenInStone('mongodb', {
  path: 'mongodb://localhost/test'
});

Event types to log

Then you can log an event with certain fixed attributes per type, and a payload. Following event types exist:

Type | Fixed attributes | Usage :-------------------- | :--------------------------- | :-------------------------------------------------------- Activity | activity | Atomic events like email sent Status | key, value | Values that change over time like load of queue Request | requester, requested | Requests of resources like requested endpoint Cycle | type, identifier, step | Incremental monitoring like endqueued, then processed

Activity

An activity logs the firing of some atomic function.

The activity acts as a category, additional information can be logged in the payload, e.g. if an email is sent.

const activity = 'email-sent';

var payload = {
  to: '[email protected]',
  from: '[email protected]'
};

stonePlate.engraveActivity(activity, payload);

Status

A status reflects the current state of the application.

The key is the variable of which the snapshot should be made, the value represents the snapshot itself, i.e. its current status. With the payload, any additional information can be logged. This makes sense to e.g. log the current waiting jobs in a queue (redis).

const key = 'queue-waiting-jobs';
var value = getNumberOfJobsInQueue();

var payload = {
  env: process.env.NODE_ENV
};

stonePlate.engraveStatus(key, value, payload);

Request

A request logs, as the name suggests, a request of a resource.

The requester is the requesting entity, e.g. the users IP address in an Express.js service. requested represents the requested resource, e.g. a fixed name for a certain service. Within the payload additional information can be stored.

Note: So far, only the event type request is supported with MySQL as persistence.

const requested = 'name-of-this-resource';
var requester = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

var payload = {
  query: req.query
};

stoneLog.request(requester, requested, payload);

Cycle

A cycle event is one step in the processing of a certain object. E.g. if a document from the database is processed in several steps, each step can be enumerated.

The type described the kind of cycle. The identifier is unique for the cycle. The step represents the current progress. The combination of identifier and step is required to be unique.

// after enqueueing a job
const type = 'render-images';
var identifier = job.id;
var step = 0;

var payload = {
  imageSource: 'user-upload'
}

stonePlate.engraveCycle(type, identifier, step, payload);

Then, in a later step:

// in the queue worker after processing is done
const type = 'render-images';
var identifier = job.id;
var step = 1;

stonePlate.engraveCycle(type, identifier, step, null);

Advanced usage

Instances

To segregate your logs, you can also pass an instance (which is a Number) to every .engraveX() as optional first parameter.

stonePlate.engraveActivity(0, 'something-happened, null');

Callbacks

Every .engraveX() has a callback as optional last parameter.

stonePlate.engraveActivity('something-happened', null, function (err) {
  console.log(err);
});

Contribute

This is all dirty. ✋ If you want to help, please do.

Licensed as MIT, uses async, mongoose, node-mysql, underscore.