1.0.1 â€ĸ Published 6 months ago

logmi v1.0.1

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

Logmi ✨

A beautiful Node.js logger with colors, emojis, and async operation support. Perfect for making your console logs more readable and informative.

Features ✨

  • 🎨 HEX Color support
  • 😊 Emoji support
  • 🔄 Async operations (Promise & Callback)
  • â†Šī¸ Indentation & grouping
  • âšĄī¸ Method chaining
  • đŸŽ¯ Simple API

Installation

npm install logmi

Quick Start

import Logmi from "logmi";

// With name
const authLogger = new Logmi("Auth Service");
authLogger.info("User logged in"); // [Auth Service] 📝 User logged in

// With name and options
const dbLogger = new Logmi("Database", { showTimestamp: true });
dbLogger.info("Connected"); // [2024-01-16T12:34:56.789Z] [Database] 📝 Connected

// Without name (original behavior)
const logger = new Logmi();
logger.info("Hello world"); // 📝 Hello world

// Basic logging
logger.info("Server started");
logger.success("Connected to database");
logger.warning("Low memory");
logger.error("Failed to send email");

// With custom icons and colors
logger.info("Deploy successful", {
  icon: "🚀", // Custom emoji
  color: "#87CEEB", // HEX color
});

// Grouped logs with indentation
logger
  .group("User Login")
  .info("Checking credentials...")
  .success("Access granted")
  .info("Last login: 2 days ago")
  .groupEnd();

// Async operations with automatic logging
try {
  const data = await logger.promise(fetchData(), {
    loading: "Fetching data...", // Loading message
    success: "Data retrieved", // Success message
    error: "Failed to fetch data", // Error message
    loadingIcon: "🔄", // Custom icons
    successIcon: "✅",
    errorIcon: "❌",
    loadingColor: "#87CEEB", // Custom colors
    successColor: "#98FB98",
    errorColor: "#FF6B6B",
  });
} catch (err) {
  // Error already logged
}

Async Support

Promise-based Operations

try {
  const data = await logger.promise(fetchUserData(), {
    loading: "Fetching user data...",
    success: "Data retrieved",
    error: "Failed to fetch data",
    loadingIcon: "🔄",
    successIcon: "✅",
    errorIcon: "❌",
  });
} catch (err) {
  // Error already logged
}

Callback-based Operations

logger.callback(simulateDbQuery, (err, data) => {
  if (err) {
    logger.error("Failed to query database", { icon: "đŸ’ĸ" });
  } else {
    logger.success("Database query successful", { icon: "✅" });
  }
});

API Reference

Basic Methods

logger.info(message, options?) // Info level
logger.success(message, options?) // Success level
logger.warning(message, options?) // Warning level
logger.error(message, options?) // Error level

Options

{
  icon?: string;
  color?: string;
}

Async Methods

logger.promise(promise, {
loading?: "Loading message",
success?: "Success message",
error?: "Error message",
loadingIcon?: "âŗ",
successIcon?: "✅",
errorIcon?: "❌",
loadingColor?: "#87CEEB",
successColor?: "#98FB98",
errorColor?: "#FF6B6B"
})
logger.callback(fn, { / same options as promise / })

Author

David Amunga

License

MIT License

Copyright (c) 2023 David Amunga

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.0.1

6 months ago

1.0.0

7 months ago