diff options
author | 2022-07-19 09:47:55 +0100 | |
---|---|---|
committer | 2022-07-19 10:47:55 +0200 | |
commit | 098dbe6ff4f59652181c8e0e3873fbfcf0e65ea3 (patch) | |
tree | 17036ad9db68c3080e1e91279c8bce9f9ea6e5c3 /internal/transport | |
parent | [bugfix] Markdown format fixes (#718) (diff) | |
download | gotosocial-098dbe6ff4f59652181c8e0e3873fbfcf0e65ea3.tar.xz |
[chore] use our own logging implementation (#716)
* first commit
Signed-off-by: kim <grufwub@gmail.com>
* replace logging with our own log library
Signed-off-by: kim <grufwub@gmail.com>
* fix imports
Signed-off-by: kim <grufwub@gmail.com>
* fix log imports
Signed-off-by: kim <grufwub@gmail.com>
* add license text
Signed-off-by: kim <grufwub@gmail.com>
* fix package import cycle between config and log package
Signed-off-by: kim <grufwub@gmail.com>
* fix empty kv.Fields{} being passed to WithFields()
Signed-off-by: kim <grufwub@gmail.com>
* fix uses of log.WithFields() with whitespace issues and empty slices
Signed-off-by: kim <grufwub@gmail.com>
* *linter related grumbling*
Signed-off-by: kim <grufwub@gmail.com>
* gofmt the codebase! also fix more log.WithFields() formatting issues
Signed-off-by: kim <grufwub@gmail.com>
* update testrig code to match new changes
Signed-off-by: kim <grufwub@gmail.com>
* fix error wrapping in non fmt.Errorf function
Signed-off-by: kim <grufwub@gmail.com>
* add benchmarking of log.Caller() vs non-cached
Signed-off-by: kim <grufwub@gmail.com>
* fix syslog tests, add standard build tags to test runner to ensure consistency
Signed-off-by: kim <grufwub@gmail.com>
* make syslog tests more robust
Signed-off-by: kim <grufwub@gmail.com>
* fix caller depth arithmatic (is that how you spell it?)
Signed-off-by: kim <grufwub@gmail.com>
* update to use unkeyed fields in kv.Field{} instances
Signed-off-by: kim <grufwub@gmail.com>
* update go-kv library
Signed-off-by: kim <grufwub@gmail.com>
* update libraries list
Signed-off-by: kim <grufwub@gmail.com>
* fuck you linter get nerfed
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal/transport')
-rw-r--r-- | internal/transport/controller.go | 4 | ||||
-rw-r--r-- | internal/transport/derefinstance.go | 19 | ||||
-rw-r--r-- | internal/transport/transport.go | 13 |
3 files changed, 17 insertions, 19 deletions
diff --git a/internal/transport/controller.go b/internal/transport/controller.go index 45eb4fd79..255932d5d 100644 --- a/internal/transport/controller.go +++ b/internal/transport/controller.go @@ -29,12 +29,12 @@ import ( "codeberg.org/gruf/go-byteutil" "codeberg.org/gruf/go-cache/v2" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/activity/pub" "github.com/superseriousbusiness/activity/streams" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb" + "github.com/superseriousbusiness/gotosocial/internal/log" ) // Controller generates transports for use in making federation requests to other servers. @@ -73,7 +73,7 @@ func NewController(db db.DB, federatingDB federatingdb.DB, clock pub.Clock, clie // Transport cache has TTL=1hr freq=1m c.cache.SetTTL(time.Hour, false) if !c.cache.Start(time.Minute) { - logrus.Panic("failed to start transport controller cache") + log.Panic("failed to start transport controller cache") } return c diff --git a/internal/transport/derefinstance.go b/internal/transport/derefinstance.go index 35b088b88..c43625a0b 100644 --- a/internal/transport/derefinstance.go +++ b/internal/transport/derefinstance.go @@ -28,19 +28,16 @@ import ( "net/url" "strings" - "github.com/sirupsen/logrus" - "github.com/superseriousbusiness/gotosocial/internal/api" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/id" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/util" "github.com/superseriousbusiness/gotosocial/internal/validate" ) func (t *transport) DereferenceInstance(ctx context.Context, iri *url.URL) (*gtsmodel.Instance, error) { - l := logrus.WithField("func", "DereferenceInstance") - var i *gtsmodel.Instance var err error @@ -48,26 +45,26 @@ func (t *transport) DereferenceInstance(ctx context.Context, iri *url.URL) (*gts // This will provide the most complete picture of an instance, and avoid unnecessary api calls. // // This will only work with Mastodon-api compatible instances: Mastodon, some Pleroma instances, GoToSocial. - l.Debugf("trying to dereference instance %s by /api/v1/instance", iri.Host) + log.Debugf("trying to dereference instance %s by /api/v1/instance", iri.Host) i, err = dereferenceByAPIV1Instance(ctx, t, iri) if err == nil { - l.Debugf("successfully dereferenced instance using /api/v1/instance") + log.Debugf("successfully dereferenced instance using /api/v1/instance") return i, nil } - l.Debugf("couldn't dereference instance using /api/v1/instance: %s", err) + log.Debugf("couldn't dereference instance using /api/v1/instance: %s", err) // If that doesn't work, try to dereference using /.well-known/nodeinfo. // This will involve two API calls and return less info overall, but should be more widely compatible. - l.Debugf("trying to dereference instance %s by /.well-known/nodeinfo", iri.Host) + log.Debugf("trying to dereference instance %s by /.well-known/nodeinfo", iri.Host) i, err = dereferenceByNodeInfo(ctx, t, iri) if err == nil { - l.Debugf("successfully dereferenced instance using /.well-known/nodeinfo") + log.Debugf("successfully dereferenced instance using /.well-known/nodeinfo") return i, nil } - l.Debugf("couldn't dereference instance using /.well-known/nodeinfo: %s", err) + log.Debugf("couldn't dereference instance using /.well-known/nodeinfo: %s", err) // we couldn't dereference the instance using any of the known methods, so just return a minimal representation - l.Debugf("returning minimal representation of instance %s", iri.Host) + log.Debugf("returning minimal representation of instance %s", iri.Host) id, err := id.NewRandomULID() if err != nil { return nil, fmt.Errorf("error creating new id for instance %s: %s", iri.Host, err) diff --git a/internal/transport/transport.go b/internal/transport/transport.go index 22dfbeb9a..80710a519 100644 --- a/internal/transport/transport.go +++ b/internal/transport/transport.go @@ -31,11 +31,12 @@ import ( "time" errorsv2 "codeberg.org/gruf/go-errors/v2" + "codeberg.org/gruf/go-kv" "github.com/go-fed/httpsig" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/activity/pub" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/httpclient" + "github.com/superseriousbusiness/gotosocial/internal/log" ) // Transport wraps the pub.Transport interface with some additional functionality for fetching remote media. @@ -90,11 +91,11 @@ func (t *transport) do(r *http.Request, signer func(*http.Request) error, retryO backoff := time.Second * 2 // Start a log entry for this request - l := logrus.WithFields(logrus.Fields{ - "pubKeyID": t.pubKeyID, - "method": r.Method, - "url": r.URL.String(), - }) + l := log.WithFields(kv.Fields{ + {"pubKeyID", t.pubKeyID}, + {"method", r.Method}, + {"url", r.URL.String()}, + }...) for i := 0; i < maxRetries; i++ { // Reset signing header fields |