Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 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 (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-17T14:46:23.000Z (5 months ago)
- Last Synced: 2024-09-17T18:30:31.401Z (5 months ago)
- Topics: discord, go, golang, logger, slack, webhook
- Language: Go
- Homepage:
- Size: 140 KB
- Stars: 19
- 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)