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

@nabinsaru/j-logger

v1.0.1

Published

Library to customize the console logs.

Downloads

3

Readme

Custom Logger

A custom logger utility for Node.js with configurable styles and features. Allows the log saving to the folder path.

Installation

npm i @nabinsaru/j-logger

### Installation Development
```bash
# Clone the repository
git clone [email protected]:NabinSaru/j-logger.git
cd J-LOGGER

# Install dependencies
npm install

Configuration

The logger can be configured using a JSON file(Optional). Fields are also optionals. Create a j-logger.config.json file with the following structure:

{
  "color": "White",
  "backgroundColor": "Black",
  "saveLog": true,
  "logPath": "/log/j-logger.log",
  "textFormat": ["Bold", "Underline"],
  "stylizedMode": true
}

Available methods

  • getLogTypes() => get all available middleware log formats
  • TextColors() => available text colors
  • BgColors() => available background colors
  • BrightColors() => available bright text colors
  • FormattingOptions() => available text formatting options

Available Properties

  • SavePath(path_string)
  • TextColor(color_string)
  • BackgroundColor(color_string)
  • TextFormat(formats_string_array)
  • SaveLog(boolean) >>> This takes j-logger.log as default path if not configured.

Usage

// Import the JLogger class and other required modules
import { JLogger, requestLogger } from "@nabinsaru/j-logger";
// or
const { JLogger, requestLogger } = require("@nabinsaru/j-logger");


// Set custom log styles
JLogger.TextColor = "White";
JLogger.BackgroundColor = "Black";
JLogger.TextFormat = ["Bold", "Underline"];
JLogger.StylizedMode = true;

// Use the logger
JLogger.log("This is a log message.");
JLogger.info("This is an info message.");
JLogger.error("This is an error message.");
JLogger.warn("This is a warning message.");
JLogger.debug("This is a debug message.");

// Use requestLogger middleware
app.use(requestLogger("REQUEST"));

// Log types
const logTypes = JLogger.getLogTypes();
console.log("Available log types:", logTypes);

Middleware Usage

The requestLogger middleware can be used to log HTTP request details.

const express = require("express");
const { requestLogger } = require("@nabinsaru/j-logger");

const app = express();

// Use requestLogger middleware for logging requests
// Provide log format type
app.use(requestLogger("common"));

// Your routes and other middleware...

// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

Request logger supports 4 distinct log types.

  • common
::1 - - [Wed, 13 Dec 2023 05:34:25 GMT] "GET / HTTP/1.1" 200 15 "-" "PostmanRuntime/7.29.4"
  • dev
GET / 200 5 ms - 15
  • combined
::1 - - [Wed, 13 Dec 2023 05:41:02 GMT] "GET / HTTP/1.1" 200 15 "-" "PostmanRuntime/7.29.4"
  • short
GET / 200 15 - 5 ms

Demo

Generic Log

JLogger.log("This is custom log initialized with config file.");
JLogger.error("This is an error.");
JLogger.warn("This is a warning.");
JLogger.info("This is an info.");
JLogger.cleanLog("This is a clean Log.");
JLogger.debug("This is a debug statement.");
JLogger.debugBox("This is a debug box.");

JLogger.TextColor = 'Red';
JLogger.BackgroundColor = 'White';
JLogger.StylizedMode = true;
JLogger.saveLog = true;
JLogger.log("This is updated custom log.");

with config file j-logger.config.json

{
  "color": "Red",
  "backgroundColor": "Blue",
  "textFormat": ["Italic", "Bold"]
}

Generic Log

Stylized Log

JLogger.error("This is an error.");
JLogger.warn("This is a warning.");
JLogger.info("This is an info.");
JLogger.debug("This is a debug statement.");

Stylized Log

Stylized middleware Log

License

This custom logger is open-source and available under the MIT License. Feel free to use, modify, and share!

Development and Publication Scripts

  • npm run prepare => transpile the typescript into js
  • npm run start:dev => start the transpiled code
  • npm run test:build => set the build environment
  • npm run test => start the test module

Contributions

If you want to contribute, create an issues and make a PR for the issues.

Bugs

This release is maintained by solo developer and maybe prone to bug. So, I would appreciate if you can create a bug issues.