Skip to content

Commit

Permalink
update to latest disgo
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Sep 28, 2021
1 parent daa46e8 commit 8a326fd
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 243 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ updates:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: gomod
directory: "/examples/factory_example"
directory: "/_examples/webhook_client_example"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: gomod
directory: "/examples/builder_example"
directory: "/_examples/id_token_example"
schedule:
interval: daily
open-pull-requests-limit: 10
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Go Version](https://img.shields.io/github/go-mod/go-version/DisgoOrg/dislog)](https://golang.org/doc/devel/release.html)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/DisgoOrg/dislog/blob/master/LICENSE)
[![Disgo Version](https://img.shields.io/github/v/release/DisgoOrg/dislog)](https://github.com/DisgoOrg/dislog/releases/latest)
[![Disgo Discord](https://img.shields.io/badge/Disgo%20Discord-blue.svg)](https://discord.gg/zQ4u3CdU3J)
[![Disgo Discord](https://img.shields.io/badge/Disgo%20Discord-blue.svg)](https://discord.gg/mgjJeufk)

dislog is a [logrus](https://github.com/sirupsen/logrus) [logging hook](https://github.com/sirupsen/logrus#hooks) sending logs over [Discord Webhooks](https://discord.com/developers/docs/resources/webhook) using the [disgohook](https://github.com/DisgoOrg/dislog) library

Expand All @@ -25,39 +25,41 @@ Import the package into your project.
import "github.com/DisgoOrg/dislog"
```

Create a new [logrus](https://github.com/sirupsen/logrus) logger then create a new dislog instance by passing a http.Client(*pass nil for default client*), the `logrus.Loglevel` for the underlying webhook and webhook token `webhook_id/webhook_token`.
Create a new [logrus](https://github.com/sirupsen/logrus) logger then create a new dislog instance by providing the webhook id and webhook token.

```go
logger := logrus.New()
dlog, err := dislog.NewDisLogByToken(nil, logrus.InfoLevel, os.Getenv("webhook_token"), dislog.TraceLevelAndAbove...)
dlog, err := dislog.New(
// Sets which logging levels to send to the webhook
dislog.WithLogLevels(dislog.TraceLevelAndAbove...),
// Sets webhook id & token
dislog.WithWebhookIDToken(webhookID, webhookToken),
)
if err != nil {
logger.Errorf("error initializing dislog %s", err)
return
logger.Fatal("error initializing dislog: ", err)
}
defer dlog.Close()
logger.AddHook(dlog)
```

Builder example can be found [here](https://github.com/DisgoOrg/dislog/tree/master/examples/builder_example/builder_example.go)

## Documentation

Documentation is unfinished and can be found under
Documentation can be found here

* [![Go Reference](https://pkg.go.dev/badge/github.com/DisgoOrg/dislog.svg)](https://pkg.go.dev/github.com/DisgoOrg/dislog)
* [![logrus Hooks Documentation](https://img.shields.io/badge/logrus%20Documentation-blue.svg)](https://github.com/sirupsen/logrus#hooks)

## Examples

You can find examples [here](https://github.com/DisgoOrg/dislog/tree/master/examples)
You can find examples [here](https://github.com/DisgoOrg/dislog/tree/master/_examples)

## Troubleshooting

For help feel free to open an issues or reach out on [Discord](https://discord.gg/zQ4u3CdU3J)
For help feel free to open an issues or reach out on [Discord](https://discord.gg/mgjJeufk)

## Contributing

Contributions are welcomed but for bigger changes please first reach out via [Discord](https://discord.gg/zQ4u3CdU3J) or create an issue to discuss your intentions and ideas.
Contributions are welcomed but for bigger changes please first reach out via [Discord](https://discord.gg/mgjJeufk) or create an issue to discuss your intentions and ideas.

## License

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package main

import (
"github.com/DisgoOrg/disgo/discord"
"os"
"time"

"github.com/DisgoOrg/dislog"
"github.com/sirupsen/logrus"
)

var webhookToken = os.Getenv("webhook_token")
var (
webhookID = discord.Snowflake(os.Getenv("webhook_id"))
webhookToken = os.Getenv("webhook_token")

var logger = logrus.New()
logger = logrus.New()
)

func main() {
// override default trace color
Expand All @@ -23,8 +27,14 @@ func main() {
dislog.TimeFormatter = "2006-01-02 15:04:05 Z07"

logger.SetLevel(logrus.TraceLevel)
logger.Info("starting examples...")
dlog, err := dislog.NewDisLogByToken(nil, logrus.InfoLevel, webhookToken, dislog.TraceLevelAndAbove...)
logger.Info("starting example...")

dlog, err := dislog.New(
// Sets which logging levels to send to the webhook
dislog.WithLogLevels(dislog.TraceLevelAndAbove...),
// Sets webhook id & token
dislog.WithWebhookIDToken(webhookID, webhookToken),
)
if err != nil {
logger.Errorf("error initializing dislog %s", err)
return
Expand Down
20 changes: 20 additions & 0 deletions _examples/id_token_example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/DisgoOrg/dislog/_examples/id_token_example

go 1.17

replace github.com/DisgoOrg/dislog => ../../

require (
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc
github.com/DisgoOrg/dislog v1.0.2
github.com/sirupsen/logrus v1.8.1
)

require (
github.com/DisgoOrg/log v1.1.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
)
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
github.com/DisgoOrg/disgohook v1.4.3 h1:JtZiV0jAku9NZRYD6wVH7tWY1617rh4tRqn4ihTUJRc=
github.com/DisgoOrg/disgohook v1.4.3/go.mod h1:aHNyBHq1pBbdWrkCq3ZCSBeavUoGWZAAT4+609EcrvU=
github.com/DisgoOrg/log v1.1.0 h1:a6hLfVSDuTFJc5AKQ8FDYQ5TASnwk3tciUyXThm1CR4=
github.com/DisgoOrg/log v1.1.0/go.mod h1:Qihgz6fax3JCfuO7vxVavL0LyHS0sUdQ9OmykQ2fiQs=
github.com/DisgoOrg/restclient v1.2.7 h1:A8ltFP+8O2q9ZTk/vRmlQRvH2cbcnaacUV2uXWFcONQ=
github.com/DisgoOrg/restclient v1.2.7/go.mod h1:2pc/htya/5kjxvWNYya98sb8B4mexobxmWvhTiWPt94=
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc h1:+fxaZZRmwgFRJu+SG2mkhEMXc/pcBBsSL8JmkjYdCIo=
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc/go.mod h1:fUybH2+qCyaMbv2Zmwlm8OVU9o6ooT3mzgYLZ6R3meM=
github.com/DisgoOrg/log v1.1.2 h1:tGJS4jaH1PyjPRHybHp8WpYJ/4fR3fYWT4Mv1PoDGBM=
github.com/DisgoOrg/log v1.1.2/go.mod h1:tSMofXaNhQNvzLRoL4tAiCG9yGY1ES5DLvduh7e9GRU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"github.com/DisgoOrg/disgo/discord"
"github.com/DisgoOrg/disgo/rest"
"github.com/DisgoOrg/disgo/webhook"
"net/http"
"os"
"time"
Expand All @@ -9,10 +12,13 @@ import (
"github.com/sirupsen/logrus"
)

var webhookToken = os.Getenv("webhook_token")
var (
webhookID = discord.Snowflake(os.Getenv("webhook_id"))
webhookToken = os.Getenv("webhook_token")

var logger = logrus.New()
var httpClient = http.DefaultClient
logger = logrus.New()
httpClient = http.DefaultClient
)

func main() {
// override default trace color
Expand All @@ -25,16 +31,14 @@ func main() {
dislog.TimeFormatter = "2006-01-02 15:04:05 Z07"

logger.SetLevel(logrus.TraceLevel)
logger.Info("starting examples...")
dlog, err := dislog.NewDisLogBuilder().
// Sets which logrus.LogLevel the webhook client should log at if none is passed
SetWebhookLoglevel(logrus.ErrorLevel).
SetWebhookIDToken(webhookToken).
// Sets a custom http client or nil for inbuilt
SetHttpClient(httpClient).
logger.Info("starting example...")

dlog, err := dislog.New(
// Sets which logging levels to send to the webhook
SetLevels(dislog.TraceLevelAndAbove...).
Build()
dislog.WithLogLevels(dislog.TraceLevelAndAbove...),
// Sets a custom http client or nil for inbuilt
dislog.WithWebhookClient(webhook.NewClient(webhookID, webhookToken, webhook.WithRestClientConfigOpts(rest.WithHTTPClient(httpClient)))),
)
if err != nil {
logger.Errorf("error initializing dislog %s", err)
return
Expand Down
20 changes: 20 additions & 0 deletions _examples/webhook_client_example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/DisgoOrg/dislog/_examples/webhook_client_example

go 1.17

replace github.com/DisgoOrg/dislog => ../../

require (
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc
github.com/DisgoOrg/dislog v1.0.2
github.com/sirupsen/logrus v1.8.1
)

require (
github.com/DisgoOrg/log v1.1.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
)
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
github.com/DisgoOrg/disgohook v1.4.3 h1:JtZiV0jAku9NZRYD6wVH7tWY1617rh4tRqn4ihTUJRc=
github.com/DisgoOrg/disgohook v1.4.3/go.mod h1:aHNyBHq1pBbdWrkCq3ZCSBeavUoGWZAAT4+609EcrvU=
github.com/DisgoOrg/log v1.1.0 h1:a6hLfVSDuTFJc5AKQ8FDYQ5TASnwk3tciUyXThm1CR4=
github.com/DisgoOrg/log v1.1.0/go.mod h1:Qihgz6fax3JCfuO7vxVavL0LyHS0sUdQ9OmykQ2fiQs=
github.com/DisgoOrg/restclient v1.2.7 h1:A8ltFP+8O2q9ZTk/vRmlQRvH2cbcnaacUV2uXWFcONQ=
github.com/DisgoOrg/restclient v1.2.7/go.mod h1:2pc/htya/5kjxvWNYya98sb8B4mexobxmWvhTiWPt94=
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc h1:+fxaZZRmwgFRJu+SG2mkhEMXc/pcBBsSL8JmkjYdCIo=
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc/go.mod h1:fUybH2+qCyaMbv2Zmwlm8OVU9o6ooT3mzgYLZ6R3meM=
github.com/DisgoOrg/log v1.1.2 h1:tGJS4jaH1PyjPRHybHp8WpYJ/4fR3fYWT4Mv1PoDGBM=
github.com/DisgoOrg/log v1.1.2/go.mod h1:tSMofXaNhQNvzLRoL4tAiCG9yGY1ES5DLvduh7e9GRU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE=
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
54 changes: 54 additions & 0 deletions config_opts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dislog

import (
"github.com/DisgoOrg/disgo/discord"
"github.com/DisgoOrg/disgo/webhook"
"github.com/DisgoOrg/log"
"github.com/sirupsen/logrus"
)

var DefaultConfig = Config{
Logger: log.Default(),
LogLevels: ErrorLevelAndAbove,
}

type Config struct {
Logger log.Logger
LogLevels []logrus.Level
WebhookID discord.Snowflake
WebhookToken string
WebhookClient *webhook.Client
}

type ConfigOpt func(config *Config)

func (c *Config) Apply(opts []ConfigOpt) {
for _, opt := range opts {
opt(c)
}
}

func WithLogger(logger log.Logger) ConfigOpt {
return func(config *Config) {
config.Logger = logger
}
}

func WithLogLevels(levels ...logrus.Level) ConfigOpt {
return func(config *Config) {
config.LogLevels = levels
}
}

func WithWebhookIDToken(webhookID discord.Snowflake, webhookToken string) ConfigOpt {
return func(config *Config) {
config.WebhookID = webhookID
config.WebhookToken = webhookToken
}
}

func WithWebhookClient(webhookClient *webhook.Client) ConfigOpt {
return func(config *Config) {
config.WebhookClient = webhookClient
}
}
Loading

0 comments on commit 8a326fd

Please sign in to comment.