From e9299d3df4312fd9654095c5b0dba207d2b54f71 Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Tue, 30 Nov 2021 02:07:37 +0100 Subject: [PATCH] update dislog to latest disgo release --- _examples/id_token_example/example.go | 7 +++---- _examples/id_token_example/go.mod | 4 +--- _examples/id_token_example/go.sum | 7 ++----- _examples/webhook_client_example/example.go | 10 ++++------ _examples/webhook_client_example/go.mod | 4 +--- _examples/webhook_client_example/go.sum | 7 ++----- dislog.go | 19 +++++++++---------- go.mod | 4 +--- go.sum | 7 ++----- 9 files changed, 25 insertions(+), 44 deletions(-) diff --git a/_examples/id_token_example/example.go b/_examples/id_token_example/example.go index 56d9663..b53a03c 100644 --- a/_examples/id_token_example/example.go +++ b/_examples/id_token_example/example.go @@ -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 @@ -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") } diff --git a/_examples/id_token_example/go.mod b/_examples/id_token_example/go.mod index 11b56b6..d503ef3 100644 --- a/_examples/id_token_example/go.mod +++ b/_examples/id_token_example/go.mod @@ -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 diff --git a/_examples/id_token_example/go.sum b/_examples/id_token_example/go.sum index 51c9829..ba6138e 100644 --- a/_examples/id_token_example/go.sum +++ b/_examples/id_token_example/go.sum @@ -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= @@ -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= diff --git a/_examples/webhook_client_example/example.go b/_examples/webhook_client_example/example.go index c179efc..c11e517 100644 --- a/_examples/webhook_client_example/example.go +++ b/_examples/webhook_client_example/example.go @@ -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 @@ -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) @@ -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") } diff --git a/_examples/webhook_client_example/go.mod b/_examples/webhook_client_example/go.mod index f71c7af..eee7035 100644 --- a/_examples/webhook_client_example/go.mod +++ b/_examples/webhook_client_example/go.mod @@ -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 diff --git a/_examples/webhook_client_example/go.sum b/_examples/webhook_client_example/go.sum index 51c9829..ba6138e 100644 --- a/_examples/webhook_client_example/go.sum +++ b/_examples/webhook_client_example/go.sum @@ -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= @@ -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= diff --git a/dislog.go b/dislog.go index a7d5666..6af07cc 100644 --- a/dislog.go +++ b/dislog.go @@ -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" @@ -74,7 +73,7 @@ type DisLog struct { webhookClient *webhook.Client queued bool - logQueue []discord.Embed + queue []discord.Embed levels []logrus.Level } @@ -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() @@ -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 { @@ -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). diff --git a/go.mod b/go.mod index 55cb32c..577734a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 51c9829..ba6138e 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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=