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

slack-logs

v1.1.3

Published

slack-logs

Downloads

338

Readme

Slack Log Package

Description

This package provides a simple and efficient way to log messages directly to Slack from your Node.js applications. Utilizing Slack's Incoming Webhooks, it allows for real-time notifications and logging of critical events, errors, or any custom messages you choose to send to your Slack channel.

Features

  • Easy integration with Slack via Incoming Webhooks.
  • Supports custom messages with dynamic data.
  • Validates Slack webhook URLs before attempting to send messages.
  • Asynchronous logging with async/await support.
  • Configurable to fit various logging needs.

Installation

  • Install the package using npm:
npm install slack-logs
  • Or using yarn:
yarn add slack-logs

Configuration:

Before you start, ensure you have created an Incoming Webhook in Slack and have the webhook URL ready. For more information on setting up Incoming Webhooks in Slack, visit Slack's API documentation.

Usage

Here is a basic example of how to use the Slack Log package to send a message to your Slack channel:

.env 🚨

...
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/******/******/********************"
...
import { slack } from "slack-logs";
or
const { slack } = require('slack-logs');

/*Slack Notification with default format*/
slack.log("Data", [{ title: "1yes!" }]);
slack.log("Data", { title: "2yes!" });
slack.log("Data", "Hello world!");

/*Slack Notification with block format*/
const payload = [
{ title: "Title 1", value: "1234" },
{ title: "Title 2", value: 123 },
{ title: "Title 3", value: { id: 12 } },
{ title: "Title 3", value: [{ id: 12 }] },
];
slack.logBlockMessage("Validation Message!", payload);
/*Slack Notification with colored block format*/

import { LogLevel, slack } from "slack-logs";

const payload = [
{ title: "Title 1", value: "1234" },
{ title: "Title 2", value: 123 },
{ title: "Title 3", value: { id: 12 } },
{ title: "Title 3", value: [{ id: 12 }] },
];
slack.logBlockMessage("Validation Message!", payload);
// Or
slack.logBlockMessage("Validation Message!", payload, LogLevel.DEFAULT);
// Or
slack.logBlockMessage("Validation Message!", payload, LogLevel.ERROR);
// Or
slack.logBlockMessage("Validation Message!", payload, LogLevel.INFO);
// Or
slack.logBlockMessage("Validation Message!", payload, LogLevel.SUCCESS);
// Or
slack.logBlockMessage("Validation Message!", payload, LogLevel.WARN);

Sample code with output:

Sample 1:

import { slack } from "slack-logs";.

slack.log("Data Log with bold", "Here is *BOLD* message");
slack.log("Highlight Log", "`Message`");
slack.log("Emoji :rocket: Log", "Yeah :female-technologist::skin-tone-2:");
slack.log("Object Log", {id:"123", value:"Lorem Impulse"});

Sample Image

Sample 2:

import { LogLevel, slack } from "slack-logs";.

const payload = [
{ title: "Title 1", value: "1234" },
{ title: "Title 2", value: 123 },
{ title: "Title 3", value: { id: 12 } },
{ title: "Title 4", value: [{ id: 12 }] },
];

slack.logBlockMessage("Custom Logs!", payload);
slack.logBlockMessage("Some Information Logs!", payload, LogLevel.INFO);
slack.logBlockMessage("Critical Alert!", payload, LogLevel.ERROR);

Sample Image

Sample 3:

import { LogLevel, slack } from "slack-logs";.

const payload = [
  { title: "Event Name", value: "directMessage" },
  {
    title: "`to_user` Validation",
    value: "Message 'to_user' is required! Current value is null",
  },
];

slack.logBlockMessage(`Validation failure on "development" server`, payload, LogLevel.WARN);

Sample Image

Sample 3:

import { LogLevel, slack } from "slack-logs";.

const title =
      ":rotating_light: Error processing message failure on 'local' server :rotating_light:";

const payload = [
  { title: "Event Name", value: "directMessage" },
  { title: "`error`", value: {} },
];

slack.logBlockMessage(title, payload, LogLevel.ERROR);

Sample Image

Contributing

Contributions are welcome! If you have a feature request, bug report, or a pull request, please open an issue or submit a PR on the GitHub repository

License:

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