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

logthing

v1.1.4

Published

Simple logging with log channels configurable on the fly. Organize your console.log calls without losing your sanity.

Downloads

13

Readme

🪵 Logthing

Simple logging with log channels configurable on the fly

Organize your logs without losing your sanity.

Logthing is a versatile and customizable logging library for JavaScript and TypeScript. It provides an effortless approach to produce informative and visually distinct logs, with flexible output methods and extensive customization options.

Table of Contents

Installation

Logthing can be installed directly from npm. Use the following command to add it to your project:

npm install logthing

Importing Logthing

You can import logthing from the package like this:

import { logthing } from 'logthing';

Basic Usage

Let's get started with a simple usage of logthing. Here's how you can create a log channel and print some messages:

const simple = logthing('Simple');
simple.log("Welcome to logthing!");
simple.log("By default, you have access to the following methods:", Object.keys(simple));

This will output:

Simple ❯    log: Welcome to logthing!
Simple ❯    log: By default, you have access to the following methods:
                 [
                   'mute',
                   'unmute',
                   'mute_all',
                   'unmute_all',
                   'debug',
                   'log',
                   'warn',
                   'error'
                 ]

And did you know? You can chain methods in logthing:

simple.log("Here's what they look like:\n")
	.log("Informational message")
	.debug("Debug message")
	.warn("Warning message")
	.error("Error message");

Your console will now show:

Simple ❯    log: Informational message
Simple ❯  ◌ debug: Debug message
Simple ❯  ▲ warn: Warning message
Simple ❯  ✖ error: Error message

Customization

logthing allows you to customize your logs to your heart's content. You can tailor the output of logs, define multiple types of messages (we call them "channels"), customize the flag, symbol, and color of the channel, or even define a completely custom template.

const custom = logthing('Customization', [
	{
		name: "templates",
		template: "warn",
	}),
	// Basic customization
	{
		name: "about",
		symbol: "✪",
		color: 'cyan',
	},
	// Custom template
	{
		name: "all_in",
		color: 'magenta',
		symbol: "[Symbol]",
		flag: "[Flag]",
		prefix: "[Prefix]",
	},
]);

Customize Delivery

Want to send your logs somewhere other than the console? logthing gives you the power to define your own delivery methods. This is especially useful if you want to send your logs to a file system or a remote server.

import { Console, logthing } from 'logthing';
class FSLog<T extends string> {
	constructor (public readonly name: T) { }
	deliver(...args: unknown[]) {
		console.log("*Pretend* writing to FileSystem:", ...args, "\n");
	}
}

const custom_console = logthing('Custom Console', [
	[
		// Console is the default delivery method.
		new Console("Custom Console", "info"),
		new FSLog("

`Logthing` is a versatile and customizable logging library for JavaScript and TypeScript. It provides an organized and configurable way to handle console.log calls. You can install it via npm using the command `npm install logthing`.

Here is a simple example of how to use `logthing`:

```javascript
import { logthing } from 'logthing';

const simple = logthing('Simple');
simple.log("Welcome to logthing!");
simple.log("By default, you have access to the following methods:", Object.keys(simple));

By default, you have access to the following methods: 'mute', 'unmute', 'mute_all', 'unmute_all', 'debug', 'log', 'warn', 'error'. You can also chain these methods:

simple.log("Here's what they look like:\n")
	.log("Informational message")
	.debug("Debug message")
	.warn("Warning message")
	.error("Error message");

logthing offers extensive customization options. You can customize the output of logs, define multiple types of messages (called "channels"), customize the flag, symbol, and color of the channel, or even define a completely custom template. Here's an example:

const custom = logthing('Customization', [
	{
		name: "templates",
		template: "warn",
	}),
	{
		name: "about",
		symbol: "✪",
		color: 'cyan',
	},
	{
		name: "all_in",
		color: 'magenta',
		symbol: "[Symbol]",
		flag: "[Flag]",
		prefix: "[Prefix]",
	},
]);

logthing also allows you to define your own delivery methods, which is useful if you want to send your logs somewhere other than the console, such as a file system or a remote server.

import { Console, logthing } from 'logthing';

class FSLog<T extends string> {
	constructor (public readonly channel: T) { }
	deliver(...args: unknown[]) {
		console.log("*Pretend* writing to FileSystem:", ...args, "\n");
	}
}

const custom_console = logthing('Custom Console', [
	[
		new Console("Custom Console", "info"),
		new FSLog("info")
	],
	[
		new Console("Custom Console", "warn"),
		new FSLog("warn")
	],
]);

custom_console.info("This is an info message that's written to the console and to a custom delivery method.");
custom_console.warn("This is a warning message that's written to the console and to a custom delivery method.");

Environment Variables

Use LOGTHING_MUTE and LOGTHING_UNMUTE to mute channels and logthings by either channel or logthing name.

Examples:

Mute logthings named Simple and Customization:

LOGTHING_MUTE=Simple,Customization

Unmute all info channels:

LOGTHING_MUTE=info

Mute Simple logthing and info channels:

LOGTHING_MUTE=Simple,info

Mute everything

LOGTHING_MUTE=

Both LOGTHING_MUTE and LOGTHING_UNMUTE work the same way, and can even be used together, for example, this will mute everything except info channels:

LOGTHING_MUTE=
LOGTHING_UNMUTE=info