From 098dbe6ff4f59652181c8e0e3873fbfcf0e65ea3 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Tue, 19 Jul 2022 09:47:55 +0100 Subject: [chore] use our own logging implementation (#716) * first commit Signed-off-by: kim * replace logging with our own log library Signed-off-by: kim * fix imports Signed-off-by: kim * fix log imports Signed-off-by: kim * add license text Signed-off-by: kim * fix package import cycle between config and log package Signed-off-by: kim * fix empty kv.Fields{} being passed to WithFields() Signed-off-by: kim * fix uses of log.WithFields() with whitespace issues and empty slices Signed-off-by: kim * *linter related grumbling* Signed-off-by: kim * gofmt the codebase! also fix more log.WithFields() formatting issues Signed-off-by: kim * update testrig code to match new changes Signed-off-by: kim * fix error wrapping in non fmt.Errorf function Signed-off-by: kim * add benchmarking of log.Caller() vs non-cached Signed-off-by: kim * fix syslog tests, add standard build tags to test runner to ensure consistency Signed-off-by: kim * make syslog tests more robust Signed-off-by: kim * fix caller depth arithmatic (is that how you spell it?) Signed-off-by: kim * update to use unkeyed fields in kv.Field{} instances Signed-off-by: kim * update go-kv library Signed-off-by: kim * update libraries list Signed-off-by: kim * fuck you linter get nerfed Signed-off-by: kim Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com> --- internal/media/processingmedia.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'internal/media/processingmedia.go') diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go index 17fddddb7..885e97417 100644 --- a/internal/media/processingmedia.go +++ b/internal/media/processingmedia.go @@ -28,11 +28,11 @@ import ( "sync/atomic" "time" - "github.com/sirupsen/logrus" terminator "github.com/superseriousbusiness/exif-terminator" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/id" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/storage" "github.com/superseriousbusiness/gotosocial/internal/uris" ) @@ -80,10 +80,10 @@ func (p *ProcessingMedia) AttachmentID() string { // LoadAttachment blocks until the thumbnail and fullsize content // has been processed, and then returns the completed attachment. func (p *ProcessingMedia) LoadAttachment(ctx context.Context) (*gtsmodel.MediaAttachment, error) { - logrus.Tracef("LoadAttachment: getting lock for attachment %s", p.attachment.URL) + log.Tracef("LoadAttachment: getting lock for attachment %s", p.attachment.URL) p.mu.Lock() defer p.mu.Unlock() - logrus.Tracef("LoadAttachment: got lock for attachment %s", p.attachment.URL) + log.Tracef("LoadAttachment: got lock for attachment %s", p.attachment.URL) if err := p.store(ctx); err != nil { return nil, err @@ -113,7 +113,7 @@ func (p *ProcessingMedia) LoadAttachment(ctx context.Context) (*gtsmodel.MediaAt p.insertedInDB = true } - logrus.Tracef("LoadAttachment: finished, returning attachment %s", p.attachment.URL) + log.Tracef("LoadAttachment: finished, returning attachment %s", p.attachment.URL) return p.attachment, nil } @@ -137,7 +137,7 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) error { } // stream the original file out of storage - logrus.Tracef("loadThumb: fetching attachment from storage %s", p.attachment.URL) + log.Tracef("loadThumb: fetching attachment from storage %s", p.attachment.URL) stored, err := p.storage.GetStream(ctx, p.attachment.File.Path) if err != nil { p.err = fmt.Errorf("loadThumb: error fetching file from storage: %s", err) @@ -147,14 +147,14 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) error { // whatever happens, close the stream when we're done defer func() { - logrus.Tracef("loadThumb: closing stored stream %s", p.attachment.URL) + log.Tracef("loadThumb: closing stored stream %s", p.attachment.URL) if err := stored.Close(); err != nil { - logrus.Errorf("loadThumb: error closing stored full size: %s", err) + log.Errorf("loadThumb: error closing stored full size: %s", err) } }() // stream the file from storage straight into the derive thumbnail function - logrus.Tracef("loadThumb: calling deriveThumbnail %s", p.attachment.URL) + log.Tracef("loadThumb: calling deriveThumbnail %s", p.attachment.URL) thumb, err := deriveThumbnail(stored, p.attachment.File.ContentType, createBlurhash) if err != nil { p.err = fmt.Errorf("loadThumb: error deriving thumbnail: %s", err) @@ -163,7 +163,7 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) error { } // put the thumbnail in storage - logrus.Tracef("loadThumb: storing new thumbnail %s", p.attachment.URL) + log.Tracef("loadThumb: storing new thumbnail %s", p.attachment.URL) if err := p.storage.Put(ctx, p.attachment.Thumbnail.Path, thumb.small); err != nil { p.err = fmt.Errorf("loadThumb: error storing thumbnail: %s", err) atomic.StoreInt32(&p.thumbState, int32(errored)) @@ -184,7 +184,7 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) error { // we're done processing the thumbnail! atomic.StoreInt32(&p.thumbState, int32(complete)) - logrus.Tracef("loadThumb: finished processing thumbnail for attachment %s", p.attachment.URL) + log.Tracef("loadThumb: finished processing thumbnail for attachment %s", p.attachment.URL) fallthrough case complete: return nil @@ -245,7 +245,7 @@ func (p *ProcessingMedia) loadFullSize(ctx context.Context) error { // we're done processing the full-size image atomic.StoreInt32(&p.fullSizeState, int32(complete)) - logrus.Tracef("loadFullSize: finished processing full size image for attachment %s", p.attachment.URL) + log.Tracef("loadFullSize: finished processing full size image for attachment %s", p.attachment.URL) fallthrough case complete: return nil @@ -270,13 +270,13 @@ func (p *ProcessingMedia) store(ctx context.Context) error { if err != nil { return fmt.Errorf("store: error executing data function: %s", err) } - logrus.Tracef("store: reading %d bytes from data function for media %s", fileSize, p.attachment.URL) + log.Tracef("store: reading %d bytes from data function for media %s", fileSize, p.attachment.URL) // defer closing the reader when we're done with it defer func() { if rc, ok := reader.(io.ReadCloser); ok { if err := rc.Close(); err != nil { - logrus.Errorf("store: error closing readcloser: %s", err) + log.Errorf("store: error closing readcloser: %s", err) } } }() @@ -330,7 +330,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error { defer func() { if rc, ok := clean.(io.ReadCloser); ok { if err := rc.Close(); err != nil { - logrus.Errorf("store: error closing clean readcloser: %s", err) + log.Errorf("store: error closing clean readcloser: %s", err) } } }() @@ -353,7 +353,7 @@ func (p *ProcessingMedia) store(ctx context.Context) error { return p.postData(ctx) } - logrus.Tracef("store: finished storing initial data for attachment %s", p.attachment.URL) + log.Tracef("store: finished storing initial data for attachment %s", p.attachment.URL) return nil } -- cgit v1.2.3