1.0.2 • Published 4 months ago
discord-winston-transport v1.0.2
Discord Winston Transport
A robust and enhanced Winston transport for Discord, supporting advanced formatting, printf-style interpolation, error propagation, and updated dependencies.
This library extends the original winston-discord-transport
with additional features and improvements.
Features
- ✅ Printf-style formatting and splat support: Use familiar Winston formatting patterns (
%s
,%d
,%j
) directly in your Discord logs. - ✅ Complete error propagation: Throw and propagate errors properly, ensuring reliable error handling.
- ✅ Color-coded messages: Clearly distinguish log levels with intuitive color coding (errors in red, warnings in yellow, etc.).
- ✅ Custom metadata support: Easily add custom metadata fields to your Discord messages.
- ✅ Updated dependencies: Regularly maintained with up-to-date and secure dependencies.
Installation
npm install discord-winston-transport
# Or using yarn
yarn add discord-winston-transport
# Or using pnpm
pnpm add discord-winston-transport
Usage
Basic Setup
import winston from 'winston';
import DiscordTransport from 'discord-winston-transport';
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.splat(),
winston.format.printf(({ level, message, timestamp }) => `${timestamp} [${level}]: ${message}`),
winston.format.timestamp()
),
transports: [
new DiscordTransport({
webhook: 'https://your.discord.webhook',
defaultMeta: { service: 'my-node-service' },
level: 'warn',
}),
],
});
logger.error('Error initializing service: %s', 'database connection failed');
Logging Errors with Stack Traces
Automatically sends complete error stack traces to Discord:
logger.error('Unhandled exception occurred', { error: new Error('Critical failure') });
Selectively Skip Discord Logging
To prevent specific logs from flooding your Discord channel, set discord: false
:
logger.warn('This warning will not be sent to Discord', { discord: false });
Screenshots
Error Message
Warning Message
Info Message
Verbose Message
Debug Message
Silly Message
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
MIT © Seigneurhol