1.0.3 • Published 5 months ago

loggerv2 v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

LoggerV2

npm version npm version

Repo: https://github.com/leonatkdev/LoggerV2

LoggerV2 is a lightweight and flexible Node.js utility for interactive logging, pausing execution, and saving data during debugging. It offers features like depth control, colorized output, and interactive commands for skipping or saving data to JSON files.

⚠️ Warning:
This version of LoggerV2 is for testing purposes only and is not stable for production use.

Features

  • Dynamic Logging: Easily log objects with customizable depth and colorized output.
  • Interactive Pause: Pause and inspect loops with user-controlled options (continue, skip, or save).
  • Save to JSON: Export logged data to JSON files for analysis and persistence.
  • Process Control: Debug interactively with full control over flow and inspection.
  • Node.js Focused: Exclusively built for Node.js environments to streamline debugging.

Examples

1. Basic Logging

Log data with optional configurations:

import { log } from "loggerv2";

// Example data
const data = { id: 1, name: "Test Item" };

// Log with depth and colorized output
log(data, { depth: 2, colors: true });

// Output:
// { id: 1, name: 'Test Item' }

2. Save Data to JSON

Log data and save it directly to a JSON file:

import { log } from "loggerv2";

// Example data
const data = { id: 1, name: "Test Item" };

// Save data as JSON
log(data, { saveAsJson: true });

// Terminal:
// Data saved to /path/loggers-v2/log-1732138956514.json

New Feature: Save Logs in Custom Folder

Specify a folder name for saving logs as JSON:

import { log } from "loggerv2";

// Example data
const data = { id: 1, name: "Test Item" };

// Save data in a custom folder
log(data, { saveAsJson: true, folderName: "custom_logs" });

// Terminal:
// Data saved to /path/custom_logs/log-1732138956514.json

3. Interactive Process with processAsync

Handle loops in asynchronous functions with interactive actions:

import { processAsync } from "loggerv2";

// Example items
const items = [
  { id: 1, name: "Item 1" },
  { id: 2, name: "Item 2" },
];

async function testProcessAsync() {
  console.log("\nTesting processAsync function...");
  await processAsync(items, { depth: 2, colors: true });
  console.log("processAsync function tested successfully!");
}

testProcessAsync();

4.Synchronous Processing with processStatic

Handle loops in synchronous functions with similar interactivity:

import { processStatic } from "loggerv2";

// Example items
const items = [
  { id: 1, name: "Item 1" },
  { id: 2, name: "Item 2" },
];

function testProcessStatic() {
  console.log("\nTesting processStatic function...");
  processStatic(items, { depth: 2, colors: true });
  console.log("processStatic function tested successfully!");
}

testProcessStatic();

5 Interactive Pause with pauseAsync

Handle loops in asynchronous functions with interactive actions:

import { pauseAsync } from "loggerv2";

// Example items
const items = [
  { id: 1, name: "Item 1" },
  { id: 2, name: "Item 2" },
];

async function processItems() {
  const handleSkip = pauseAsync(); // Create an async handler

  for (const item of items) {
    const { action } = await handleSkip(item);

    if (action === "json") {
      console.log("Data saved to JSON.");
      continue;
    }

    console.log(`Processing: ${item.name}`);
  }

  console.log("All items processed.");
}

processItems();

6 Interactive Pause with pauseStatic

Pause loops in synchronous functions for debugging:

import { pauseStatic } from "loggerv2";

// Example items
const items = [
  { id: 1, name: "Item 1" },
  { id: 2, name: "Item 2" },
];

const handleSkip = pauseStatic(); // Create a static handler

for (const item of items) {
  const { action } = handleSkip(item);

  if (action === "json") {
    console.log("Data saved to JSON.");
    continue;
  }

  console.log(`Processing: ${item.name}`);
}

console.log("All items processed.");

Installation

Install LoggerV2 via npm:

npm install loggerv2

Actions in Interactive Loops

  • Press Enter: Continue to the next item in the loop
  • Press s: Skip all logs for subsequent items.
  • Press j: Save the current item to a JSON file.

Options

Logging Options

OptionTypeDefaultDescription
depthnumbernullSets the depth for object inspection.
colorsbooleantrueEnables or disables colored output.
saveAsJsonbooleanfalseSaves the logged data to a JSON file.
folderNamestringloggers-v2Specifies the folder name for saved JSON files.
1.0.3

5 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago