A custom winston transport for Discord.
This library serves as a Transport
for winston, a popular Nodejs logging library.
$ npm i winston-discord-transport
import winston from "winston";
import DiscordTransport from "winston-discord-transport";
const logger = winston.createLogger({
transports: [
new DiscordTransport({
webhook: "https:/your/discord/webhook",
defaultMeta: { service: "my_node_service" },
level: "warn"
})
]
});
logger.log({
level: "error",
message: "Error intializing service",
error: new Error()
});
There might be some log messages which you might want to raise to a file or console, but not flood your Discord channel.
For such message, just include discord: false
as a key-value in the log message and the transport will drop the message from being sent to Discord.
logger.log({
level: "warn",
message: "Some warning message to not send to discord",
discord: false
});