@ryanforever/discord-logger

3.2.0 • Public • Published

discord-logger

image

log to a discord channel. uses discord webhooks

getting your webhook URL

  1. find the channel you want to log to
  2. click the Edit Channel button
  3. click Integrations in the side panel
  4. click View Webhooks
  5. if you don't already have a webhook dedicated for this logger, click New Webhook
  6. click the Copy Webhook URL button
  7. done! use this URL when in the instance config

usage

const DiscordLogger = require("@ryanforever/discord-logger")
const logger = new DiscordLogger({
	name: "discordLogger", // name your logger, defaults to "logger"
	url: process.env.DISCORD_WEBHOOK_URL, // webhook url
})

logger.log("this is a log")
logger.info("this is info")
logger.warn("this is a warning")
logger.error("this is an error")
logger.debug("this is a debug")

change name of logger on the fly

handy to quickly change the name

// change name via logger.name
logger.name = "boosted"
logger.log("this log will have a new name")
// [log] this log will have a new name

//                ~ or ~

// change name via opts parameter
logger.log("change name via config", {name: "zoinks"})
// [log] change name via config

change style

change how the logger appears in discord

const logger = new DiscordLogger({
	name: "discordLogger",
	url: process.env.DISCORD_WEBHOOK_URL,
	style: "console" // options are "text" "console" or "default"
})

edit a log

pass in the returned log object to logger.edit to edit the log in place

let log = await logger.log("original log")
logger.edit(log,"new log")

delete a log

pass in the returned log object to logger.delete to delete the log

let log = await logger.log("this log will go bye bye")
logger.delete(log)

methods

.log(string, opts)

.info(string, opts)

.warn(string, opts)

.error(string, opts)

.debug(string, opts)

.edit(logObject, string)

.delete(logObject)

Readme

Keywords

Package Sidebar

Install

npm i @ryanforever/discord-logger

Weekly Downloads

9

Version

3.2.0

License

ISC

Unpacked Size

7.92 kB

Total Files

6

Last publish

Collaborators

  • ryanforever