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

drpg-logger

v2.0.6

Published

Pretty logging for Discord.JS

Downloads

83

Readme

DRPG Logger

Pretty logging for Discord.JS

image

image

What is DRPG Logger?

DRPG Logger is an advanced console and channel logging package for bots created with Discord.JS. With this package, you can quickly print nicely formatted logs to your console, as well as to any discord Channel.

On top of formatting the logs, any Discord User, Member, or Channel will also be displayed in the console in a nice and easy to read manner (including display name and ID). This is done by default when a User, GuildMember, or Channel is supplied - which when included in a string forms a pattern such as <@12345678912345678>.

NOTE Currently, this package only supports a single log channel. If your bot is a multi-guild bot (as most are), a log channel per guild is currently not supported.

Install

Run npm install drpg-logger

Usage

  1. Import the module
import { Logger, LogLevel } from "drpg-logger";
  1. Provide your config in the constructor and access desired functions
import { Client } from "discord.js";
import { Logger, LogLevel } from "drpg-logger";

const client = new Client({}); // However you are creating your discord Client - this is up to you

const logChannelId = process.env.LOG_CHANNEL_ID; // However you decide to provide the log channel. Suggested via environment variables.
const logger = new Logger(client, { defaultLogChannel: logChannelId, dateDisplayTimezone: "+1000" });

client.once("ready", () => {
	logger.info("Bot has started!", "Bot Running");
});

client.login(token);
  1. Once initialized, you can use Logger to access all of it's static methods.
client.on('interactionCreate', interaction => {
    Logger.debug(`${interaction.user} did some interaction in ${interaction.channel}`,"Interaction", interaction.message);
});

Suggestions

  • For easy and repeated use, it is suggested that your instance of logger is exported, so that you can use the same instance throughout.
  • This package makes heavy use of the colorette library. You can use this library with the content properties, to further enhance the display of your logs.

Default Log Types

By default, a number of log types are included. All of these can be quickly used by calling Logger.trace, Logger.info, Logger.warn and so on.

  • trace (Priority 10)
  • debug (Priority 20)
  • info (Priority 30)
  • warn (Priority 40)
  • error (Priority 50)
  • fatal (Priority 60)

Configuration

All configuration is done via the ILoggerOptions, which is passed in at the time of creation.

  • defaultLogChannel Required. The Channel that will be used for sending Log embeds.
  • allowEmbedLevel Optional. Defaults to 30. Each LogType has a Priority. If a new log has less than this level of priority, the Embed will not be sent.
  • allowLogLevel Optional. Defaults to 10. Each LogType has a priority. If a new log has less than this level of priority, the console log will not be sent.
  • dateDisplayTimezone Optional. Defaults to 0. Must be procided as a UTC Offset ie +1030 for UTC+10:30. Will change the date used for logging.
  • dateFormat Optional. Defaults to YYYY-MM-DD HH:mm:ss. Will be included in all console logs.