{"id":28364582,"url":"https://github.com/bufferoverflovv/slog-discord","last_synced_at":"2025-10-13T00:27:33.463Z","repository":{"id":272582315,"uuid":"915647789","full_name":"Bufferoverflovv/slog-discord","owner":"Bufferoverflovv","description":"A discord handler for slog","archived":false,"fork":false,"pushed_at":"2025-01-16T01:09:39.000Z","size":232,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-13T00:27:33.001Z","etag":null,"topics":["discord","go","golang","http","log","middleware","notifications","slog"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/Bufferoverflovv/slog-discord","language":"Go","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/Bufferoverflovv.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-01-12T12:41:49.000Z","updated_at":"2025-01-16T01:09:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"c2833e99-449d-4512-9dea-e8905d58c658","html_url":"https://github.com/Bufferoverflovv/slog-discord","commit_stats":null,"previous_names":["bufferoverflovv/slog-discord"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Bufferoverflovv/slog-discord","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bufferoverflovv%2Fslog-discord","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bufferoverflovv%2Fslog-discord/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bufferoverflovv%2Fslog-discord/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bufferoverflovv%2Fslog-discord/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bufferoverflovv","download_url":"https://codeload.github.com/Bufferoverflovv/slog-discord/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bufferoverflovv%2Fslog-discord/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013633,"owners_count":26085298,"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-12T02:00:06.719Z","response_time":53,"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":["discord","go","golang","http","log","middleware","notifications","slog"],"created_at":"2025-05-28T21:08:14.588Z","updated_at":"2025-10-13T00:27:33.447Z","avatar_url":"https://github.com/Bufferoverflovv.png","language":"Go","readme":"# Slog Discord Handler\n\n[![GitHub Tag](https://img.shields.io/github/v/tag/Bufferoverflovv/slog-discord)](https://github.com/Bufferoverflovv/slog-discord/releases)\n![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)\n[![GoDoc](https://godoc.org/github.com/Bufferoverflovv/slog-discord?status.svg)](https://pkg.go.dev/github.com/Bufferoverflovv/slog-discord)\n[![Go Report Card](https://goreportcard.com/badge/github.com/Bufferoverflovv/slog-discord)](https://goreportcard.com/report/github.com/Bufferoverflovv/slog-discord)\n[![GitHub License](https://img.shields.io/github/license/Bufferoverflovv/slog-discord)](./LICENSE)\n\nA custom [slog](https://pkg.go.dev/log/slog) handler for [Discord](https://discord.com) that can send structured logs directly to Discord using a webhook. It converts a log into a Discord Embed with optional customisation.\n\n![Screenshot of a Discord embed with log details](./images/example.png)\n\n## ⭐️ Features\n- **Flexible Embeds** – You can customise the embed title, description, colours, footers, etc.\n- **Log Level Colours** – Configure distinct colours for INFO, WARN, ERROR, etc.\n- **Structured** – Embrace key-value pairs, grouping, and other slog superpowers in your logs.\n\n## 🚀 Install\n```\ngo get github.com/Bufferoverflovv/slog-discord\n```\n*Compatible with go versions \u003e= 1.21*\n\n## 🪵 Usage\n### Requirements \nCreate a discord [webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) in the channel you want to log notifications to be sent to\n### Configuration \n`DiscordWebhookConfig` configures how logs are sent to discord\n```go\ntype DiscordWebhookConfig struct {\n    MinLevel slog.Level // Set the minimum slog level (Default: Debug) : Optional\n    Timeout time.Duration // Set the timeout (Default: 5 Seconds) : Optional\n    WebhookURL string // The webhook URL from discord \n    Username string // Set a custom username : Optional\n    AvatarURL string  // Set a custom avatar : Optional\n    LevelColors LevelColors // Customise the colours for each slog level : Optional\n    CustomEmbed CustomEmbed  // Customise the embed content : Optional\n}\n```\n### Basic Setup (Default Embed)\nBy default you do not need to add any customisations and can simply get going by creating a `NewDiscordHandler` \n```go\npackage main\n\nimport (\n    \"log/slog\"\n\n    slogdiscord \"github.com/Bufferoverflovv/slog-discord\"\n)\n\nconst (\n    WebhookURL string = \"DISCORD WEBHOOK URL HERE\"\n)\n\nfunc main() {\n    default_example()\n}\n\nfunc default_example() {\n    // 1) Configure how you want your Discord logs to look\n    cfg := slogdiscord.DiscordWebhookConfig{\n        WebhookURL: WebhookURL,\n    }\n\n    // 2) Create your Discord handler\n    discordHandler := slogdiscord.NewDiscordHandler(cfg)\n\n    // 3) Create a slog.Logger\n    logger := slog.New(discordHandler)\n\n    // 4) Log away!\n    logger.Info(\"Hello from Info\", \"version\", \"1.2.3\")\n    logger.Warn(\"Watch out, memory usage is high\", \"usage\", \"85%\")\n    logger.Error(\"Oh no, database connection failed\", \"error\", \"timeout\")\n}\n```\n### Custom Embed \nIf you want to customise the embed (like changing the title, description, or footers), provide your own function. For example:\n```go\nfunc custom_example() {\n    // 1) Configure how you want your Discord logs to look\n    cfg := slogdiscord.DiscordWebhookConfig{\n        MinLevel: slog.LevelDebug,\n        Timeout: 5 * time.Second,\n        WebhookURL: WebhookURL,\n        Username: \"Slog Notifications\",\n        LevelColors: slogdiscord.LevelColors{\n            \"DEBUG\": 0x95a5a6, // Gray\n            \"INFO\": 0x3498db, // Blue\n            \"WARN\": 0xf1c40f, // Yellow\n            \"ERROR\": 0xe74c3c, // Red\n        },\n        // Optional custom embed function. If omitted, a default is used.\n        CustomEmbed: func(r slog.Record, lc slogdiscord.LevelColors) *slogdiscord.DiscordEmbed {\n            // custom formatting\n            return \u0026slogdiscord.DiscordEmbed{\n                Title: fmt.Sprintf(\"Custom title: %s\", r.Level.String()),\n                Description: fmt.Sprintf(\"Custom description: %s\", r.Message),\n                Color: lc[r.Level.String()],\n                Timestamp: time.Now().Format(time.RFC3339),\n                Fields: []slogdiscord.EmbedField{\n                    {\n                    Name: \"Custom Field\",\n                    Value: \"Custom Value\",\n                    Inline: true,\n                    },\n                },\n                Footer: \u0026slogdiscord.EmbedFooter{\n                    Text: \"Custom Footer\",\n                },\n            }\n        },\n    }\n\n    // 3) Create your Discord handler\n    discordHandler := slogdiscord.NewDiscordHandler(cfg)\n        \n    // 4) Create a slog.Logger\n    logger := slog.New(discordHandler)\n\n    // 5) Log away!\n    logger.Info(\"Hello from Info\", \"version\", \"1.2.3\")\n    logger.Warn(\"Watch out, memory usage is high\", \"usage\", \"85%\")\n    logger.Error(\"Oh no, database connection failed\", \"error\", \"timeout\")\n}\n```\n\n### Structured Logging\nslog supports structured logging with **attributes** (key-value pairs) and **grouping**. These show up as fields in your Discord embed.\n\n**WithAttrs**\nWithAttrs sets up **global** attributes applied to each subsequent log:\n```go\nlogger := slog.New(slogdiscord.NewDiscordHandler(cfg)).\n    WithAttrs([]slog.Attr{\n        slog.String(\"env\", \"production\"),\n        slog.Int(\"version\", 2),\n    })\n\n// Now all logs will carry env=production and version=2\nlogger.Info(\"Server started!\")\n```\n\n**WithGroup**\nWithGroup logically groups attributes under a named “folder”:\n```go\nlogger := slog.New(slogdiscord.NewDiscordHandler(cfg)).\n    WithGroup(\"request\").\n    WithAttrs([]slog.Attr{\n        slog.Int(\"id\", 42),\n        slog.String(\"user\", \"Jordan\"),\n    })\n\n// In a structured format, these might nest under \"request.id\", \"request.user\"\n// For the embed fields, they just appear as separate fields, but you could\n// alter the embed logic to visually reflect grouping if you want.\nlogger.Info(\"Handling user request\")\n```\n\n## 📝 Examples \nCheck out the [examples](./examples) folder for:\n• **Basic example**: Logs to Discord only.\n• **Custom embed**: Showcases how to override the default embed.\n\n## ❓FAQ\n1. **What if I need to also log locally?**\n\t- You can create a “multi-handler” approach (one logs to Discord, the other logs locally) if you **combine** them, or you can build a single handler that calls a “next” local handler. Either way, you do not have to limit yourself to only Discord.\n2. **How do I prevent spamming Discord?**\n\t- You can implement rate limiting or batching. For heavy logs, consider sending only WARN or ERROR to Discord.\n3. **Do I need a connection pool?**\n\t- Probably not. HTTP is stateless, and the Go http.Client already manages keep-alives. Discord also enforces rate limits, so a pool wouldn’t help much.\n5. **What if I get a** `nil pointer dereference`**?**\n\t- Make sure your handler references are properly set. \n1. **I keep seeing “400 Bad Request” or \"429 Rate Limit Exceeded\"!**\n\t- Double-check your webhook URL, or confirm that you’re not violating any Discord request size/rate limit.\n## ❤️ License and Contributions\nThis project is licensed under the [MIT License](LICENSE). You’re free to use, modify, and distribute it.\n\nYou are more than welcome to  contribute if you see room for improvement—**PRs are always welcome**\n\n---\n**Enjoy sending your logs in style to Discord!** If you need help or want a new feature, open an issue or drop a PR!","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufferoverflovv%2Fslog-discord","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbufferoverflovv%2Fslog-discord","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufferoverflovv%2Fslog-discord/lists"}