mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-04 04:53:17 -06:00
reference global logrus (#274)
* reference logrus' global logger instead of passing and storing a logger reference everywhere * always directly use global logrus logger instead of referencing an instance * test suites should also directly use the global logrus logger * rename gin logging function to clarify that it's middleware * correct comments which erroneously referenced removed logger parameter * setting log level for tests now uses logrus' exported type instead of the string value, to guarantee error isn't possible
This commit is contained in:
parent
367bdca250
commit
083099a957
210 changed files with 506 additions and 662 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
|
|
@ -179,7 +180,7 @@ func (c *converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
|
|||
}
|
||||
status.URI = uriProp.GetIRI().String()
|
||||
|
||||
l := c.log.WithField("statusURI", status.URI)
|
||||
l := logrus.WithField("statusURI", status.URI)
|
||||
|
||||
// web url for viewing this status
|
||||
if statusURL, err := ap.ExtractURL(statusable); err != nil {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
"net/url"
|
||||
|
||||
"github.com/go-fed/activity/streams/vocab"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/cache"
|
||||
|
|
@ -176,16 +175,14 @@ type TypeConverter interface {
|
|||
type converter struct {
|
||||
config *config.Config
|
||||
db db.DB
|
||||
log *logrus.Logger
|
||||
asCache cache.Cache
|
||||
}
|
||||
|
||||
// NewConverter returns a new Converter
|
||||
func NewConverter(config *config.Config, db db.DB, log *logrus.Logger) TypeConverter {
|
||||
func NewConverter(config *config.Config, db db.DB) TypeConverter {
|
||||
return &converter{
|
||||
config: config,
|
||||
db: db,
|
||||
log: log,
|
||||
asCache: cache.New(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package typeutils_test
|
|||
|
||||
import (
|
||||
"github.com/go-fed/activity/streams/vocab"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
|
|
@ -327,7 +326,6 @@ type TypeUtilsTestSuite struct {
|
|||
suite.Suite
|
||||
config *config.Config
|
||||
db db.DB
|
||||
log *logrus.Logger
|
||||
testAccounts map[string]*gtsmodel.Account
|
||||
testStatuses map[string]*gtsmodel.Status
|
||||
testPeople map[string]vocab.ActivityStreamsPerson
|
||||
|
|
@ -338,11 +336,11 @@ type TypeUtilsTestSuite struct {
|
|||
func (suite *TypeUtilsTestSuite) SetupSuite() {
|
||||
suite.config = testrig.NewTestConfig()
|
||||
suite.db = testrig.NewTestDB()
|
||||
suite.log = testrig.NewTestLog()
|
||||
testrig.InitTestLog()
|
||||
suite.testAccounts = testrig.NewTestAccounts()
|
||||
suite.testStatuses = testrig.NewTestStatuses()
|
||||
suite.testPeople = testrig.NewTestFediPeople()
|
||||
suite.typeconverter = typeutils.NewConverter(suite.config, suite.db, suite.log)
|
||||
suite.typeconverter = typeutils.NewConverter(suite.config, suite.db)
|
||||
}
|
||||
|
||||
func (suite *TypeUtilsTestSuite) SetupTest() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ package typeutils
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -302,8 +303,6 @@ func (c *converter) TagToAPITag(ctx context.Context, t *gtsmodel.Tag) (model.Tag
|
|||
}
|
||||
|
||||
func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*model.Status, error) {
|
||||
l := c.log
|
||||
|
||||
repliesCount, err := c.db.CountStatusReplies(ctx, s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error counting replies: %s", err)
|
||||
|
|
@ -380,7 +379,7 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, gtsAttachment := range s.Attachments {
|
||||
apiAttachment, err := c.AttachmentToAPIAttachment(ctx, gtsAttachment)
|
||||
if err != nil {
|
||||
l.Errorf("error converting attachment with id %s: %s", gtsAttachment.ID, err)
|
||||
logrus.Errorf("error converting attachment with id %s: %s", gtsAttachment.ID, err)
|
||||
continue
|
||||
}
|
||||
apiAttachments = append(apiAttachments, apiAttachment)
|
||||
|
|
@ -391,12 +390,12 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, aID := range s.AttachmentIDs {
|
||||
gtsAttachment, err := c.db.GetAttachmentByID(ctx, aID)
|
||||
if err != nil {
|
||||
l.Errorf("error getting attachment with id %s: %s", aID, err)
|
||||
logrus.Errorf("error getting attachment with id %s: %s", aID, err)
|
||||
continue
|
||||
}
|
||||
apiAttachment, err := c.AttachmentToAPIAttachment(ctx, gtsAttachment)
|
||||
if err != nil {
|
||||
l.Errorf("error converting attachment with id %s: %s", aID, err)
|
||||
logrus.Errorf("error converting attachment with id %s: %s", aID, err)
|
||||
continue
|
||||
}
|
||||
apiAttachments = append(apiAttachments, apiAttachment)
|
||||
|
|
@ -410,7 +409,7 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, gtsMention := range s.Mentions {
|
||||
apiMention, err := c.MentionToAPIMention(ctx, gtsMention)
|
||||
if err != nil {
|
||||
l.Errorf("error converting mention with id %s: %s", gtsMention.ID, err)
|
||||
logrus.Errorf("error converting mention with id %s: %s", gtsMention.ID, err)
|
||||
continue
|
||||
}
|
||||
apiMentions = append(apiMentions, apiMention)
|
||||
|
|
@ -421,12 +420,12 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, mID := range s.MentionIDs {
|
||||
gtsMention, err := c.db.GetMention(ctx, mID)
|
||||
if err != nil {
|
||||
l.Errorf("error getting mention with id %s: %s", mID, err)
|
||||
logrus.Errorf("error getting mention with id %s: %s", mID, err)
|
||||
continue
|
||||
}
|
||||
apiMention, err := c.MentionToAPIMention(ctx, gtsMention)
|
||||
if err != nil {
|
||||
l.Errorf("error converting mention with id %s: %s", gtsMention.ID, err)
|
||||
logrus.Errorf("error converting mention with id %s: %s", gtsMention.ID, err)
|
||||
continue
|
||||
}
|
||||
apiMentions = append(apiMentions, apiMention)
|
||||
|
|
@ -440,7 +439,7 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, gtsTag := range s.Tags {
|
||||
apiTag, err := c.TagToAPITag(ctx, gtsTag)
|
||||
if err != nil {
|
||||
l.Errorf("error converting tag with id %s: %s", gtsTag.ID, err)
|
||||
logrus.Errorf("error converting tag with id %s: %s", gtsTag.ID, err)
|
||||
continue
|
||||
}
|
||||
apiTags = append(apiTags, apiTag)
|
||||
|
|
@ -451,12 +450,12 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, t := range s.TagIDs {
|
||||
gtsTag := >smodel.Tag{}
|
||||
if err := c.db.GetByID(ctx, t, gtsTag); err != nil {
|
||||
l.Errorf("error getting tag with id %s: %s", t, err)
|
||||
logrus.Errorf("error getting tag with id %s: %s", t, err)
|
||||
continue
|
||||
}
|
||||
apiTag, err := c.TagToAPITag(ctx, gtsTag)
|
||||
if err != nil {
|
||||
l.Errorf("error converting tag with id %s: %s", gtsTag.ID, err)
|
||||
logrus.Errorf("error converting tag with id %s: %s", gtsTag.ID, err)
|
||||
continue
|
||||
}
|
||||
apiTags = append(apiTags, apiTag)
|
||||
|
|
@ -470,7 +469,7 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, gtsEmoji := range s.Emojis {
|
||||
apiEmoji, err := c.EmojiToAPIEmoji(ctx, gtsEmoji)
|
||||
if err != nil {
|
||||
l.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
|
||||
logrus.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
|
||||
continue
|
||||
}
|
||||
apiEmojis = append(apiEmojis, apiEmoji)
|
||||
|
|
@ -481,12 +480,12 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
|
|||
for _, e := range s.EmojiIDs {
|
||||
gtsEmoji := >smodel.Emoji{}
|
||||
if err := c.db.GetByID(ctx, e, gtsEmoji); err != nil {
|
||||
l.Errorf("error getting emoji with id %s: %s", e, err)
|
||||
logrus.Errorf("error getting emoji with id %s: %s", e, err)
|
||||
continue
|
||||
}
|
||||
apiEmoji, err := c.EmojiToAPIEmoji(ctx, gtsEmoji)
|
||||
if err != nil {
|
||||
l.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
|
||||
logrus.Errorf("error converting emoji with id %s: %s", gtsEmoji.ID, err)
|
||||
continue
|
||||
}
|
||||
apiEmojis = append(apiEmojis, apiEmoji)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue