{"id":29895533,"url":"https://github.com/bebancode/commandkit-plugin-custom-logger","last_synced_at":"2025-10-06T09:49:20.401Z","repository":{"id":304691503,"uuid":"1018654225","full_name":"BebanCode/commandkit-plugin-custom-logger","owner":"BebanCode","description":"A CommandKit Runtime Plugin for advanced, file-based, and webhook logging.","archived":false,"fork":false,"pushed_at":"2025-07-14T16:08:43.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-16T11:58:26.950Z","etag":null,"topics":["commandkit","commandkit-plugin","logging","logging-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BebanCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-12T18:23:53.000Z","updated_at":"2025-07-14T16:19:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"fbe55dc9-344c-41ba-8bb8-76f2d48ffcd9","html_url":"https://github.com/BebanCode/commandkit-plugin-custom-logger","commit_stats":null,"previous_names":["bebancode/commandkit-plugin-custom-logger"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/BebanCode/commandkit-plugin-custom-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BebanCode%2Fcommandkit-plugin-custom-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BebanCode%2Fcommandkit-plugin-custom-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BebanCode%2Fcommandkit-plugin-custom-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BebanCode%2Fcommandkit-plugin-custom-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BebanCode","download_url":"https://codeload.github.com/BebanCode/commandkit-plugin-custom-logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BebanCode%2Fcommandkit-plugin-custom-logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278591234,"owners_count":26012027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commandkit","commandkit-plugin","logging","logging-library"],"created_at":"2025-08-01T07:20:34.176Z","updated_at":"2025-10-06T09:49:20.389Z","avatar_url":"https://github.com/BebanCode.png","language":"TypeScript","readme":"# CommandKit Plugin: Custom Logger\n\n[![npm version](https://img.shields.io/npm/v/commandkit-plugin-custom-logger.svg)](https://www.npmjs.com/package/commandkit-plugin-custom-logger)\n\nA powerful, feature-rich logging plugin for [CommandKit](https://commandkit.dev) that offers file logging, log rotation, Discord webhook integration, and highly customizable console output.\n\n## Features\n\n*   **File Logging**: Automatically writes logs to files, organized in daily folders.\n*   **Log Rotation**: Prevents log files from growing indefinitely by automatically rotating them based on size and keeping a configurable number of backups.\n*   **Discord Webhook Integration**: Pushes important logs (like errors and fatals) directly to a Discord channel.\n*   **Customizable Console Output**: Rich, colorful console logging with customizable prefixes, colors, and timestamps.\n*   **CommandKit Integration**: Can seamlessly replace CommandKit's default internal logger to unify all logs in one place.\n*   **Standalone Usage**: Can be used as a standalone logger anywhere in your project.\n*   **Performance-conscious**: Features like caller info logging can be disabled to maximize performance.\n\n## Installation\n\n```bash\nnpm install commandkit-plugin-custom-logger\n```\n\n## Quick Start\n\nTo get started, register the plugin in your `commandkit.config.ts` file.\n\n```ts\nimport { defineConfig } from 'commandkit';\nimport { LoggerPlugin } from 'commandkit-plugin-custom-logger'; \n\nexport default defineConfig({\n  plugins: [\n    new LoggerPlugin(), // Use default settings\n  ],\n});\n```\n\nThis is the simplest setup and will enable console logging and file logging to the `./logs` directory.\n\n## Using the Logger\n\nAfter initialization, you can import and use the logger functions anywhere in your project.\n\n**File:** `/src/commands/myCommand.js`\n```javascript\nimport { SlashCommandBuilder } from 'discord.js';\nimport { info, error, warn } from 'commandkit-plugin-logger'; // Adjust the import path\n\nexport const data = new SlashCommandBuilder()\n  .setName('my-command')\n  .setDescription('An example command.');\n\nexport const chatInput = async (ctx) =\u003e {\n  const { interaction } = ctx;\n\n  info(`User ${interaction.user.tag} ran the command.`);\n\n  try {\n    // Some logic that might fail\n    if (Math.random() \u003e 0.5) {\n      throw new Error('Something went wrong!');\n    }\n    await interaction.reply('Command executed successfully!');\n  } catch (e) {\n    error('An error occurred in my-command:', e);\n    warn('This error was handled gracefully.');\n    await interaction.reply({\n      content: 'An error occurred, but it has been logged.',\n      ephemeral: true\n    });\n  }\n}\n```\n\n## Configuration\n\nYou can customize the logger by passing an options object to the `LoggerPlugin` constructor.\n\n### Example Configuration\n\n```ts\nimport { defineConfig } from 'commandkit';\nimport { LoggerPlugin } from 'commandkit-plugin-logger';\n\nexport default defineConfig({\n  plugins: [\n    new LoggerPlugin({\n      // Send ERROR and FATAL logs to a Discord channel\n      webhookUrl: 'https://discord.com/api/webhooks/...',\n      webhookLogLevels: ['error', 'fatal'],\n\n      // Set console to only show INFO level and above\n      consoleLogLevel: 'info',\n\n      // Keep more log files\n      maxFileSizeMB: 20,\n      maxRotatedFiles: 10,\n\n      // Enable caller info for debugging\n      includeCallerInfo: true,\n    }),\n  ],\n});\n```\n\n### All Options\n\n| Option | Type | Description | Default |\n| :--- | :--- | :--- | :--- |\n| `logDirectory` | `string` | The directory where log files will be stored. | `'./logs'` |\n| `logFileName` | `string` | The base name for the log files. | `'app.log'` |\n| `maxFileSizeMB` | `number` | The maximum size of a log file in MB before it is rotated. | `10` |\n| `maxRotatedFiles` | `number` | The maximum number of rotated log files to keep. | `5` |\n| `dateFormat` | `string` | The [Moment.js](https://momentjs.com/docs/#/displaying/format/) format for daily log folder names. | `'YYYY-MM-DD'` |\n| `timestampFormat` | `string` | The Moment.js format for timestamps in log entries. | `'YYYY-MM-DD HH:mm:ss.SSS'` |\n| `consoleLogLevel` | `LogLevel` | Minimum log level for the console (`debug`, `info`, `warn`, etc.). | `'debug'` |\n| `fileLogLevel` | `LogLevel` | Minimum log level for the log file. | `'debug'` |\n| `webhookUrl` | `string \\| null` | The URL of the Discord webhook to send logs to. | `null` |\n| `webhookLogLevels`| `LogLevel[]` | An array of log levels that should trigger a webhook message. | `['error', 'fatal']` |\n| `includeCallerInfo` | `boolean` | Includes the caller's file path and line number in logs. **Can impact performance.** | `false` |\n| `replaceCommandKitLogger` | `boolean` | Replaces CommandKit's internal logger with this one to unify logs. | `true` |\n| `commandKitLogPrefix` | `string` | The prefix to use for logs originating from CommandKit's internal logger. | `'[CK]'` |\n| `colors` | `object` | Custom color mappings for log levels in the console. | (See defaults) |\n| `prefixes` | `object` | Custom prefix strings for log levels. | (See defaults) |\n\n## API Reference\n\nThe plugin exports several functions for direct use:\n\n*   `info(...args: any[]): void`\n*   `warn(...args: any[]): void`\n*   `error(...args: any[]): void`\n*   `debug(...args: any[]): void`\n*   `fatal(...args: any[]): void`\n*   `success(...args: any[]): void`\n*   `log(level: string, ...args: any[]): void` - Logs with a dynamic level.\n*   `closeLogger(): Promise\u003cvoid\u003e` - Gracefully closes file streams and webhook clients.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbebancode%2Fcommandkit-plugin-custom-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbebancode%2Fcommandkit-plugin-custom-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbebancode%2Fcommandkit-plugin-custom-logger/lists"}