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

@norviah/logger

v7.0.0

Published

A simple logging system.

Downloads

4

Readme

@norviah/logger

A simple logging system for node.js/TypeScript that uses Chalk. The purpose of Logger is to be a purposeful logging system that allows you to print logs in a structured and pretty manner, in addition to saving logs into a file if desired.

Installation

npm install @norviah/logger

Usage

For a more in depth look into logger, check out the docs here.

Here is a basic usage:

import { Logger } from '@norviah/logger';

const logger = new Logger();
logger.print('hello world');

For the example above, the following is printed:

[ 01-10-2022 1:04 PM ] hello world

Structure

In Logger, logs are divided into three sections: the date of the log, the title, and the actual contents. By default, the date always appears in a log but titles are optional. If you would like to print a log with a title, you can provide one within the options parameter for the print method. If we extend the example above:

logger.print('world', { title: 'hello' });

This would print:

[ 01-10-2022 1:04 PM ] hello: world

The title is only printed if one is given. Additionally, there are a few methods within Logger that acts as a shortcut to log with a title, those methods being:

  • error
  • success
  • warn
  • info

Each method takes the same input as the print method, it just adds a title with the respective name and edits the color of the title corresponding to the level.

If desired, you can change how logs are printed by modifying these sections in the format option. For example, if you don't want the date to appear within logs, you can set options.format.general to %t%c. This will only result in the title (if provided) and the contents to appear in logs. You can also set how you want to structure the date or the title, the date is parsed using a format similar to the unix date command, and titles are as is, with %t replaced with the actual title.

Color

You can set the color for each section of logs either when initializing a Logger instance or when calling the print method. If you set colors in the constructor then all logs will be using the specified colors, however if you pass colors in the method directly, then that specific log will only consist of the desired color.

Writing Logs

If you would like to save logs into a file, you can initialize an instance and set the write property to true:

const logger = new Logger({ write: true });

Every log printed will then be saved into a file. By default, logs are saved into the root folder for your project under the logs subdirectory. Of course you can change this directory by passing in a value for the dir option. Additionally, when calling the print method, you can specify options for how and where to save that log. For example, you can change the name of the file or if you want that specific log to be saved under a subdirectory, which can go on infinitely if desired.

If the name of the file hasn't changed, each log will be appended into that file, separated via a newline.