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:
R. Aidan Campbell 2021-10-11 05:37:33 -07:00 committed by GitHub
commit 083099a957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
210 changed files with 506 additions and 662 deletions

View file

@ -31,7 +31,7 @@ import (
const retries = 5
func (t *timeline) Get(ctx context.Context, amount int, maxID string, sinceID string, minID string, prepareNext bool) ([]*apimodel.Status, error) {
l := t.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "Get",
"accountID": t.accountID,
"amount": amount,
@ -137,7 +137,7 @@ func (t *timeline) GetXFromTop(ctx context.Context, amount int) ([]*apimodel.Sta
}
func (t *timeline) GetXBehindID(ctx context.Context, amount int, behindID string, attempts *int) ([]*apimodel.Status, error) {
l := t.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "GetXBehindID",
"amount": amount,
"behindID": behindID,

View file

@ -40,13 +40,13 @@ func (suite *GetTestSuite) SetupSuite() {
func (suite *GetTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
testrig.StandardDBSetup(suite.db, nil)
// let's take local_account_1 as the timeline owner
tl, err := timeline.NewTimeline(context.Background(), suite.testAccounts["local_account_1"].ID, suite.db, suite.tc, suite.log)
tl, err := timeline.NewTimeline(context.Background(), suite.testAccounts["local_account_1"].ID, suite.db, suite.tc)
if err != nil {
suite.FailNow(err.Error())
}

View file

@ -81,7 +81,7 @@ grabloop:
}
func (t *timeline) IndexBehind(ctx context.Context, statusID string, include bool, amount int) error {
l := t.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "IndexBehind",
"include": include,
"amount": amount,

View file

@ -41,13 +41,13 @@ func (suite *IndexTestSuite) SetupSuite() {
func (suite *IndexTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
testrig.StandardDBSetup(suite.db, nil)
// let's take local_account_1 as the timeline owner, and start with an empty timeline
tl, err := timeline.NewTimeline(context.Background(), suite.testAccounts["local_account_1"].ID, suite.db, suite.tc, suite.log)
tl, err := timeline.NewTimeline(context.Background(), suite.testAccounts["local_account_1"].ID, suite.db, suite.tc)
if err != nil {
suite.FailNow(err.Error())
}

View file

@ -84,13 +84,12 @@ type Manager interface {
}
// NewManager returns a new timeline manager with the given database, typeconverter, config, and log.
func NewManager(db db.DB, tc typeutils.TypeConverter, config *config.Config, log *logrus.Logger) Manager {
func NewManager(db db.DB, tc typeutils.TypeConverter, config *config.Config) Manager {
return &manager{
accountTimelines: sync.Map{},
db: db,
tc: tc,
config: config,
log: log,
}
}
@ -99,11 +98,10 @@ type manager struct {
db db.DB
tc typeutils.TypeConverter
config *config.Config
log *logrus.Logger
}
func (m *manager) Ingest(ctx context.Context, status *gtsmodel.Status, timelineAccountID string) (bool, error) {
l := m.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "Ingest",
"timelineAccountID": timelineAccountID,
"statusID": status.ID,
@ -119,7 +117,7 @@ func (m *manager) Ingest(ctx context.Context, status *gtsmodel.Status, timelineA
}
func (m *manager) IngestAndPrepare(ctx context.Context, status *gtsmodel.Status, timelineAccountID string) (bool, error) {
l := m.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "IngestAndPrepare",
"timelineAccountID": timelineAccountID,
"statusID": status.ID,
@ -135,7 +133,7 @@ func (m *manager) IngestAndPrepare(ctx context.Context, status *gtsmodel.Status,
}
func (m *manager) Remove(ctx context.Context, timelineAccountID string, statusID string) (int, error) {
l := m.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "Remove",
"timelineAccountID": timelineAccountID,
"statusID": statusID,
@ -151,7 +149,7 @@ func (m *manager) Remove(ctx context.Context, timelineAccountID string, statusID
}
func (m *manager) HomeTimeline(ctx context.Context, timelineAccountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*apimodel.Status, error) {
l := m.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "HomeTimelineGet",
"timelineAccountID": timelineAccountID,
})
@ -237,7 +235,7 @@ func (m *manager) getOrCreateTimeline(ctx context.Context, timelineAccountID str
i, ok := m.accountTimelines.Load(timelineAccountID)
if !ok {
var err error
t, err = NewTimeline(ctx, timelineAccountID, m.db, m.tc, m.log)
t, err = NewTimeline(ctx, timelineAccountID, m.db, m.tc)
if err != nil {
return nil, err
}

View file

@ -38,7 +38,7 @@ func (suite *ManagerTestSuite) SetupSuite() {
func (suite *ManagerTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
testrig.StandardDBSetup(suite.db, nil)

View file

@ -30,7 +30,7 @@ import (
)
func (t *timeline) prepareNextQuery(ctx context.Context, amount int, maxID string, sinceID string, minID string) error {
l := t.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "prepareNextQuery",
"amount": amount,
"maxID": maxID,
@ -170,7 +170,7 @@ prepareloop:
}
func (t *timeline) PrepareFromTop(ctx context.Context, amount int) error {
l := t.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "PrepareFromTop",
"amount": amount,
})

View file

@ -27,7 +27,7 @@ import (
)
func (t *timeline) Remove(ctx context.Context, statusID string) (int, error) {
l := t.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "Remove",
"accountTimeline": t.accountID,
"statusID": statusID,
@ -79,7 +79,7 @@ func (t *timeline) Remove(ctx context.Context, statusID string) (int, error) {
}
func (t *timeline) RemoveAllBy(ctx context.Context, accountID string) (int, error) {
l := t.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "RemoveAllBy",
"accountTimeline": t.accountID,
"accountID": accountID,

View file

@ -23,7 +23,6 @@ import (
"sync"
"time"
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
@ -134,12 +133,11 @@ type timeline struct {
db db.DB
filter visibility.Filter
tc typeutils.TypeConverter
log *logrus.Logger
sync.Mutex
}
// NewTimeline returns a new Timeline for the given account ID
func NewTimeline(ctx context.Context, accountID string, db db.DB, typeConverter typeutils.TypeConverter, log *logrus.Logger) (Timeline, error) {
func NewTimeline(ctx context.Context, accountID string, db db.DB, typeConverter typeutils.TypeConverter) (Timeline, error) {
timelineOwnerAccount := &gtsmodel.Account{}
if err := db.GetByID(ctx, accountID, timelineOwnerAccount); err != nil {
return nil, err
@ -151,9 +149,8 @@ func NewTimeline(ctx context.Context, accountID string, db db.DB, typeConverter
accountID: accountID,
account: timelineOwnerAccount,
db: db,
filter: visibility.NewFilter(db, log),
filter: visibility.NewFilter(db),
tc: typeConverter,
log: log,
}, nil
}

View file

@ -19,7 +19,6 @@
package timeline_test
import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -32,7 +31,6 @@ type TimelineStandardTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
testAccounts map[string]*gtsmodel.Account