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

wizelib

v1.0.18

Published

Libraries for node project that usually i need

Downloads

3

Readme

wizelib

Libraries for all utilites in node project that usually i need

Logz

A flexible logging utility for Node.js applications that supports various log levels and custom logging functions.

Installation

npm install wizelib

Usage

Basic Setup

const { Logz } = require("wizelib");

const logz = new Logz();

Customizing Log File Path and Name

Specify custom paths and file names for log file storage.

const logz = new Logz({
  file: "application.log",
  path: "./logs/",
});
logz.info("This is an information");

logz.error("Something went wrong").record();
// It would record error log to application.log file in ./logs directory like as defined in the option of constructor on Logz class

logz.error("Database error happen").record("database.txt");
// Now it would store the error in the database.txt file but still in ./logs directory

Custom Logger Function

Use a custom logging function with destructuring for type and message.

const customLogger = ({ type, message, now }) => {
  console.log(
    `[Custom Logger] ${now(false)} - ${type.toUpperCase()}: ${message}`
  );
};

const logz = new Logz({
  logger: customLogger,
});

logz.info("This will use the custom logger");
// Outputs: [Custom Logger] 2024-06-01 12:00:00 - INFO: This will use the custom logger

Logging Levels

Log messages with different severity levels.

logz.info("This is an info message");
// : INFO    2024-06-01 12:00:00  This is an info message

logz.error("This is an error message");
// : ERROR   2024-06-01 12:00:00  This is an error message

logz.debug("This is a debug message");
// : DEBUG   2024-06-01 12:00:00  This is a debug message

logz.warning("This is a warning message");
// : WARNING 2024-06-01 12:00:00  This is a warning message

logz.docs("This is a docs message");
// : DOCS    2024-06-01 12:00:00  This is a docs message

logz.stackoverflow("This is a stackoverflow message");
// : STACKOVERFLOW 2024-06-01 12:00:00  This is a stackoverflow message - https://stackoverflow.com/search?q=This%20is%20a%20stackoverflow%20message

logz.sponsor("This is a sponsor message");
// : SPONSOR 2024-06-01 12:00:00  This is a sponsor message

Labeling and JSON

Add labels and log JSON objects.

logz.label("User Data").json({ name: "John Doe", age: 30 });
// Outputs: > User Data :
// Outputs JSON formatted data

logz.print("This is a simple string").record();
// Outputs: This is a simple string
// Appends the log to the file

logz.json(objectData);
// Outputs: stringified dataObject to json format

// You can store this stringified json to file too just by adding:
.record()

Logging to a File

Log messages to a specific file.

logz.error("An error occurred").record("error.log");
// Appends the error message to error.log

logz.info("General info message").record("general.log");
// Appends the info message to general.log

Timestamp

Print the current timestamp.

logz.now(); // Outputs and returns: 2024-06-01 12:00:00

Tables

Print data as a table.

logz.table([
  { name: "John", age: 30 },
  { name: "Jane", age: 25 },
]);
// Outputs a table in the console with the data

Examples

Log to Different Files Based on Error Type

logz
  .setType("error")
  .setMessage("A critical error occurred")
  .record("critical_errors.log");
// Appends the message to critical_errors.log

logz.setType("info").setMessage("This is just an info").record("info.log");
// Appends the message to info.log

Chainable API

logz.setType("debug").setMessage("Debugging the application").record();
// Appends the debug message to the default log file

logz.label("Test Label").json({ key: "value" }).record();
// Outputs: > Test Label :
// Outputs JSON formatted data
// Appends the JSON data to the default log file

Complete Method Examples

logz.info("This is an info message");
// Outputs: : INFO    2024-06-01 12:00:00  This is an info message

logz.error("This is an error message");
// Outputs: : ERROR   2024-06-01 12:00:00  This is an error message

logz.warning("This is a warning message");
// Outputs: : WARNING 2024-06-01 12:00:00  This is a warning message

logz.debug("This is a debug message");
// Outputs: : DEBUG   2024-06-01 12:00:00  This is a debug message

logz.docs("This is a docs message");
// Outputs: : DOCS    2024-06-01 12:00:00  This is a docs message

logz.stackoverflow("This is a stackoverflow message");
// Outputs: : STACKOVERFLOW 2024-06-01 12:00:00  This is a stackoverflow message with a StackOverflow search URL

logz.sponsor("This is a sponsor message");
// Outputs: : SPONSOR 2024-06-01 12:00:00  This is a sponsor message

logz.label("Label Example");
// Outputs: > Label Example :

logz.json({ example: "JSON data" });
// Outputs formatted JSON data

logz.print("This is a display message");
// Outputs: This is a display message

logz.table([
  { name: "John", age: 30 },
  { name: "Jane", age: 25 },
]);
// Outputs a table with the data

logz.now();
// Outputs and returns the current timestamp

License

MIT