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

loggr.js

v1.2.5

Published

A simple logging utility.

Downloads

6

Readme

loggr.js

A simple logging utility.

Table of Contents

Usage
Installing
Example
loggr.js API
Roadmap
Credits
License

Usage

Used to log data to a write stream while also logging it to the console so that you can review now, and later.

Installing

npm i loggr.js

Example

const fs = require('fs');
const path = require('path');
const loggr = require('loggr.js');
const accessLog = fs.createWriteStream(path.join(__dirname, 'access.log'), { flags: 'a' });

... // Your code with an variable "data" that has some value.

// Default, will log to an event.log file.
loggr.log(data);

// Exprected result example:
// [mm/dd/yyyy @ hh:mm:ss:fff a] - value of data variable

// Normal, pass in a destination WriteStream.
loggr.log(accessLog, data); // Should output to access.log

// JSON
loggr.log(accessLog, data, 'json');

// Pretty printed JSON
loggr.log(accessLog, data, 'pretty');

// Have loggr.js create the log so you do not have to require fs and path
// separately.
loggr.create('trigger');

loggr.log('trigger', data); // Should output to /logs/trigger.log

// Have loggr.js recolor a log.
loggr.recolor.alert('\x1b[42m');

loggr.alert(data); // Should output a message with the severity notice using a
                   // green background to the console and the message to
                   // /logs/alert.log.

loggr.js API

Styling the console messages, potentially based on message severity, is possible using different logging helper functions.

| Function | Severity | Style (BG/FG or FG) | Description | | ----------------------------------------------- | ----------------- | ------------------- | ----------------------------------------------------------------------- | | loggr.emerg(data); | Emergency (0) | Red/White | Process is unstable. | | loggr.alert(data); | Alert (1) | Blue/White | Must take action immediately. | | loggr.crit(data); | Critical (2) | Yellow | Process is in critical condition. | | loggr.err(data); | Error (3) | Red | An error has occurred with process. | | loggr.warning(data); | Warning (4) | Yellow/Black | An unexpected condition occurred with process. | | loggr.notice(data); | Notice (5) | White | Other normal condition occurred with process. | | loggr.info(data); | Informational (6) | Cyan | An informational message. | | loggr.debug(data); | Debug (7) | Green/Black | Messages used for debugging. | | loggr.log(data); | Default (8) | Default | Just a normal message. | | loggr.create(data); | N/A | N/A | Creates 'data' log for future use. | | loggr.recolor.severity(data); | N/A | N/A | Changes the color for the 'severity' notice for a non-default log type. |

Note: With loggr.recolor.severity you need to change "severity" to the function name for the serverity type of log. For example, "Error" would be loggr.recolor.err().

Roadmap

Latest Feature

  • Automatically rotate logs everyday, i.e. logs/2018/04/11 (yyyy/mm/dd).

These are future capabilites that we intend to add:

In Progress

  • Allow for different timestamp formats.

Untouched

  • Timing
    • Speed up logging.
  • Website
    • Develop the landing page for the project.

Credits

loggr.js was inspired by the console.log(); functionality with the intention of adding a precise timestamp and preserving the logs for future reference. Rather than just logging to the console users should be able to log to any WriteStream they provide for enhancing their workflow such as an access.log, a transaction.log, a download.log, etc. Allowing users to easily log data to WriteStreams that make sense for their workflow. Another goal of the project is to help provide a mostly standardized approach to logging so that the logs can be easily consumed and parsed to find specific details. As with all things the final goal of the project is to help users save time so that they will "have more time" to allocate toward whatever they want.

License

MIT