discord-starboard-plus
Version:
Discord Starboard Plus: A clean, maintainable starboard system for Discord.js bots. Features per-guild configuration, TypeScript support. Highlight your community's favorite messages with customizable starboards.
70 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
/**
* Structured logger for the Starboard system.
* Provides consistent logging with timestamps, prefixes, and context.
*/
class Logger {
enabled;
prefix;
constructor(options = {}) {
this.enabled = options.enabled !== false;
this.prefix = options.prefix ?? 'Starboard';
}
/**
* Log an informational message
*/
info(message, context = {}) {
this.log('INFO', '\u2139\ufe0f', message, context);
}
/**
* Log a success message
*/
success(message, context = {}) {
this.log('SUCCESS', '\u2705', message, context);
}
/**
* Log a warning message
*/
warn(message, context = {}) {
this.log('WARN', '\u26a0\ufe0f', message, context);
}
/**
* Log an error message with optional Error object
*/
error(message, error = null, context = {}) {
const errorContext = { ...context };
if (error) {
errorContext.error = error.message;
if (error.stack) {
errorContext.stack = error.stack.split('\n')[1]?.trim();
}
}
this.log('ERROR', '\u274c', message, errorContext);
}
/**
* Internal logging method
*/
log(_level, emoji, message, context) {
if (!this.enabled)
return;
const timestamp = new Date().toISOString();
const contextStr = this.formatContext(context);
console.log(`[${timestamp}] [${this.prefix}] ${emoji} ${message}${contextStr}`);
}
/**
* Format context object as string
*/
formatContext(context) {
const entries = Object.entries(context).filter(([, v]) => v !== undefined);
if (entries.length === 0)
return '';
const formatted = entries
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
.join(' ');
return ` { ${formatted} }`;
}
}
exports.Logger = Logger;
//# sourceMappingURL=Logger.js.map