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

@ -33,13 +33,13 @@ import (
)
func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsAccept) error {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Accept",
},
)
if f.log.Level >= logrus.DebugLevel {
if logrus.GetLevel() >= logrus.DebugLevel {
i, err := marshalItem(accept)
if err != nil {
return err

View file

@ -29,13 +29,13 @@ import (
)
func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStreamsAnnounce) error {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Announce",
},
)
if f.log.Level >= logrus.DebugLevel {
if logrus.GetLevel() >= logrus.DebugLevel {
i, err := marshalItem(announce)
if err != nil {
return err

View file

@ -46,13 +46,13 @@ import (
// Under certain conditions and network activities, Create may be called
// multiple times for the same ActivityStreams object.
func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Create",
},
)
if f.log.Level >= logrus.DebugLevel {
if logrus.GetLevel() >= logrus.DebugLevel {
i, err := marshalItem(asType)
if err != nil {
return err
@ -169,7 +169,7 @@ func (f *federatingDB) activityCreate(ctx context.Context, asType vocab.Type, re
// createNote handles a Create activity with a Note type.
func (f *federatingDB) createNote(ctx context.Context, note vocab.ActivityStreamsNote, receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account, fromFederatorChan chan messages.FromFederator) error {
l := f.log.WithFields(logrus.Fields{
l := logrus.WithFields(logrus.Fields{
"func": "createNote",
"receivingAccount": receivingAccount.URI,
"requestingAccount": requestingAccount.URI,

View file

@ -25,7 +25,6 @@ import (
"github.com/go-fed/activity/pub"
"github.com/go-fed/activity/streams/vocab"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
@ -47,20 +46,18 @@ type federatingDB struct {
pool sync.Pool
db db.DB
config *config.Config
log *logrus.Logger
typeConverter typeutils.TypeConverter
}
// New returns a DB interface using the given database, config, and logger.
func New(db db.DB, config *config.Config, log *logrus.Logger) DB {
// New returns a DB interface using the given database and config
func New(db db.DB, config *config.Config) DB {
fdb := federatingDB{
mutex: sync.Mutex{},
locks: make(map[string]*mutex, 100),
pool: sync.Pool{New: func() interface{} { return &mutex{} }},
db: db,
config: config,
log: log,
typeConverter: typeutils.NewConverter(config, db, log),
typeConverter: typeutils.NewConverter(config, db),
}
go fdb.cleanupLocks()
return &fdb

View file

@ -36,7 +36,7 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Delete",
"id": id,

View file

@ -32,7 +32,7 @@ import (
//
// Implementation note: this just straight up isn't implemented, and doesn't *really* need to be either.
func (f *federatingDB) Exists(c context.Context, id *url.URL) (exists bool, err error) {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Exists",
"id": id,

View file

@ -21,7 +21,6 @@ package federatingdb_test
import (
"context"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -37,7 +36,6 @@ type FederatingDBTestSuite struct {
suite.Suite
config *config.Config
db db.DB
log *logrus.Logger
tc typeutils.TypeConverter
federatingDB federatingdb.DB
@ -68,7 +66,7 @@ func (suite *FederatingDBTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.log = testrig.NewTestLog()
testrig.InitTestLog()
suite.federatingDB = testrig.NewTestFederatingDB(suite.db)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

View file

@ -17,7 +17,7 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Followers",
"id": actorIRI,

View file

@ -17,7 +17,7 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Following",
"id": actorIRI,

View file

@ -32,7 +32,7 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Get",
"id": id,

View file

@ -33,7 +33,7 @@ import (
// the database has an entry for the IRI.
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Owns",
"id": id,

View file

@ -31,13 +31,13 @@ import (
)
func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) error {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Undo",
},
)
if f.log.Level >= logrus.DebugLevel {
if logrus.GetLevel() >= logrus.DebugLevel {
i, err := marshalItem(undo)
if err != nil {
return err

View file

@ -41,13 +41,13 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "Update",
},
)
if f.log.Level >= logrus.DebugLevel {
if logrus.GetLevel() >= logrus.DebugLevel {
i, err := marshalItem(asType)
if err != nil {
return err

View file

@ -63,13 +63,13 @@ func sameActor(activityActor vocab.ActivityStreamsActorProperty, followActor voc
// The go-fed library will handle setting the 'id' property on the
// activity or object provided with the value returned.
func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) {
l := f.log.WithFields(
l := logrus.WithFields(
logrus.Fields{
"func": "NewID",
},
)
if f.log.Level >= logrus.DebugLevel {
if logrus.GetLevel() >= logrus.DebugLevel {
i, err := marshalItem(t)
if err != nil {
return nil, err