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

@ofrepose/logtastic

v1.0.7

Published

Provides a flexible way to log messages with customizable colors, styles, and backgrounds.

Downloads

16

Readme

npm (scoped)npmnpm package minimized gzipped size (scoped version select exports)

Logtastic is a versatile Node.js logging utility that allows you to easily log messages, warnings, and errors with customizable formatting options. It provides flexibility in adjusting text color, style, background color, and more. You can also choose to log messages to files, databases, or both.

Installation

To use Logtastic in your project, you can install it using npm:

npm install @ofrepose/logtastic

Usage

const logger = require('@ofrepose/logtastic');

// Simple Logging a simple text message
logger.log("Hello, Logtastic!", { color: "green", style: "bold" });

// Simple Logging an object with custom styling
const data = { name: "John", age: 30, occupation: "Developer" };
logger.log(data, { color: "blue", bgStyle: "yellow" });

// Log messages
logger.log('This is a log message.', {
    color: 'green', // optional - else default values are used
    style: 'bold', // optional - else default values are used
    bgStyle: 'black', // optional - else default values are used
    time: true, // optional
    override: false, // optional
    trace: false // optional
});

// Log warnings
logger.warn('This is a warning.', {
    color: 'yellow', // optional - else default values are used
    style: 'dim', // optional - else default values are used
    bgStyle: 'red', // optional - else default values are used
    time: true, // optional
    override: false, // optional
    trace: false // optional
});

// Log errors
logger.err('This is an error.', {
    color: 'red', // optional else default values are used
    style: 'bold', // optional else default values are used
    bgStyle: 'white', // optional else default values are used
    time: true, // optional
    override: false, // optional
    trace: true, // optional
    escape: true // optional
});

// Configure logging mode
logger.setMode({ silent: false }); // Enable log visibility

// Configure default settings
logger.setDefaults({
    color: 'blue',
    style: 'dim',
    bgStyle: 'reset',
    type: 'log'
});

// Activate logging to file mode
logger.setToFileMode('./logs');

// Get current mode and defaults
logger.getMode();
logger.getDefaults();

Features

Custom Formatting You can easily customize the formatting of log messages, warnings, and errors by specifying color, style, and background options.

Logging to File Logtastic allows you to log messages to files. You can set the directory where log files will be saved using the setToFileMode(directory) method.

Silent Mode You can control whether log messages are visible by using the setMode({ silent: true/false }) method. When silent mode is active, logs will not be visible in the console.

Default Settings Logtastic comes with default settings for log messages, warnings, and errors. You can modify these settings using the setDefaults(options) method.

API Reference

logger.log(text, options)

Log a message with customizable formatting options.

  • text: The message text or object to be logged.
  • options: An object containing formatting options such as:
    • color: Text color for the message.
    • style: Text style for the message.
    • bgStyle: Background style for the message.
    • time: Whether to include a timestamp in the message (default: false).
    • override: Forcefully override the logging mode (default: false).
    • trace: Whether to include stack trace information (default: false).

logger.warn(text, options)

Log a warning message with customizable formatting options.

  • text: The warning message text or object to be logged.
  • options: An object containing formatting options such as:
    • color: Text color for the warning message.
    • style: Text style for the warning message.
    • bgStyle: Background style for the warning message.
    • time: Whether to include a timestamp in the message (default: false).
    • override: Forcefully override the logging mode (default: false).
    • trace: Whether to include stack trace information (default: false).

logger.err(text, options)

Log an error message with customizable formatting options.

  • text: The error message text or object to be logged.
  • options: An object containing formatting options such as:
    • color: Text color for the error message.
    • style: Text style for the error message.
    • bgStyle: Background style for the error message.
    • time: Whether to include a timestamp in the message (default: true).
    • override: Forcefully override the logging mode (default: false).
    • trace: Whether to include stack trace information (default: true).
    • escape: Whether to forcefully exit the application after logging (default: true).

logger.setMode(options)

Set the logging mode to control log visibility.

  • options: An object containing a silent property. If silent is true, logs will not be visible.

logger.setDefaults(options)

Set default log message formatting options.

  • options: An object containing options to update default formatting settings, including:
    • color: Default text color.
    • style: Default text style.
    • bgStyle: Default background style.
    • type: type of log you are editing default type for ('log', 'warn', or 'err').

logger.setLoggingMode(active)

Sets the logging mode for writing logs to a file.

  • active: A boolean value indicating whether logging to file mode should be active.

logger.setToFileMode(directory)

Activate logging to file mode and specify the log directory.

  • directory: The directory path where log files will be saved.

logger.getMode()

Display the current logging mode and its configuration.

logger.getDefaults()

Display the default settings and provide instructions on modifying them.

License

This project is licensed under the MIT License - see the LICENSE file for details.