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

sharplogger

v1.0.6

Published

SharpLogger is a simple, easy-to-use, lightweight logging library.

Downloads

59

Readme

SharpLogger

SharpLogger is a simple, easy-to-use, lightweight logging library.

This package provides color support (ANSI colors), pre-set logging functions (error, warn, info, and log), and an optional file logging functionality that automatically appends to log files whenever log functions are called.

Features

  • ANSI colors: Easily apply ANSI colors to your logs (automatically applied to prefixes)
  • Pre-set logging functions: Use error, warn, info, and log to standardize your logging output
  • Optional log file: Automatically append to a log file when a logging function is called, creates during initalization
  • Customizable prefix colors: Change the color of the log prefixes using the setPrefixColor method

Installation

npm install simplelogger

Example usage

const LogFile = require('simplelogger')

// Create a new file named /log and append a date string.
// Would come out like so: ./log-24-08-09_14-30-45.log (YY-MM-DD_HH-MM-SS)

const logFile = new LogFile('./log', 'log', true);
logFile.initialize(); // only called when filePath is not null

// Set prefix color of informational logs to bright green

logFile.setPrefixColor('info', logFile.colors.fg.brightGreen);

// Test out log functionalities

logFile.log('hello'); // "hello"
logFile.error('world'); // "[ERROR] world" with [ERROR] is bright red
logFile.warn('!!!'); // "[WARN] !!!" with [WARN] is bright yellow
logFile.info(':D'); // "[INFO] :D" with [INFO] is bright blue

Log file output w/ example

Log data @ August 9, 2024 at 02:28:12 AM
-----
[LOG : August 9, 2024 at 02:28:12 AM] hello
[ERROR : August 9, 2024 at 02:28:12 AM] world
[WARN : August 9, 2024 at 02:28:12 AM] !!!
[INFO : August 9, 2024 at 02:28:12 AM] :D

Documentation

LogFile class

Constructor: new LogFile(filePath = null, extension = null, newLogFile = null);

  • All of these are optional, if you do not want to use the log file functionality, leave the LogFile constructor empty.
  • filePath (String): The directory path with the base file name to create the log file in, eg. "./log"
  • extension (String): The extension of the file, without the preceding dot, eg. "log"
  • newLogFile (Boolean): Whether to create a new log file with an appended date string

Methods

  • initialize(): Create the log file if filePath and newLogFile are not null, appending an initial entry with the current date & time
  • setPrefixColor(functionName, color): Set the color for the specific log prefix, functionName should match any below functions and color can technically be anything, but you should use LogFile.colors for ANSI colors. You can also use multiple colors, eg. setPrefixColor('error', logFile.colors.fg.brightRed + logFile.colors.fg.bold) (formatting is not reset)
  • All log functions will append the message to the log file with a prefix such as [ERROR] or [LOG]
  • endProcess can end the process on 3 codes:
    • 0: non-error
    • 1: error
    • 2: warning
  • log(string, endProcess = false): Log a standard message to the console
  • error(string, endProcess = false): Log an error to the console with a red-prefixed [ERROR]
  • warn(string, endProcess = false): Log a warning message with a yellow-prefixed [WARN]
  • info(string, endProcess = false): Log an informational message with a blue-prefixed [INFO]

ANSI Colors

The LogFile class provides all ANSI Colors with an object in the constructor, LogFile.colors.fg or LogFile.colors.bg with additional formatting options.

Colors are applied automatically to the following functions:

  • error: Bright red
  • warn: Bright yellow
  • info: Bright blue
  • log: No color