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

banana-logger

v0.0.1

Published

Banana (logger): A fun and advanced TypeScript logger with formatting, callback, and timing capabilities

Downloads

4

Readme

Banana (Logger) 🍌

Banana (Logger) is a fun and advanced TypeScript logger with formatting, callback, timing, and highlighting capabilities. Inspired by the simplicity of logging but with a twist of humor, Banana Logger ensures your logging experience is both efficient and enjoyable.

Features

  • Formatted Logging: Customizable log messages with tags, details, metadata, and highlights.
  • Callbacks: Define custom log handlers to extend functionality.
  • Timing: Measure and log the duration of operations.
  • Group Logging: Organize logs into groups for better readability.
  • Tabular Data Logging: Easily log data in table format.
  • Highlighting Keywords: Highlight specific keywords in log messages for better visibility.
  • Environment-Specific Logging: Automatically adjust logging levels based on environment (development, staging, production).

Installation

npm install banana-logger

Usage

Basic Configuration

import Banana from 'banana-logger';

// Basic configuration
Banana.configure({ tag: 'APP' });

// Simple logging
Banana.info('Application started');

Logging with Options

Banana.warn('Warning!', { details: 'Low memory', metadata: 'RAM: 80%' });

Using Timer

Banana.time('operation');
// ... perform operation ...
Banana.timeEnd('operation');

Using Callback

Banana.setLogCallback((level, message, options) => {
    // Send log to external service
});

Grouped Logs

Banana.groupStart('Initialization');
Banana.debug('Loading modules...');
Banana.groupEnd();

Tabular Data Logging

Banana.tab([{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }]);

Adding Blank Lines

Banana.addBlankLine();
Banana.info('This message is after a blank line');

Highlighting Keywords

Banana.configure({ highlights: [{ keyword: 'error', style: '31' }] });
Banana.info('This is an error message that should be highlighted');

Configuring with Global Metadata

Banana.configure({ metadata: 'https://example.com' });
Banana.info('This log entry includes clickable metadata');

Resetting Global Configurations

Banana.reset();
Banana.info('This log entry should not include any global configuration');

API

configure(options: { tag?: string; details?: string; metadata?: string; highlights?: HighlightConfig[] })

Configure global options for all logs.

setLogCallback(callback: (level: LogLevel, message: string, options?: LogOptions) => void)

Set a callback function for all log messages.

debug(message: string, options?: LogOptions)

Log a debug message.

info(message: string, options?: LogOptions)

Log an info message.

warn(message: string, options?: LogOptions)

Log a warning message.

error(message: string, options?: LogOptions)

Log an error message.

time(label: string)

Start a timer with the specified label.

timeEnd(label: string)

End a timer and log the elapsed time.

timePromise<T>(label: string, fn: (() => Promise<T>) | Promise<T>): Promise<T>

Measure the execution time of a function or promise.

groupStart(label: string)

Start a new log group.

groupEnd()

End the current log group.

tab(data: Array<unknown> | object)

Display data in a tabular format.

addBlankLine()

Add a blank line to the logs.

applyHighlights(message: string, highlights: HighlightConfig[]): string

Apply highlights to specific keywords in the log message.

isValidUrl(url: string): boolean

Check if a given string is a valid URL.

reset()

Reset global configurations to their default state.

Contributing

Contributions are welcome! Please submit a pull request or open an issue on GitHub.

License

This project is licensed under the MIT License.


Made with ❤️ by TrevoNerd and a touch of 🍌.