@ryanforever/discord-logger
v3.2.0
Published
a utility to send logs to a discord channel using webhooks
Downloads
26
Readme
discord-logger
log to a discord channel. uses discord webhooks
getting your webhook URL
- find the channel you want to log to
- click the
Edit Channel
button - click
Integrations
in the side panel - click
View Webhooks
- if you don't already have a webhook dedicated for this logger, click
New Webhook
- click the
Copy Webhook URL
button - 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)