https://github.com/seipan/loghook
⚡ logger to notify logs to slack,discord using webhook ⚡
https://github.com/seipan/loghook
discord go golang logger slack webhook
Last synced: 2 months ago
JSON representation
⚡ logger to notify logs to slack,discord using webhook ⚡
- Host: GitHub
- URL: https://github.com/seipan/loghook
- Owner: seipan
- License: mit
- Created: 2023-06-20T09:39:37.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-16T09:30:50.000Z (3 months ago)
- Last Synced: 2025-04-18T20:44:28.533Z (3 months ago)
- Topics: discord, go, golang, logger, slack, webhook
- Language: Go
- Homepage:
- Size: 142 KB
- Stars: 21
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README




[](https://github.com/seipan/loghook/actions/workflows/go.yml)
[](https://codecov.io/gh/seipan/loghook)
# loghook
⚡ logger to notify logs to slack,discord using webhook ⚡
## Installation
```
go get github.com/seipan/loghook
```## Usage
When using it, you need to obtain the default webhook for discord and the incoming webhook for slack in advance.
```go
package discordimport "github.com/seipan/loghook"
var (
// DiscordWebhookURL is a webhook url for discord.
DiscordWebhookURL = "https://discord.com/api/webhooks/xxxxxxxx/xxxxxxxx"
)func main() {
logger := loghook.NewLogger("", "test", "discord", DiscordWebhookURL)
logger.SetLevel(loghook.DebugLevel)
logger.SetWebhook(DiscordWebhookURL)logger.Debug("test")
logger.Infof("test %s", "info")
}
```If you do not want to be notified of a particular log level, you can set
```go
package discordimport "github.com/seipan/loghook"
var (
// DiscordWebhookURL is a webhook url for discord.
DiscordWebhookURL = "https://discord.com/api/webhooks/xxxxxxxx/xxxxxxxx"
)func main(){
logger := loghook.NewLogger("", "test", "discord", DiscordWebhookURL)logger.NoSendDebug()
logger.Debug("test")
logger.NoSendInfo()
logger.Infof("test %s", "info")
}
```
You can also change the webhook to be notified for each log level
```go
package discordimport "github.com/seipan/loghook"
var (
// DiscordWebhookURL is a webhook url for discord.
DiscordWebhookURL = "https://discord.com/api/webhooks/xxxxxxxx/xxxxxxxx"
)func main(){
logger := loghook.NewLogger("", "test", "discord", DiscordWebhookURL)logger.SetErrorWebhook(DiscordErrorWebhookURL)
logger.Error("test")
}
```
There is also a method that takes 'context' as an argument
```go
package discordimport "github.com/seipan/loghook"
var (
// DiscordWebhookURL is a webhook url for discord.
DiscordWebhookURL = "https://discord.com/api/webhooks/xxxxxxxx/xxxxxxxx"
)func main(){
logger := loghook.NewLogger("", "test", "discord", DiscordWebhookURL)logger.ErrorContext("test")
}
```
If you want a more detailed example, please see the [examples](https://github.com/seipan/loghook/blob/main/example).
## License
Code licensed under
[the MIT License](https://github.com/seipan/loghook/blob/main/LICENSE).## Author
[seipan](https://github.com/seipan).## Star History
[](https://star-history.com/#seipan/loghook&Date)