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

turbo-logger

v3.0.1

Published

Console, file and Slack logger for Node.js Applications

Downloads

14

Readme

TurboLogger

TurboLogger is a versatile logging library for Node.js applications that supports logging to the console, file, and Slack channel. It provides configurable logging levels (error, info, warn), single and hybrid logging capabilities, and customizable logging contexts.

Installation

Install TurboLogger using npm:

    npm i --save turbo-logger

FEATURE

  • Logging to Slack Channel
  • Console Logging
  • Logging to file
  • Support for different logging levels (error, info, warn)
  • Single and Hybrid Logger (Ability to log to one or multiple sources)
  • Configurable through environment variables (e.g., setting the context to production, development, or custom context)
  • Ability to log comma-separated messages

Usage

  import turboLogger from 'turbo-logger';

  const config = {
      "slack": {
          webhook_url: `${process.env.WEBHOOK_URL}`,
          channel: 'sample-channel',
      }
  }
  
  const env = {
      prod: ['console', 'slack'],
      dev: ['file', 'console'],
      myCustomConfig: ['console']
  }
  
  const logger = turboLogger.createStream(config, env.prod);

Once the logger is initialized, you can use it to log messages:

  logger.log('hello world'); // logs the message to the console and Slack with an "info" context
  logger.warn('hello world'); // logs the message to the console with a "warn" context
  logger.error('hello world'); // logs the message to a file and the console with an "error" context

You need to initialize the logger with the slack config if you plan on logging to Slack. If not, you can use like so.

    import turboLogger from 'turbo-logger';
    const logger = turboLogger.createStream(); // env will default to logging to console.

Single Logger

To log only to Slack, set the environment parameter to "slack" and provide the required Slack configuration. Please note that in order to use this feature, you need to create a Slack app and obtain the necessary credentials.

Here's how to set up the Single Logger for Slack:

  1. Create a Slack app following the instructions in the Slack App Creation Guide..

  2. Obtain the webhook_url and channel for your Slack app. The webhook_url is a unique URL that allows your application to send messages to a specific Slack channel. This is gotten from the "incoming webhook" settings for the slack app you created. Enable it and set the channel you want the message to be sent to. Slack creates a separate webhook url for eah channel. ![](Webhook Screen)

  3. Configure the config object with the webhook_url and channel values:

        const config = {
            "slack": {
                webhook_url: `${process.env.WEBHOOK_URL}`,
                channel: 'sample-channel',
            }
        }
    
        const env = ['slack']
        const logger = turboLogger.createStream(config, env);
        logger.log('hello world'); // sends the message to the specified Slack channel

    Ensure that you replace ${process.env.SECRET} in the webhook_url with the actual secret value obtained from your Slack app.

    Note: If the config object does not have the required webhook_url and channel parameters, TurboLogger will throw an error.

Hybrid Logger

The hybrid logger combines multiple log levels. It could be a combination of all three or any two levels. To use this, we set the environment configuration to include all three or any two log levels:

		const env = ['console', 'slack', 'file']
		const logger = turboLogger.createStream(config, env);
		logger.log('hello world'); // sends the message to all contexts (console, Slack, and file)

Logging multiple messages

TurboLogger allows you to log comma-separated messages. For example:

	logger.log('My config object: ', config);

The console prints:

You can log as many comma-separated messages as you want.

Logging To Multiple Slack Channel

You can log to several Slack channels. The logger streams are configured separately as every channel

	import turboLogger from 'turbo-logger';
	const env = ['slack'];

	// Error channel set up
	const errorChannelName = "error-logs";
	const errorChannelConfig = {
		"slack": {
			webhook_url: `${process.env.SLACK_ERROR_CHANNEL_WEBHOOK_URL}`,
			channel: errorChannelName,
		}
	};
	
	// Success channel set up
	const successChannelName = "success-logs";
		const successChannelConfig = {
		"slack": {
			webhook_url: `${process.env.SLACK_SUCCESS_CHANNEL_WEBHOOK_URL}`,
			channel: successChannelName,
		}
	};
	
	// Instantiate logger
	const slackErrorLogger = turboLogger.createStream(errorChannelConfig, env);
	const slackSuccessLogger = turboLogger.createStream(successChannelConfig, env);

	// Usage
	slackErrorLogger.error("Internal server error") // This sends a message with an error context to the channel named "error-logs"
	slackSuccessLogger.log("Request successful") // This sends a message with an info context to the channel named "success-logs"

License

TurboLogger is licensed under the MIT License.

Author

TurboLogger was created by Gideon Odiase.

Support

Buy me a coffee here.