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.
Installation
Section titled “Installation”npm install @zumito-team/logger-moduleAdd to your zumito.config.ts:
bundles: ['@zumito-team/logger-module']What it provides
Section titled “What it provides”LogManager Service
Section titled “LogManager Service”The main service accessible via the service container:
import { ServiceContainer } from 'zumito-framework';
const logger = ServiceContainer.getService('LogManager');Methods
Section titled “Methods”| Method | Signature | Description |
|---|---|---|
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. |
LogData types
Section titled “LogData types”The log() method accepts a discriminated union of context-aware log data:
// Bot-level logawait logger.log({ context: 'bot', title: 'Bot started', description: 'The bot has successfully connected to Discord.'});
// Guild-level logawait logger.log({ context: 'guild', guildId: '123456789', channelId: '987654321', title: 'Member joined', description: 'User @example joined the server.'});
// DM logawait logger.log({ context: 'dm', channelId: '987654321', title: 'DM received', description: 'Received a DM from user @example.'});
// Generic logawait logger.log({ context: 'other', title: 'Custom event', description: 'Something happened that does not fit other contexts.'});| Field | Type | Description |
|---|---|---|
context | 'bot' | 'guild' | 'dm' | 'other' | Context category. |
title | string | Short log title. |
description | string | Detailed log description (supports markdown in embeds). |
guildId | string | Discord guild ID (required for guild context). |
channelId | string | Discord channel ID. |
Database models
Section titled “Database models”Each log entry is persisted to the Logs collection:
| Field | Type | Description |
|---|---|---|
title | string | Log title. |
description | string | Log description. |
createdAt | Date | Timestamp of the log entry. |
Guild settings
Section titled “Guild settings”The module extends the Guild model with:
| Field | Type | Description |
|---|---|---|
logChannel | string (optional) | Channel ID where guild logs should be sent. This is where context: 'guild' logs are output. |
Configuration
Section titled “Configuration”Setting a guild log channel
Section titled “Setting a guild log channel”Use the GuildDataGetter service to configure which channel receives guild logs:
const guildData = ServiceContainer.getService('GuildDataGetter');await guildData.set('guildId', 'logChannel', 'channelId');How logging works
Section titled “How logging works”- You call
logger.log(data). - If
contextis'guild':- The guild’s
logChannelsetting is checked. - If a channel is configured, an embed is sent to that channel.
- The guild’s
- The log entry is always persisted to the database.
Extending
Section titled “Extending”Logging from your own module
Section titled “Logging from your own module”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.' }); }}Custom log processing
Section titled “Custom log processing”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); }}Querying logs
Section titled “Querying logs”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});Dependencies
Section titled “Dependencies”ejs— Template rendering.zumito-framework
Related modules
Section titled “Related modules”- Admin Module — Can display logs in the admin dashboard.