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

log-in-channel

v1.2.0

Published

a small utility for logging in js applications

Downloads

9

Readme

log-in-channel

npm GitHub

No messy console.log's anymore! Log things in specific channels you can mute, unmute and give specific colors.

https://i.imgur.com/VKxwRQO.png

Install

$ npm install log-in-channel

or

$ yarn add log-in-channel

Usage

Define your own instance of Logger in one file and use it in all other files!

// logger.helper.js
import Logger from 'log-in-channel';

// an object containing the channel ids for easier use while developing

interface IChannelIds {
  [key: string]: string | IChannelIds;
}

const ChannelIds: IChannelIds = {
  DEFAULT: 'default',
  auth: {
    STATE: 'auth/state',
  },
};

// create logger
/*

{
  colorSupportType?: null | 'terminal' | 'chrome', // Define here in which environment you are
  // null --> no colored logs
  // 'terminal' --> colored logs where chalk (npm package) works
  // 'chrome' --> colored logs where css styled logs work
  channelIds: IChannelIds,
  channel: {
    '<id of channel>': {
      // channel config params
      options?: {
        style?: {
          color?: '<hexa color code>', // string
          backgroundColor?: '<hexa color code>', // string
          fontWeight?: '<400 | 700>', // string
        },
      },
    },
  },
}

*/


const CustomLogger = new Logger<typeof ChannelIds>({
  colorSupportType: 'terminal',
  channelIds: ChannelIds,
  channels: {
    'default': {},
    'auth/state': {
      options: {
        style: {
          color: '#009aff',
        },
      },
    },

    ...
 },
});

export default CustomLogger;
// myfile.js
import CustomLogger from '../helpers/logger.helper';

CustomLogger.channel(CustomLogger.channels.auth.STATE).withPath('set').success('logged in :D');

And if you don't want to have logs of one channel, you can mute it and unmute it, when you need it again.

CustomLogger.muteChannel(CustomLogger.channels.auth.STATE); // mute single channel

CustomLogger.unmuteChannel(CustomLogger.channels.auth.STATE); // unmute single channel

CustomLogger.muteAllChannels(); // mute all channels

CustomLogger.unmuteAllChannels(); // unmute all channels

You can also add and remove event listeners to listen for log events.

const listenerId = CustomLogger.addListener((event) => {
  console.log(`Logged in channel with id ${event.channelId}!`);
});

CustomLogger.removeListener(listenerId);

Last but not least you can remove all colors and log all messages as plain text if you want to.

CustomLogger.logWithStyle(false);

// reactivate

CustomLogger.logWithStyle(true);

Example

You can find an example in the example directory.

Run with ts-node example/example.ts or yarn run:example or npm run run:example!

License

This repo is licensed under the MIT License.