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

abcdediscordlogfabio

v1.1.0

Published

Want something simpler than Sentry, Datadog, etc.? Do you want to log your app's information to Discord like a console.log in production? Simple and easy, with no cost? Discord webhooks are a good alternative. I do a lot of this in my projects, so I creat

Downloads

8

Readme

Log in Discord

Want something simpler than Sentry, Datadog, etc.? Do you want to log your app's information to Discord like a console.log in production? Simple and easy, with no cost? Discord webhooks are a good alternative. I do a lot of this in my projects, so I created a package to help me with that and I want to share it with you.

This package allows you to easily log information to Discord using webhooks. You can specify different webhooks for different types of logs, and you can log any type of information.

See the example image below:

I hope you find it useful. If so, buy me a coffee to keep me awake and coding!

Installation

Install the package using your preferred package manager:

npm

npm install discord-as-logger

Yarn

yarn add discord-as-logger

pnpm

pnpm add discord-as-logger

Bun

bun add discord-as-logger

Configuration

Go to your Discord server, right-click on the channel you want to log to, and click on "Edit Channel". Go to the "Integrations" tab and click on "Create Webhook". Copy the webhook URL. You can create multiple webhooks for different types of logs.

Create a discord-as-logger.json file in the root of your project with the following structure:

{
  "commands": [
    {
      "name": "default",
      "description": "Default logger, if you don't need to specify a label to the logger",
      "webhookUrl": "https://discord.com/api/webhooks/..."
    },
    {
      "name": "UserFlow",
      "description": "Log the user auth flow",
      "webhookUrl": "https://discord.com/api/webhooks/other-or-same..."
    }
  ]
}

You can create as many commands as you need. The name is the label you will use to log information. The webhookUrl is the URL you copied from Discord.

Usage

Import the logger in your code and use it to log information to Discord:

// Example usage
import { DiscordLogger } from "discord-as-logger";

const fakeData = { user: "John Doe", action: "login" };

DiscordLogger.send({ label: "default", value: fakeData, type: "info" });
DiscordLogger.send({
  label: "UserFlow",
  value: { user: "John Doe", step: "authenticated" },
  type: "success",
});

try {
  throw new Error("This is an error");
} catch (error) {
  DiscordLogger.send({
    label: "default",
    value: error,
    type: "error",
  });
}

Options

Method send has the following parameters:

| key | type | description | | :---- | :------- | :---------------------------------------------------------------------- | | label | string | Required. The label you used in the configuration file. | | value | any | Required. The information you want to log. | | type | string | Optional. The type of log. Can be info, success, warn or error. |

Be aware

This package makes http requests to Discord's API. Consider the time it takes to log information to Discord, errors, etc.

This package does not have any kind of rate limiting but Discord does, if you log too much information, it can be ignored by for a while. If the log content has more than 2000 characters, it will be split into multiple messages called "chunks". So, if you have any doubts how Discord handles webhooks, check the Discord documentation.

This package is not meant to replace Sentry, Datadog, etc. It is a simple way to log information to Discord. It is not meant to log sensitive information, as the information is sent to Discord in plain text.

Support

Let me know that you like this package by buying me a coffee!

Contributing

Let me know if you have any ideas to improve this package.

Issues

If you find any issues, please open an issue on the GitHub repository. I will be happy to help you. If you can, please provide a code snippet that reproduces the issue. It will help me to solve it faster.

License

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