Skip to content

Commit

Permalink
update dislog to latest disgo release
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Nov 30, 2021
1 parent 8a326fd commit e9299d3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 44 deletions.
7 changes: 3 additions & 4 deletions _examples/id_token_example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import (
var (
webhookID = discord.Snowflake(os.Getenv("webhook_id"))
webhookToken = os.Getenv("webhook_token")

logger = logrus.New()
)

func main() {
logger := logrus.New()
// override default trace color
dislog.TraceLevelColor = 0xd400ff

Expand Down Expand Up @@ -47,8 +46,8 @@ func main() {
logger.Info("info log")
logger.Warn("warn log")
logger.Error("error log")
// Calls os.Exit(1) after logging
logger.Fatal("fatal log")
// Calls panic() after logging
logger.Panic("panic log")
// Calls os.Exit(1) after logging
logger.Fatal("fatal log")
}
4 changes: 1 addition & 3 deletions _examples/id_token_example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ go 1.17
replace github.com/DisgoOrg/dislog => ../../

require (
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc
github.com/DisgoOrg/disgo v0.6.1
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
Expand Down
7 changes: 2 additions & 5 deletions _examples/id_token_example/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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/disgo v0.6.1 h1:ndKixxtk1usNeDKILB0m/j6ERNgFyXp1o8F84ZYx0sY=
github.com/DisgoOrg/disgo v0.6.1/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=
Expand All @@ -23,7 +21,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
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=
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=
Expand Down
10 changes: 4 additions & 6 deletions _examples/webhook_client_example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import (
var (
webhookID = discord.Snowflake(os.Getenv("webhook_id"))
webhookToken = os.Getenv("webhook_token")

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

func main() {
logger := logrus.New()
// override default trace color
dislog.TraceLevelColor = 0xd400ff

Expand All @@ -37,7 +35,7 @@ func main() {
// Sets which logging levels to send to the webhook
dislog.WithLogLevels(dislog.TraceLevelAndAbove...),
// Sets a custom http client or nil for inbuilt
dislog.WithWebhookClient(webhook.NewClient(webhookID, webhookToken, webhook.WithRestClientConfigOpts(rest.WithHTTPClient(httpClient)))),
dislog.WithWebhookClient(webhook.NewClient(webhookID, webhookToken, webhook.WithRestClientConfigOpts(rest.WithHTTPClient(http.DefaultClient)))),
)
if err != nil {
logger.Errorf("error initializing dislog %s", err)
Expand All @@ -51,8 +49,8 @@ func main() {
logger.Info("info log")
logger.Warn("warn log")
logger.Error("error log")
// Calls os.Exit(1) after logging
logger.Fatal("fatal log")
// Calls panic() after logging
logger.Panic("panic log")
// Calls os.Exit(1) after logging
logger.Fatal("fatal log")
}
4 changes: 1 addition & 3 deletions _examples/webhook_client_example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ go 1.17
replace github.com/DisgoOrg/dislog => ../../

require (
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc
github.com/DisgoOrg/disgo v0.6.1
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
Expand Down
7 changes: 2 additions & 5 deletions _examples/webhook_client_example/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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/disgo v0.6.1 h1:ndKixxtk1usNeDKILB0m/j6ERNgFyXp1o8F84ZYx0sY=
github.com/DisgoOrg/disgo v0.6.1/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=
Expand All @@ -23,7 +21,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
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=
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=
Expand Down
19 changes: 9 additions & 10 deletions dislog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dislog
import (
"errors"
"fmt"
"github.com/DisgoOrg/disgo/core"
"github.com/DisgoOrg/disgo/discord"
"github.com/DisgoOrg/disgo/webhook"
"github.com/DisgoOrg/log"
Expand Down Expand Up @@ -74,7 +73,7 @@ type DisLog struct {

webhookClient *webhook.Client
queued bool
logQueue []discord.Embed
queue []discord.Embed
levels []logrus.Level
}

Expand All @@ -89,8 +88,8 @@ func (l *DisLog) Close() {
func (l *DisLog) queueEmbed(embed discord.Embed, forceSend bool) error {
l.Lock()
defer l.Unlock()
l.logQueue = append(l.logQueue, embed)
if len(l.logQueue) >= MaxEmbeds || forceSend {
l.queue = append(l.queue, embed)
if len(l.queue) >= MaxEmbeds || forceSend {
go l.sendEmbeds()
} else {
l.queueEmbeds()
Expand All @@ -101,19 +100,19 @@ func (l *DisLog) queueEmbed(embed discord.Embed, forceSend bool) error {
func (l *DisLog) sendEmbeds() {
l.Lock()
defer l.Unlock()
if len(l.logQueue) == 0 {
if len(l.queue) == 0 {
return
}
message := webhook.NewMessageCreateBuilder()
message := discord.NewWebhookMessageCreateBuilder()

for i := 0; i < len(l.logQueue); i++ {
for i := 0; i < len(l.queue); i++ {
if i >= MaxEmbeds {
// queue again as we have logs to send
l.queueEmbeds()
break
}
message.AddEmbeds(l.logQueue[i])
l.logQueue = append(l.logQueue[:i], l.logQueue[i+1:]...)
message.AddEmbeds(l.queue[i])
l.queue = append(l.queue[:i], l.queue[i+1:]...)
i--
}
if len(message.Embeds) == 0 {
Expand All @@ -139,7 +138,7 @@ func (l *DisLog) queueEmbeds() {
}

func (l *DisLog) Fire(entry *logrus.Entry) error {
eb := core.NewEmbedBuilder().
eb := discord.NewEmbedBuilder().
SetColor(*LevelColors[entry.Level]).
SetDescription(entry.Message).
AddField("LogLevel", entry.Level.String(), true).
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ module github.com/DisgoOrg/dislog
go 1.17

require (
github.com/DisgoOrg/disgo v0.5.12-0.20210927235146-fb4bb75295bc
github.com/DisgoOrg/disgo v0.6.1
github.com/DisgoOrg/log v1.1.2
github.com/sirupsen/logrus v1.8.1
)

require (
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
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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/disgo v0.6.1 h1:ndKixxtk1usNeDKILB0m/j6ERNgFyXp1o8F84ZYx0sY=
github.com/DisgoOrg/disgo v0.6.1/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=
Expand All @@ -23,7 +21,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
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=
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=
Expand Down

0 comments on commit e9299d3

Please sign in to comment.