Skip to content

Logger Module

The Logger Module (@zumito-team/logger-module) provides a centralized logging system. It can output logs to configured Discord channels (as embeds) and persist them to the database for later querying.

Terminal window
npm install @zumito-team/logger-module

Add to your zumito.config.ts:

bundles: ['@zumito-team/logger-module']

The main service accessible via the service container:

import { ServiceContainer } from 'zumito-framework';
const logger = ServiceContainer.getService('LogManager');
MethodSignatureDescription
log(data)(data: LogData): Promise<void>Log an event. Outputs to Discord channel (if configured) and persists to database.
logToChannel(channel, log)(channel, log: LogData): Promise<void>Sends a Discord embed to a specific channel with the log’s title and description.

The log() method accepts a discriminated union of context-aware log data:

// Bot-level log
await logger.log({
context: 'bot',
title: 'Bot started',
description: 'The bot has successfully connected to Discord.'
});
// Guild-level log
await logger.log({
context: 'guild',
guildId: '123456789',
channelId: '987654321',
title: 'Member joined',
description: 'User @example joined the server.'
});
// DM log
await logger.log({
context: 'dm',
channelId: '987654321',
title: 'DM received',
description: 'Received a DM from user @example.'
});
// Generic log
await logger.log({
context: 'other',
title: 'Custom event',
description: 'Something happened that does not fit other contexts.'
});
FieldTypeDescription
context'bot' | 'guild' | 'dm' | 'other'Context category.
titlestringShort log title.
descriptionstringDetailed log description (supports markdown in embeds).
guildIdstringDiscord guild ID (required for guild context).
channelIdstringDiscord channel ID.

Each log entry is persisted to the Logs collection:

FieldTypeDescription
titlestringLog title.
descriptionstringLog description.
createdAtDateTimestamp of the log entry.

The module extends the Guild model with:

FieldTypeDescription
logChannelstring (optional)Channel ID where guild logs should be sent. This is where context: 'guild' logs are output.

Use the GuildDataGetter service to configure which channel receives guild logs:

const guildData = ServiceContainer.getService('GuildDataGetter');
await guildData.set('guildId', 'logChannel', 'channelId');
  1. You call logger.log(data).
  2. If context is 'guild':
    • The guild’s logChannel setting is checked.
    • If a channel is configured, an embed is sent to that channel.
  3. The log entry is always persisted to the database.

Any module can consume the LogManager service:

import { Module, ServiceContainer } from 'zumito-framework';
class MyModule extends Module {
async onReady() {
const logger = ServiceContainer.getService('LogManager');
await logger.log({
context: 'bot',
title: 'MyModule ready',
description: 'MyModule has been initialized successfully.'
});
}
}

The LogManager is a standard service. You can extend or wrap it:

class EnhancedLogManager extends LogManager {
async log(data: LogData) {
// Add custom logic before logging
if (data.context === 'guild') {
// Send to a webhook too
await fetch(webhookUrl, { method: 'POST', body: JSON.stringify(data) });
}
return super.log(data);
}
}

Since logs are stored in the database, you can query them for dashboards or analytics:

import { DatabaseModel } from 'zumito-framework';
const LogsModel = new DatabaseModel('Logs');
const recentErrors = await LogsModel.findMany({
filter: { title: { $regex: /error/i } },
sort: { createdAt: -1 },
limit: 10
});
  • ejs — Template rendering.
  • zumito-framework