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

logawesome

v0.0.1

Published

Rudimentary logging implementation

Downloads

3

Readme

logawesome

npm node

Travis branch Coveralls github

license GitHub tag GitHub issues GitHub last commit GitHub top language GitHub code size in bytes

logawesome is a rudimentary logging implementation and still WIP.

Why another Logger?

Some loggers are doing too much or specific work.

logawesome is:

  • not having one global logging configuration, but multiple if desired
  • syntactic sugar easy to use logger
  • minimal functional interface for dispatching to so called appenders
  • unrestricted in terms of log levels or log messages

Example:

logger `INFO` `connecting to ${{url: 'https://...'}}`;

Usage

npm install logawesome

We use npm package debug. To make me verbose use DEBUG=logawesome.

Creating a log system

import {LogSystem} from 'logawesome';

const logSystem = new LogSystem();
logSystem.addAppender(appender1);
logSystem.addAppender(appender2);
logSystem.addAppender(appender2);

Console Appender

Using moment as date formatter.

import {createConsoleAppender} from 'logawesome';

const appender = createConsoleAppender({
    timestampToString: timestamp => moment(timestamp).format('HH:mm:ss.SSS')
});

logSystem.addAppender(appender);

File Stream Appender

import {createFileStreamAppender} from 'logawesome';

const appender = createFileStreamAppender({
    timestampToString: timestamp => moment(timestamp).format('YYYY-MM-DD HH:mm:ss.SSS'),
    timestampToFilepath: timestamp => path.join('logs', moment(timestamp).format(`[applogs_]YYYY-MM-DD[.${workerName}.json.log]`))
});

logSystem.addAppender(appender);

How it works

A logger can be invoked like this:

logger `INFO` `connecting to ${{url: 'https://...'}}`;

The LogSystem invokes all appenders deferred (process.nextTick). Log message is enhanced with:

  • a timestamp (whatever you passed to new LogSystem(timestampFn), or Date.now() per default)
  • an existing immutable context, updated by logger.set(...) or branched by logger.branch()

An Appender simply is a function, taking 6 arguments:

  • timestamp: number, produced by LogSystem
  • context: object, immutable context of the log entry
  • levelTpls: array of strings, first parameter of a template string
  • levelPlaceholders: array, second parameter of a template string
  • msgTpls: array of strings, first parameter of a template string
  • msgPlaceholders: array, second parameter of a template string

It's the appender's responsibility to aggregate information. At current logawesome is shipping with 2 appenders.

  • file stream appender: writing logs to time dependant rotating files
  • console appender: writing logs to console

Both using composition: Appender = Transformer -> Formatter -> Writer

  • Transformer: context aggregation according to template string
  • Formatter: produces log message
  • Writer: writes it to the target

Plans

  • micro packages, move appender logic to external packages
  • ELK stack support
  • syslog support