From 083099a9575f8b2fac22c1d4a51a9dd0e2201243 Mon Sep 17 00:00:00 2001 From: "R. Aidan Campbell" Date: Mon, 11 Oct 2021 05:37:33 -0700 Subject: [PATCH] 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 --- cmd/gotosocial/runaction.go | 6 +- internal/api/client/account/account.go | 5 +- internal/api/client/account/account_test.go | 6 +- internal/api/client/account/accountcreate.go | 3 +- internal/api/client/account/accountupdate.go | 3 +- internal/api/client/account/accountverify.go | 3 +- internal/api/client/account/relationships.go | 3 +- internal/api/client/account/statuses.go | 3 +- internal/api/client/account/unfollow.go | 3 +- internal/api/client/admin/admin.go | 5 +- .../api/client/admin/domainblockcreate.go | 2 +- .../api/client/admin/domainblockdelete.go | 2 +- internal/api/client/admin/domainblockget.go | 2 +- internal/api/client/admin/domainblocksget.go | 2 +- internal/api/client/admin/emojicreate.go | 2 +- internal/api/client/app/app.go | 5 +- internal/api/client/app/appcreate.go | 3 +- internal/api/client/auth/auth.go | 5 +- internal/api/client/auth/auth_test.go | 4 +- internal/api/client/auth/authorize.go | 5 +- internal/api/client/auth/middleware.go | 3 +- internal/api/client/auth/signin.go | 7 +- internal/api/client/auth/token.go | 3 +- internal/api/client/blocks/blocks.go | 5 +- internal/api/client/blocks/blocksget.go | 3 +- internal/api/client/emoji/emoji.go | 5 +- internal/api/client/favourites/favourites.go | 5 +- .../api/client/favourites/favouritesget.go | 3 +- internal/api/client/fileserver/fileserver.go | 5 +- internal/api/client/fileserver/servefile.go | 2 +- .../api/client/fileserver/servefile_test.go | 5 +- internal/api/client/filter/filter.go | 5 +- internal/api/client/followrequest/accept.go | 3 +- .../api/client/followrequest/followrequest.go | 5 +- internal/api/client/followrequest/get.go | 3 +- internal/api/client/instance/instance.go | 5 +- internal/api/client/instance/instanceget.go | 3 +- internal/api/client/instance/instancepatch.go | 3 +- internal/api/client/list/list.go | 5 +- internal/api/client/media/media.go | 5 +- internal/api/client/media/mediacreate.go | 3 +- internal/api/client/media/mediacreate_test.go | 5 +- internal/api/client/media/mediaget.go | 3 +- internal/api/client/media/mediaupdate.go | 3 +- .../api/client/notification/notification.go | 5 +- .../client/notification/notificationsget.go | 2 +- internal/api/client/search/search.go | 5 +- internal/api/client/search/searchget.go | 2 +- internal/api/client/status/status.go | 8 +- internal/api/client/status/status_test.go | 2 - internal/api/client/status/statusboost.go | 2 +- .../api/client/status/statusboost_test.go | 4 +- internal/api/client/status/statusboostedby.go | 2 +- internal/api/client/status/statuscontext.go | 2 +- internal/api/client/status/statuscreate.go | 3 +- .../api/client/status/statuscreate_test.go | 4 +- internal/api/client/status/statusdelete.go | 2 +- internal/api/client/status/statusfave.go | 2 +- internal/api/client/status/statusfave_test.go | 4 +- internal/api/client/status/statusfavedby.go | 2 +- .../api/client/status/statusfavedby_test.go | 4 +- internal/api/client/status/statusget.go | 2 +- internal/api/client/status/statusget_test.go | 4 +- internal/api/client/status/statusunboost.go | 2 +- internal/api/client/status/statusunfave.go | 2 +- .../api/client/status/statusunfave_test.go | 4 +- internal/api/client/streaming/stream.go | 3 +- internal/api/client/streaming/streaming.go | 5 +- internal/api/client/timeline/home.go | 3 +- internal/api/client/timeline/public.go | 3 +- internal/api/client/timeline/timeline.go | 5 +- internal/api/s2s/nodeinfo/nodeinfo.go | 5 +- internal/api/s2s/nodeinfo/nodeinfoget.go | 2 +- internal/api/s2s/nodeinfo/wellknownget.go | 2 +- internal/api/s2s/user/followers.go | 2 +- internal/api/s2s/user/following.go | 2 +- internal/api/s2s/user/inboxpost.go | 2 +- internal/api/s2s/user/inboxpost_test.go | 8 +- internal/api/s2s/user/publickeyget.go | 2 +- internal/api/s2s/user/repliesget.go | 2 +- internal/api/s2s/user/repliesget_test.go | 6 +- internal/api/s2s/user/statusget.go | 2 +- internal/api/s2s/user/user.go | 5 +- internal/api/s2s/user/user_test.go | 8 +- internal/api/s2s/user/userget.go | 2 +- internal/api/s2s/user/userget_test.go | 2 +- internal/api/s2s/webfinger/webfinger.go | 5 +- internal/api/s2s/webfinger/webfinger_test.go | 8 +- internal/api/s2s/webfinger/webfingerget.go | 2 +- .../api/s2s/webfinger/webfingerget_test.go | 8 +- internal/api/security/security.go | 5 +- internal/api/security/signaturecheck.go | 3 +- internal/api/security/useragentblock.go | 2 +- internal/cliactions/action.go | 3 +- internal/cliactions/admin/account/account.go | 27 ++++--- internal/cliactions/admin/trans/export.go | 7 +- internal/cliactions/admin/trans/import.go | 7 +- internal/cliactions/server/server.go | 74 +++++++++---------- internal/cliactions/testrig/testrig.go | 54 +++++++------- internal/db/bundb/admin.go | 13 ++-- internal/db/bundb/basic.go | 3 +- internal/db/bundb/bundb.go | 24 +++--- internal/db/bundb/bundb_test.go | 4 +- internal/db/bundb/conn.go | 5 +- internal/db/bundb/instance.go | 3 +- internal/db/bundb/trace.go | 10 +-- internal/federation/authenticate.go | 3 +- internal/federation/dereferencing/account.go | 4 +- .../federation/dereferencing/attachment.go | 2 +- .../federation/dereferencing/dereferencer.go | 5 +- .../dereferencing/dereferencer_test.go | 14 +--- internal/federation/dereferencing/status.go | 20 ++--- internal/federation/dereferencing/thread.go | 6 +- internal/federation/federatingdb/accept.go | 4 +- internal/federation/federatingdb/announce.go | 4 +- internal/federation/federatingdb/create.go | 6 +- internal/federation/federatingdb/db.go | 9 +-- internal/federation/federatingdb/delete.go | 2 +- internal/federation/federatingdb/exists.go | 2 +- .../federatingdb/federatingdb_test.go | 4 +- internal/federation/federatingdb/followers.go | 2 +- internal/federation/federatingdb/following.go | 2 +- internal/federation/federatingdb/get.go | 2 +- internal/federation/federatingdb/owns.go | 2 +- internal/federation/federatingdb/undo.go | 4 +- internal/federation/federatingdb/update.go | 4 +- internal/federation/federatingdb/util.go | 4 +- internal/federation/federatingprotocol.go | 10 +-- internal/federation/federator.go | 7 +- internal/federation/federator_test.go | 8 +- internal/log/log.go | 23 +++--- internal/media/handler.go | 8 +- internal/media/util_test.go | 14 ++-- internal/oauth/server.go | 14 ++-- internal/oauth/tokenstore.go | 14 ++-- internal/oidc/handlecallback.go | 3 +- internal/oidc/idp.go | 7 +- internal/processing/account/account.go | 9 +-- internal/processing/account/account_test.go | 6 +- internal/processing/account/create.go | 3 +- internal/processing/account/delete.go | 2 +- internal/processing/account/update.go | 3 +- internal/processing/admin/admin.go | 5 +- .../processing/admin/createdomainblock.go | 2 +- internal/processing/fromfederator.go | 2 +- internal/processing/media/media.go | 5 +- internal/processing/notification.go | 3 +- internal/processing/processor.go | 26 +++---- internal/processing/processor_test.go | 15 +--- internal/processing/search.go | 4 +- internal/processing/status/status.go | 9 +-- internal/processing/status/status_test.go | 2 - internal/processing/status/util_test.go | 4 +- internal/processing/streaming/openstream.go | 2 +- internal/processing/streaming/streaming.go | 5 +- .../processing/streaming/streaming_test.go | 6 +- internal/processing/timeline.go | 5 +- internal/router/logger.go | 4 +- internal/router/router.go | 16 ++-- internal/text/common.go | 3 +- internal/text/common_test.go | 3 +- internal/text/formatter.go | 5 +- internal/text/formatter_test.go | 2 - internal/text/link_test.go | 3 +- internal/text/markdown_test.go | 3 +- internal/text/plain_test.go | 3 +- internal/timeline/get.go | 4 +- internal/timeline/get_test.go | 4 +- internal/timeline/index.go | 2 +- internal/timeline/index_test.go | 4 +- internal/timeline/manager.go | 14 ++-- internal/timeline/manager_test.go | 2 +- internal/timeline/prepare.go | 4 +- internal/timeline/remove.go | 4 +- internal/timeline/timeline.go | 7 +- internal/timeline/timeline_test.go | 2 - internal/trans/exporter.go | 7 +- internal/trans/exportminimal_test.go | 2 +- internal/trans/import.go | 19 ++--- internal/trans/import_test.go | 4 +- internal/trans/importer.go | 7 +- internal/trans/trans_test.go | 4 +- internal/transport/controller.go | 6 +- internal/transport/deliver.go | 3 +- internal/transport/dereference.go | 3 +- internal/transport/derefinstance.go | 9 ++- internal/transport/derefmedia.go | 3 +- internal/transport/finger.go | 3 +- internal/transport/transport.go | 2 - internal/typeutils/astointernal.go | 3 +- internal/typeutils/converter.go | 5 +- internal/typeutils/converter_test.go | 6 +- internal/typeutils/internaltofrontend.go | 27 ++++--- internal/visibility/filter.go | 7 +- internal/visibility/statushometimelineable.go | 2 +- .../visibility/statuspublictimelineable.go | 2 +- internal/visibility/statusvisible.go | 2 +- internal/web/base.go | 8 +- internal/web/thread.go | 3 +- testrig/db.go | 2 +- testrig/federatingdb.go | 2 +- testrig/federator.go | 2 +- testrig/log.go | 10 +-- testrig/mediahandler.go | 5 +- testrig/oauthserver.go | 4 +- testrig/processor.go | 2 +- testrig/router.go | 2 +- testrig/timelinemanager.go | 2 +- testrig/transportcontroller.go | 2 +- testrig/typeconverter.go | 2 +- 210 files changed, 506 insertions(+), 662 deletions(-) diff --git a/cmd/gotosocial/runaction.go b/cmd/gotosocial/runaction.go index fc548d85..c8af9ddb 100644 --- a/cmd/gotosocial/runaction.go +++ b/cmd/gotosocial/runaction.go @@ -41,11 +41,11 @@ func runAction(c *cli.Context, a cliactions.GTSAction) error { return fmt.Errorf("error parsing config: %s", err) } - // create a logger with the log level, formatting, and output splitter already set - log, err := log.New(conf.LogLevel) + // initialize the global logger to the log level, with formatting and output splitter already set + err = log.Initialize(conf.LogLevel) if err != nil { return fmt.Errorf("error creating logger: %s", err) } - return a(c.Context, conf, log) + return a(c.Context, conf) } diff --git a/internal/api/client/account/account.go b/internal/api/client/account/account.go index 42aca328..bb11888d 100644 --- a/internal/api/client/account/account.go +++ b/internal/api/client/account/account.go @@ -23,7 +23,6 @@ import ( "strings" "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -75,15 +74,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new account module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/account/account_test.go b/internal/api/client/account/account_test.go index 0acc611d..f33fd735 100644 --- a/internal/api/client/account/account_test.go +++ b/internal/api/client/account/account_test.go @@ -8,7 +8,6 @@ import ( "git.iim.gay/grufwub/go-store/kv" "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/account" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -26,7 +25,6 @@ type AccountStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter storage *kv.KVStore federator federation.Federator @@ -59,10 +57,10 @@ func (suite *AccountStandardTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.accountModule = account.New(suite.config, suite.processor, suite.log).(*account.Module) + suite.accountModule = account.New(suite.config, suite.processor).(*account.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/client/account/accountcreate.go b/internal/api/client/account/accountcreate.go index 3fab1488..6497d4d0 100644 --- a/internal/api/client/account/accountcreate.go +++ b/internal/api/client/account/accountcreate.go @@ -20,6 +20,7 @@ package account import ( "errors" + "github.com/sirupsen/logrus" "net" "net/http" @@ -67,7 +68,7 @@ import ( // '500': // description: internal error func (m *Module) AccountCreatePOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "accountCreatePOSTHandler") + l := logrus.WithField("func", "accountCreatePOSTHandler") authed, err := oauth.Authed(c, true, true, false, false) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/account/accountupdate.go b/internal/api/client/account/accountupdate.go index 35eaaad6..8534f580 100644 --- a/internal/api/client/account/accountupdate.go +++ b/internal/api/client/account/accountupdate.go @@ -20,6 +20,7 @@ package account import ( "fmt" + "github.com/sirupsen/logrus" "net/http" "strconv" @@ -100,7 +101,7 @@ import ( // '400': // description: bad request func (m *Module) AccountUpdateCredentialsPATCHHandler(c *gin.Context) { - l := m.log.WithField("func", "accountUpdateCredentialsPATCHHandler") + l := logrus.WithField("func", "accountUpdateCredentialsPATCHHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/account/accountverify.go b/internal/api/client/account/accountverify.go index c5c40a03..6b8d1f92 100644 --- a/internal/api/client/account/accountverify.go +++ b/internal/api/client/account/accountverify.go @@ -19,6 +19,7 @@ package account import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -51,7 +52,7 @@ import ( // '404': // description: not found func (m *Module) AccountVerifyGETHandler(c *gin.Context) { - l := m.log.WithField("func", "accountVerifyGETHandler") + l := logrus.WithField("func", "accountVerifyGETHandler") authed, err := oauth.Authed(c, true, false, false, true) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/account/relationships.go b/internal/api/client/account/relationships.go index d350209a..bb942d18 100644 --- a/internal/api/client/account/relationships.go +++ b/internal/api/client/account/relationships.go @@ -1,6 +1,7 @@ package account import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -47,7 +48,7 @@ import ( // '404': // description: not found func (m *Module) AccountRelationshipsGETHandler(c *gin.Context) { - l := m.log.WithField("func", "AccountRelationshipsGETHandler") + l := logrus.WithField("func", "AccountRelationshipsGETHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/account/statuses.go b/internal/api/client/account/statuses.go index 4841d86d..ab1d4e2e 100644 --- a/internal/api/client/account/statuses.go +++ b/internal/api/client/account/statuses.go @@ -19,6 +19,7 @@ package account import ( + "github.com/sirupsen/logrus" "net/http" "strconv" @@ -96,7 +97,7 @@ import ( // '404': // description: not found func (m *Module) AccountStatusesGETHandler(c *gin.Context) { - l := m.log.WithField("func", "AccountStatusesGETHandler") + l := logrus.WithField("func", "AccountStatusesGETHandler") authed, err := oauth.Authed(c, false, false, false, false) if err != nil { diff --git a/internal/api/client/account/unfollow.go b/internal/api/client/account/unfollow.go index 7ac9697d..b18903c8 100644 --- a/internal/api/client/account/unfollow.go +++ b/internal/api/client/account/unfollow.go @@ -19,6 +19,7 @@ package account import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -60,7 +61,7 @@ import ( // '404': // description: not found func (m *Module) AccountUnfollowPOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "AccountUnfollowPOSTHandler") + l := logrus.WithField("func", "AccountUnfollowPOSTHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { l.Debug(err) diff --git a/internal/api/client/admin/admin.go b/internal/api/client/admin/admin.go index eeec5196..35d16213 100644 --- a/internal/api/client/admin/admin.go +++ b/internal/api/client/admin/admin.go @@ -21,7 +21,6 @@ package admin import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -50,15 +49,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new admin module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/admin/domainblockcreate.go b/internal/api/client/admin/domainblockcreate.go index 9ef4c6f9..e1b6bb03 100644 --- a/internal/api/client/admin/domainblockcreate.go +++ b/internal/api/client/admin/domainblockcreate.go @@ -90,7 +90,7 @@ import ( // '400': // description: bad request func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DomainBlocksPOSTHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/admin/domainblockdelete.go b/internal/api/client/admin/domainblockdelete.go index 64e4ef6d..9c6f97ca 100644 --- a/internal/api/client/admin/domainblockdelete.go +++ b/internal/api/client/admin/domainblockdelete.go @@ -42,7 +42,7 @@ import ( // '404': // description: not found func (m *Module) DomainBlockDELETEHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DomainBlockDELETEHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/admin/domainblockget.go b/internal/api/client/admin/domainblockget.go index d23f99a8..b9dabcd8 100644 --- a/internal/api/client/admin/domainblockget.go +++ b/internal/api/client/admin/domainblockget.go @@ -43,7 +43,7 @@ import ( // '404': // description: not found func (m *Module) DomainBlockGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DomainBlockGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/admin/domainblocksget.go b/internal/api/client/admin/domainblocksget.go index dad8250e..979fc4a6 100644 --- a/internal/api/client/admin/domainblocksget.go +++ b/internal/api/client/admin/domainblocksget.go @@ -49,7 +49,7 @@ import ( // '404': // description: not found func (m *Module) DomainBlocksGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DomainBlocksGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/admin/emojicreate.go b/internal/api/client/admin/emojicreate.go index 38928a9d..89325c47 100644 --- a/internal/api/client/admin/emojicreate.go +++ b/internal/api/client/admin/emojicreate.go @@ -74,7 +74,7 @@ import ( // '400': // description: bad request func (m *Module) emojiCreatePOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "emojiCreatePOSTHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/app/app.go b/internal/api/client/app/app.go index 0366ae21..b3df7c38 100644 --- a/internal/api/client/app/app.go +++ b/internal/api/client/app/app.go @@ -21,7 +21,6 @@ package app import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -35,15 +34,13 @@ const BasePath = "/api/v1/apps" type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/app/appcreate.go b/internal/api/client/app/appcreate.go index e4cbc32d..0c9407ae 100644 --- a/internal/api/client/app/appcreate.go +++ b/internal/api/client/app/appcreate.go @@ -20,6 +20,7 @@ package app import ( "fmt" + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -63,7 +64,7 @@ import ( // '500': // description: internal error func (m *Module) AppsPOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "AppsPOSTHandler") + l := logrus.WithField("func", "AppsPOSTHandler") l.Trace("entering AppsPOSTHandler") authed, err := oauth.Authed(c, false, false, false, false) diff --git a/internal/api/client/auth/auth.go b/internal/api/client/auth/auth.go index bcc338ce..c183576f 100644 --- a/internal/api/client/auth/auth.go +++ b/internal/api/client/auth/auth.go @@ -21,7 +21,6 @@ package auth import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -58,17 +57,15 @@ type Module struct { db db.DB server oauth.Server idp oidc.IDP - log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, db db.DB, server oauth.Server, idp oidc.IDP, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, db db.DB, server oauth.Server, idp oidc.IDP) api.ClientModule { return &Module{ config: config, db: db, server: server, idp: idp, - log: log, } } diff --git a/internal/api/client/auth/auth_test.go b/internal/api/client/auth/auth_test.go index bd4ff27f..59a8d7b1 100644 --- a/internal/api/client/auth/auth_test.go +++ b/internal/api/client/auth/auth_test.go @@ -103,7 +103,7 @@ func (suite *AuthTestSuite) SetupTest() { log := logrus.New() log.SetLevel(logrus.TraceLevel) - db, err := bundb.NewBunDBService(context.Background(), suite.config, log) + db, err := bundb.NewBunDBService(context.Background(), suite.config) if err != nil { logrus.Panicf("error creating database connection: %s", err) } @@ -124,7 +124,7 @@ func (suite *AuthTestSuite) SetupTest() { } } - suite.oauthServer = oauth.New(context.Background(), suite.db, log) + suite.oauthServer = oauth.New(context.Background(), suite.db) if err := suite.db.Put(context.Background(), suite.testAccount); err != nil { logrus.Panicf("could not insert test account into db: %s", err) diff --git a/internal/api/client/auth/authorize.go b/internal/api/client/auth/authorize.go index 97285368..6382f473 100644 --- a/internal/api/client/auth/authorize.go +++ b/internal/api/client/auth/authorize.go @@ -21,6 +21,7 @@ package auth import ( "errors" "fmt" + "github.com/sirupsen/logrus" "net/http" "net/url" "strings" @@ -37,7 +38,7 @@ import ( // The idea here is to present an oauth authorize page to the user, with a button // that they have to click to accept. func (m *Module) AuthorizeGETHandler(c *gin.Context) { - l := m.log.WithField("func", "AuthorizeGETHandler") + l := logrus.WithField("func", "AuthorizeGETHandler") s := sessions.Default(c) // UserID will be set in the session by AuthorizePOSTHandler if the caller has already gone through the authentication flow @@ -123,7 +124,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) { // At this point we assume that the user has A) logged in and B) accepted that the app should act for them, // so we should proceed with the authentication flow and generate an oauth token for them if we can. func (m *Module) AuthorizePOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "AuthorizePOSTHandler") + l := logrus.WithField("func", "AuthorizePOSTHandler") s := sessions.Default(c) // We need to retrieve the original form submitted to the authorizeGEThandler, and diff --git a/internal/api/client/auth/middleware.go b/internal/api/client/auth/middleware.go index 3599c704..1b84458b 100644 --- a/internal/api/client/auth/middleware.go +++ b/internal/api/client/auth/middleware.go @@ -20,6 +20,7 @@ package auth import ( "github.com/gin-gonic/gin" + "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/oauth" @@ -31,7 +32,7 @@ import ( // If user or account can't be found, then the handler won't *fail*, in case the server wants to allow // public requests that don't have a Bearer token set (eg., for public instance information and so on). func (m *Module) OauthTokenMiddleware(c *gin.Context) { - l := m.log.WithField("func", "OauthTokenMiddleware") + l := logrus.WithField("func", "OauthTokenMiddleware") l.Trace("entering OauthTokenMiddleware") ti, err := m.server.ValidationBearerToken(c.Copy().Request) diff --git a/internal/api/client/auth/signin.go b/internal/api/client/auth/signin.go index 6b8bb93d..68944226 100644 --- a/internal/api/client/auth/signin.go +++ b/internal/api/client/auth/signin.go @@ -21,6 +21,7 @@ package auth import ( "context" "errors" + "github.com/sirupsen/logrus" "net/http" "github.com/gin-contrib/sessions" @@ -40,7 +41,7 @@ type login struct { // The idea is to present a sign in page to the user, where they can enter their username and password. // The form will then POST to the sign in page, which will be handled by SignInPOSTHandler func (m *Module) SignInGETHandler(c *gin.Context) { - l := m.log.WithField("func", "SignInGETHandler") + l := logrus.WithField("func", "SignInGETHandler") l.Trace("entering sign in handler") if m.idp != nil { s := sessions.Default(c) @@ -65,7 +66,7 @@ func (m *Module) SignInGETHandler(c *gin.Context) { // The idea is to present a sign in page to the user, where they can enter their username and password. // The handler will then redirect to the auth handler served at /auth func (m *Module) SignInPOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "SignInPOSTHandler") + l := logrus.WithField("func", "SignInPOSTHandler") s := sessions.Default(c) form := &login{} if err := c.ShouldBind(form); err != nil { @@ -98,7 +99,7 @@ func (m *Module) SignInPOSTHandler(c *gin.Context) { // address stored in the database. If OK, we return the userid (a ulid) for that user, // so that it can be used in further Oauth flows to generate a token/retreieve an oauth client from the db. func (m *Module) ValidatePassword(ctx context.Context, email string, password string) (userid string, err error) { - l := m.log.WithField("func", "ValidatePassword") + l := logrus.WithField("func", "ValidatePassword") // make sure an email/password was provided and bail if not if email == "" || password == "" { diff --git a/internal/api/client/auth/token.go b/internal/api/client/auth/token.go index f9009767..f24840c9 100644 --- a/internal/api/client/auth/token.go +++ b/internal/api/client/auth/token.go @@ -19,6 +19,7 @@ package auth import ( + "github.com/sirupsen/logrus" "net/http" "net/url" @@ -37,7 +38,7 @@ type tokenBody struct { // TokenPOSTHandler should be served as a POST at https://example.org/oauth/token // The idea here is to serve an oauth access token to a user, which can be used for authorizing against non-public APIs. func (m *Module) TokenPOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "TokenPOSTHandler") + l := logrus.WithField("func", "TokenPOSTHandler") l.Trace("entered TokenPOSTHandler") form := &tokenBody{} diff --git a/internal/api/client/blocks/blocks.go b/internal/api/client/blocks/blocks.go index de87e892..531dfa8d 100644 --- a/internal/api/client/blocks/blocks.go +++ b/internal/api/client/blocks/blocks.go @@ -21,7 +21,6 @@ package blocks import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -44,15 +43,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new blocks module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/blocks/blocksget.go b/internal/api/client/blocks/blocksget.go index b6c9c39e..b00a6e19 100644 --- a/internal/api/client/blocks/blocksget.go +++ b/internal/api/client/blocks/blocksget.go @@ -19,6 +19,7 @@ package blocks import ( + "github.com/sirupsen/logrus" "net/http" "strconv" @@ -84,7 +85,7 @@ import ( // '404': // description: not found func (m *Module) BlocksGETHandler(c *gin.Context) { - l := m.log.WithField("func", "PublicTimelineGETHandler") + l := logrus.WithField("func", "PublicTimelineGETHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/emoji/emoji.go b/internal/api/client/emoji/emoji.go index f3081617..4c69fbcc 100644 --- a/internal/api/client/emoji/emoji.go +++ b/internal/api/client/emoji/emoji.go @@ -21,7 +21,6 @@ package emoji import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -37,15 +36,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new emoji module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/favourites/favourites.go b/internal/api/client/favourites/favourites.go index e083f32f..daaab82f 100644 --- a/internal/api/client/favourites/favourites.go +++ b/internal/api/client/favourites/favourites.go @@ -21,7 +21,6 @@ package favourites import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -48,15 +47,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new favourites module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/favourites/favouritesget.go b/internal/api/client/favourites/favouritesget.go index 6984ea75..22ed03b3 100644 --- a/internal/api/client/favourites/favouritesget.go +++ b/internal/api/client/favourites/favouritesget.go @@ -1,6 +1,7 @@ package favourites import ( + "github.com/sirupsen/logrus" "net/http" "strconv" @@ -10,7 +11,7 @@ import ( // FavouritesGETHandler handles GETting favourites. func (m *Module) FavouritesGETHandler(c *gin.Context) { - l := m.log.WithField("func", "PublicTimelineGETHandler") + l := logrus.WithField("func", "PublicTimelineGETHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/fileserver/fileserver.go b/internal/api/client/fileserver/fileserver.go index 61286c17..e6010568 100644 --- a/internal/api/client/fileserver/fileserver.go +++ b/internal/api/client/fileserver/fileserver.go @@ -22,7 +22,6 @@ import ( "fmt" "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -45,16 +44,14 @@ const ( type FileServer struct { config *config.Config processor processing.Processor - log *logrus.Logger storageBase string } // New returns a new fileServer module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &FileServer{ config: config, processor: processor, - log: log, storageBase: config.StorageConfig.ServeBasePath, } } diff --git a/internal/api/client/fileserver/servefile.go b/internal/api/client/fileserver/servefile.go index 130a16c4..0840f1d9 100644 --- a/internal/api/client/fileserver/servefile.go +++ b/internal/api/client/fileserver/servefile.go @@ -33,7 +33,7 @@ import ( // Note: to mitigate scraping attempts, no information should be given out on a bad request except "404 page not found". // Don't give away account ids or media ids or anything like that; callers shouldn't be able to infer anything. func (m *FileServer) ServeFile(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "ServeFile", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/fileserver/servefile_test.go b/internal/api/client/fileserver/servefile_test.go index 6d5f2d39..60f9740b 100644 --- a/internal/api/client/fileserver/servefile_test.go +++ b/internal/api/client/fileserver/servefile_test.go @@ -48,7 +48,6 @@ type ServeFileTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger storage *kv.KVStore federator federation.Federator tc typeutils.TypeConverter @@ -76,7 +75,7 @@ func (suite *ServeFileTestSuite) SetupSuite() { // setup standard items suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.storage = testrig.NewTestStorage() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) @@ -85,7 +84,7 @@ func (suite *ServeFileTestSuite) SetupSuite() { suite.oauthServer = testrig.NewTestOauthServer(suite.db) // setup module being tested - suite.fileServer = fileserver.New(suite.config, suite.processor, suite.log).(*fileserver.FileServer) + suite.fileServer = fileserver.New(suite.config, suite.processor).(*fileserver.FileServer) } func (suite *ServeFileTestSuite) TearDownSuite() { diff --git a/internal/api/client/filter/filter.go b/internal/api/client/filter/filter.go index 1a8421d2..2ec53bd0 100644 --- a/internal/api/client/filter/filter.go +++ b/internal/api/client/filter/filter.go @@ -21,7 +21,6 @@ package filter import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -37,15 +36,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new filter module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/followrequest/accept.go b/internal/api/client/followrequest/accept.go index 3dba7673..6f5613f3 100644 --- a/internal/api/client/followrequest/accept.go +++ b/internal/api/client/followrequest/accept.go @@ -19,6 +19,7 @@ package followrequest import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -28,7 +29,7 @@ import ( // FollowRequestAcceptPOSTHandler deals with follow request accepting. It should be served at // /api/v1/follow_requests/:id/authorize func (m *Module) FollowRequestAcceptPOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "statusCreatePOSTHandler") + l := logrus.WithField("func", "statusCreatePOSTHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/followrequest/followrequest.go b/internal/api/client/followrequest/followrequest.go index 71352294..beedeb2d 100644 --- a/internal/api/client/followrequest/followrequest.go +++ b/internal/api/client/followrequest/followrequest.go @@ -21,7 +21,6 @@ package followrequest import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -47,15 +46,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new follow request module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/followrequest/get.go b/internal/api/client/followrequest/get.go index 47e1d74b..a07e3ad8 100644 --- a/internal/api/client/followrequest/get.go +++ b/internal/api/client/followrequest/get.go @@ -19,6 +19,7 @@ package followrequest import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -27,7 +28,7 @@ import ( // FollowRequestGETHandler allows clients to get a list of their incoming follow requests. func (m *Module) FollowRequestGETHandler(c *gin.Context) { - l := m.log.WithField("func", "statusCreatePOSTHandler") + l := logrus.WithField("func", "statusCreatePOSTHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/instance/instance.go b/internal/api/client/instance/instance.go index a5becf97..33e0054c 100644 --- a/internal/api/client/instance/instance.go +++ b/internal/api/client/instance/instance.go @@ -3,7 +3,6 @@ package instance import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -19,15 +18,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new instance information module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/instance/instanceget.go b/internal/api/client/instance/instanceget.go index 0a6d1715..fac917b2 100644 --- a/internal/api/client/instance/instanceget.go +++ b/internal/api/client/instance/instanceget.go @@ -1,6 +1,7 @@ package instance import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -29,7 +30,7 @@ import ( // '500': // description: internal error func (m *Module) InstanceInformationGETHandler(c *gin.Context) { - l := m.log.WithField("func", "InstanceInformationGETHandler") + l := logrus.WithField("func", "InstanceInformationGETHandler") instance, err := m.processor.InstanceGet(c.Request.Context(), m.config.Host) if err != nil { diff --git a/internal/api/client/instance/instancepatch.go b/internal/api/client/instance/instancepatch.go index fa37ccd8..50923dd9 100644 --- a/internal/api/client/instance/instancepatch.go +++ b/internal/api/client/instance/instancepatch.go @@ -1,6 +1,7 @@ package instance import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -84,7 +85,7 @@ import ( // '400': // description: bad request func (m *Module) InstanceUpdatePATCHHandler(c *gin.Context) { - l := m.log.WithField("func", "InstanceUpdatePATCHHandler") + l := logrus.WithField("func", "InstanceUpdatePATCHHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/list/list.go b/internal/api/client/list/list.go index 4f800a46..106682ca 100644 --- a/internal/api/client/list/list.go +++ b/internal/api/client/list/list.go @@ -21,7 +21,6 @@ package list import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -37,15 +36,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new list module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/media/media.go b/internal/api/client/media/media.go index 1e9e8fda..a051dea4 100644 --- a/internal/api/client/media/media.go +++ b/internal/api/client/media/media.go @@ -21,7 +21,6 @@ package media import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -41,15 +40,13 @@ const BasePathWithID = BasePath + "/:" + IDKey type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/media/mediacreate.go b/internal/api/client/media/mediacreate.go index 68b25039..5b7a2dea 100644 --- a/internal/api/client/media/mediacreate.go +++ b/internal/api/client/media/mediacreate.go @@ -21,6 +21,7 @@ package media import ( "errors" "fmt" + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -82,7 +83,7 @@ import ( // '422': // description: unprocessable func (m *Module) MediaCreatePOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "statusCreatePOSTHandler") + l := logrus.WithField("func", "statusCreatePOSTHandler") authed, err := oauth.Authed(c, true, true, true, true) // posting new media is serious business so we want *everything* if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/media/mediacreate_test.go b/internal/api/client/media/mediacreate_test.go index 9ba05984..1ee58e79 100644 --- a/internal/api/client/media/mediacreate_test.go +++ b/internal/api/client/media/mediacreate_test.go @@ -51,7 +51,6 @@ type MediaCreateTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger storage *kv.KVStore federator federation.Federator tc typeutils.TypeConverter @@ -79,7 +78,7 @@ func (suite *MediaCreateTestSuite) SetupSuite() { // setup standard items suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.storage = testrig.NewTestStorage() suite.tc = testrig.NewTestTypeConverter(suite.db) suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) @@ -88,7 +87,7 @@ func (suite *MediaCreateTestSuite) SetupSuite() { suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) // setup module being tested - suite.mediaModule = mediamodule.New(suite.config, suite.processor, suite.log).(*mediamodule.Module) + suite.mediaModule = mediamodule.New(suite.config, suite.processor).(*mediamodule.Module) } func (suite *MediaCreateTestSuite) TearDownSuite() { diff --git a/internal/api/client/media/mediaget.go b/internal/api/client/media/mediaget.go index 5fd7856e..0ddccc4e 100644 --- a/internal/api/client/media/mediaget.go +++ b/internal/api/client/media/mediaget.go @@ -19,6 +19,7 @@ package media import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -61,7 +62,7 @@ import ( // '422': // description: unprocessable func (m *Module) MediaGETHandler(c *gin.Context) { - l := m.log.WithField("func", "MediaGETHandler") + l := logrus.WithField("func", "MediaGETHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/media/mediaupdate.go b/internal/api/client/media/mediaupdate.go index 3af19297..2a6d056b 100644 --- a/internal/api/client/media/mediaupdate.go +++ b/internal/api/client/media/mediaupdate.go @@ -21,6 +21,7 @@ package media import ( "errors" "fmt" + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -91,7 +92,7 @@ import ( // '422': // description: unprocessable func (m *Module) MediaPUTHandler(c *gin.Context) { - l := m.log.WithField("func", "MediaGETHandler") + l := logrus.WithField("func", "MediaGETHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/notification/notification.go b/internal/api/client/notification/notification.go index 758fe505..04a1c290 100644 --- a/internal/api/client/notification/notification.go +++ b/internal/api/client/notification/notification.go @@ -21,7 +21,6 @@ package notification import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -49,15 +48,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new notification module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/notification/notificationsget.go b/internal/api/client/notification/notificationsget.go index 81e8a689..98d5c247 100644 --- a/internal/api/client/notification/notificationsget.go +++ b/internal/api/client/notification/notificationsget.go @@ -29,7 +29,7 @@ import ( // NotificationsGETHandler serves a list of notifications to the caller, with the desired query parameters func (m *Module) NotificationsGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "NotificationsGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/search/search.go b/internal/api/client/search/search.go index 1cffee5e..474cccb2 100644 --- a/internal/api/client/search/search.go +++ b/internal/api/client/search/search.go @@ -21,7 +21,6 @@ package search import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -68,15 +67,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new search module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/search/searchget.go b/internal/api/client/search/searchget.go index 84891527..f842e504 100644 --- a/internal/api/client/search/searchget.go +++ b/internal/api/client/search/searchget.go @@ -56,7 +56,7 @@ import ( // '400': // description: bad request func (m *Module) SearchGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "SearchGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/status.go b/internal/api/client/status/status.go index dec6bebc..cf6687ef 100644 --- a/internal/api/client/status/status.go +++ b/internal/api/client/status/status.go @@ -19,11 +19,11 @@ package status import ( + "github.com/sirupsen/logrus" "net/http" "strings" "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -76,15 +76,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new account module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } @@ -109,7 +107,7 @@ func (m *Module) Route(r router.Router) error { // muxHandler is a little workaround to overcome the limitations of Gin func (m *Module) muxHandler(c *gin.Context) { - m.log.Debug("entering mux handler") + logrus.Debug("entering mux handler") ru := c.Request.RequestURI switch c.Request.Method { diff --git a/internal/api/client/status/status_test.go b/internal/api/client/status/status_test.go index 214a0079..0c0c391b 100644 --- a/internal/api/client/status/status_test.go +++ b/internal/api/client/status/status_test.go @@ -20,7 +20,6 @@ package status_test import ( "git.iim.gay/grufwub/go-store/kv" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/client/status" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -37,7 +36,6 @@ type StatusStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter federator federation.Federator processor processing.Processor diff --git a/internal/api/client/status/statusboost.go b/internal/api/client/status/statusboost.go index 6a1ccde2..bc950d35 100644 --- a/internal/api/client/status/statusboost.go +++ b/internal/api/client/status/statusboost.go @@ -66,7 +66,7 @@ import ( // '404': // description: not found func (m *Module) StatusBoostPOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusBoostPOSTHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statusboost_test.go b/internal/api/client/status/statusboost_test.go index 4157bde3..2a8db1f4 100644 --- a/internal/api/client/status/statusboost_test.go +++ b/internal/api/client/status/statusboost_test.go @@ -51,10 +51,10 @@ func (suite *StatusBoostTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.statusModule = status.New(suite.config, suite.processor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.processor).(*status.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/client/status/statusboostedby.go b/internal/api/client/status/statusboostedby.go index a1446aef..79783dfb 100644 --- a/internal/api/client/status/statusboostedby.go +++ b/internal/api/client/status/statusboostedby.go @@ -63,7 +63,7 @@ import ( // '404': // description: not found func (m *Module) StatusBoostedByGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusBoostedByGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statuscontext.go b/internal/api/client/status/statuscontext.go index 90fcb960..f9d7fcc3 100644 --- a/internal/api/client/status/statuscontext.go +++ b/internal/api/client/status/statuscontext.go @@ -65,7 +65,7 @@ import ( // '404': // description: not found func (m *Module) StatusContextGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusContextGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statuscreate.go b/internal/api/client/status/statuscreate.go index cae11ebd..e9d92890 100644 --- a/internal/api/client/status/statuscreate.go +++ b/internal/api/client/status/statuscreate.go @@ -21,6 +21,7 @@ package status import ( "errors" "fmt" + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -67,7 +68,7 @@ import ( // '500': // description: internal error func (m *Module) StatusCreatePOSTHandler(c *gin.Context) { - l := m.log.WithField("func", "statusCreatePOSTHandler") + l := logrus.WithField("func", "statusCreatePOSTHandler") authed, err := oauth.Authed(c, true, true, true, true) // posting a status is serious business so we want *everything* if err != nil { l.Debugf("couldn't auth: %s", err) diff --git a/internal/api/client/status/statuscreate_test.go b/internal/api/client/status/statuscreate_test.go index 084f1a6f..e7c1125c 100644 --- a/internal/api/client/status/statuscreate_test.go +++ b/internal/api/client/status/statuscreate_test.go @@ -57,11 +57,11 @@ func (suite *StatusCreateTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.tc = testrig.NewTestTypeConverter(suite.db) suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.statusModule = status.New(suite.config, suite.processor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.processor).(*status.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/client/status/statusdelete.go b/internal/api/client/status/statusdelete.go index 1914a1a0..5a6b2928 100644 --- a/internal/api/client/status/statusdelete.go +++ b/internal/api/client/status/statusdelete.go @@ -65,7 +65,7 @@ import ( // '404': // description: not found func (m *Module) StatusDELETEHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusDELETEHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statusfave.go b/internal/api/client/status/statusfave.go index 94d93098..7d487983 100644 --- a/internal/api/client/status/statusfave.go +++ b/internal/api/client/status/statusfave.go @@ -62,7 +62,7 @@ import ( // '404': // description: not found func (m *Module) StatusFavePOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusFavePOSTHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statusfave_test.go b/internal/api/client/status/statusfave_test.go index 2f7a2c59..3fafe44e 100644 --- a/internal/api/client/status/statusfave_test.go +++ b/internal/api/client/status/statusfave_test.go @@ -54,10 +54,10 @@ func (suite *StatusFaveTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.statusModule = status.New(suite.config, suite.processor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.processor).(*status.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/client/status/statusfavedby.go b/internal/api/client/status/statusfavedby.go index 4ed6e74e..4de66d65 100644 --- a/internal/api/client/status/statusfavedby.go +++ b/internal/api/client/status/statusfavedby.go @@ -63,7 +63,7 @@ import ( // '404': // description: not found func (m *Module) StatusFavedByGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "statusGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statusfavedby_test.go b/internal/api/client/status/statusfavedby_test.go index 7475f1e6..2958379f 100644 --- a/internal/api/client/status/statusfavedby_test.go +++ b/internal/api/client/status/statusfavedby_test.go @@ -54,10 +54,10 @@ func (suite *StatusFavedByTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.statusModule = status.New(suite.config, suite.processor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.processor).(*status.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/client/status/statusget.go b/internal/api/client/status/statusget.go index 3c74b53c..b246002d 100644 --- a/internal/api/client/status/statusget.go +++ b/internal/api/client/status/statusget.go @@ -62,7 +62,7 @@ import ( // '500': // description: internal error func (m *Module) StatusGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "statusGETHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statusget_test.go b/internal/api/client/status/statusget_test.go index fa5f786c..17326b46 100644 --- a/internal/api/client/status/statusget_test.go +++ b/internal/api/client/status/statusget_test.go @@ -44,10 +44,10 @@ func (suite *StatusGetTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.statusModule = status.New(suite.config, suite.processor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.processor).(*status.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/client/status/statusunboost.go b/internal/api/client/status/statusunboost.go index f114dbd0..7ddb274e 100644 --- a/internal/api/client/status/statusunboost.go +++ b/internal/api/client/status/statusunboost.go @@ -63,7 +63,7 @@ import ( // '404': // description: not found func (m *Module) StatusUnboostPOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusUnboostPOSTHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statusunfave.go b/internal/api/client/status/statusunfave.go index 3689e189..29d3daa4 100644 --- a/internal/api/client/status/statusunfave.go +++ b/internal/api/client/status/statusunfave.go @@ -62,7 +62,7 @@ import ( // '404': // description: not found func (m *Module) StatusUnfavePOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusUnfavePOSTHandler", "request_uri": c.Request.RequestURI, "user_agent": c.Request.UserAgent(), diff --git a/internal/api/client/status/statusunfave_test.go b/internal/api/client/status/statusunfave_test.go index 9e7ea8f8..e99569e0 100644 --- a/internal/api/client/status/statusunfave_test.go +++ b/internal/api/client/status/statusunfave_test.go @@ -54,10 +54,10 @@ func (suite *StatusUnfaveTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.statusModule = status.New(suite.config, suite.processor, suite.log).(*status.Module) + suite.statusModule = status.New(suite.config, suite.processor).(*status.Module) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/client/streaming/stream.go b/internal/api/client/streaming/stream.go index 4a9dcfe5..c01bf221 100644 --- a/internal/api/client/streaming/stream.go +++ b/internal/api/client/streaming/stream.go @@ -2,6 +2,7 @@ package streaming import ( "fmt" + "github.com/sirupsen/logrus" "net/http" "time" @@ -107,7 +108,7 @@ import ( // '400': // description: bad request func (m *Module) StreamGETHandler(c *gin.Context) { - l := m.log.WithField("func", "StreamGETHandler") + l := logrus.WithField("func", "StreamGETHandler") streamType := c.Query(StreamQueryKey) if streamType == "" { diff --git a/internal/api/client/streaming/streaming.go b/internal/api/client/streaming/streaming.go index 92dfccde..fd52419e 100644 --- a/internal/api/client/streaming/streaming.go +++ b/internal/api/client/streaming/streaming.go @@ -21,7 +21,6 @@ package streaming import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -43,15 +42,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new streaming module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/client/timeline/home.go b/internal/api/client/timeline/home.go index 6df4b29d..ef5aa48b 100644 --- a/internal/api/client/timeline/home.go +++ b/internal/api/client/timeline/home.go @@ -19,6 +19,7 @@ package timeline import ( + "github.com/sirupsen/logrus" "net/http" "strconv" @@ -102,7 +103,7 @@ import ( // '400': // description: bad request func (m *Module) HomeTimelineGETHandler(c *gin.Context) { - l := m.log.WithField("func", "HomeTimelineGETHandler") + l := logrus.WithField("func", "HomeTimelineGETHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/timeline/public.go b/internal/api/client/timeline/public.go index 8c8c9f12..049078e4 100644 --- a/internal/api/client/timeline/public.go +++ b/internal/api/client/timeline/public.go @@ -19,6 +19,7 @@ package timeline import ( + "github.com/sirupsen/logrus" "net/http" "strconv" @@ -102,7 +103,7 @@ import ( // '400': // description: bad request func (m *Module) PublicTimelineGETHandler(c *gin.Context) { - l := m.log.WithField("func", "PublicTimelineGETHandler") + l := logrus.WithField("func", "PublicTimelineGETHandler") authed, err := oauth.Authed(c, true, true, true, true) if err != nil { diff --git a/internal/api/client/timeline/timeline.go b/internal/api/client/timeline/timeline.go index 72c9357b..2aa939f6 100644 --- a/internal/api/client/timeline/timeline.go +++ b/internal/api/client/timeline/timeline.go @@ -21,7 +21,6 @@ package timeline import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -51,15 +50,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new timeline module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/s2s/nodeinfo/nodeinfo.go b/internal/api/s2s/nodeinfo/nodeinfo.go index 85617f52..5d1d03b2 100644 --- a/internal/api/s2s/nodeinfo/nodeinfo.go +++ b/internal/api/s2s/nodeinfo/nodeinfo.go @@ -21,7 +21,6 @@ package nodeinfo import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -39,15 +38,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new nodeinfo module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor) api.FederationModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/s2s/nodeinfo/nodeinfoget.go b/internal/api/s2s/nodeinfo/nodeinfoget.go index c362e1d2..547aa2cf 100644 --- a/internal/api/s2s/nodeinfo/nodeinfoget.go +++ b/internal/api/s2s/nodeinfo/nodeinfoget.go @@ -28,7 +28,7 @@ import ( // NodeInfoGETHandler returns a compliant nodeinfo response to node info queries. // See: https://nodeinfo.diaspora.software/ func (m *Module) NodeInfoGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "NodeInfoGETHandler", "user-agent": c.Request.UserAgent(), }) diff --git a/internal/api/s2s/nodeinfo/wellknownget.go b/internal/api/s2s/nodeinfo/wellknownget.go index fd2c8440..e5aa39aa 100644 --- a/internal/api/s2s/nodeinfo/wellknownget.go +++ b/internal/api/s2s/nodeinfo/wellknownget.go @@ -28,7 +28,7 @@ import ( // NodeInfoWellKnownGETHandler returns a well known response to a query to /.well-known/nodeinfo, // directing (but not redirecting...) callers to the NodeInfoGETHandler. func (m *Module) NodeInfoWellKnownGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "NodeInfoWellKnownGETHandler", "user-agent": c.Request.UserAgent(), }) diff --git a/internal/api/s2s/user/followers.go b/internal/api/s2s/user/followers.go index 63d43db9..288e60f3 100644 --- a/internal/api/s2s/user/followers.go +++ b/internal/api/s2s/user/followers.go @@ -29,7 +29,7 @@ import ( // FollowersGETHandler returns a collection of URIs for followers of the target user, formatted so that other AP servers can understand it. func (m *Module) FollowersGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "FollowersGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/following.go b/internal/api/s2s/user/following.go index 3a3e1146..6c7b60d3 100644 --- a/internal/api/s2s/user/following.go +++ b/internal/api/s2s/user/following.go @@ -29,7 +29,7 @@ import ( // FollowingGETHandler returns a collection of URIs for accounts that the target user follows, formatted so that other AP servers can understand it. func (m *Module) FollowingGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "FollowingGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/inboxpost.go b/internal/api/s2s/user/inboxpost.go index d59555e1..c2992bff 100644 --- a/internal/api/s2s/user/inboxpost.go +++ b/internal/api/s2s/user/inboxpost.go @@ -29,7 +29,7 @@ import ( // InboxPOSTHandler deals with incoming POST requests to an actor's inbox. // Eg., POST to https://example.org/users/whatever/inbox. func (m *Module) InboxPOSTHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "InboxPOSTHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/inboxpost_test.go b/internal/api/s2s/user/inboxpost_test.go index 94b3e650..79c44116 100644 --- a/internal/api/s2s/user/inboxpost_test.go +++ b/internal/api/s2s/user/inboxpost_test.go @@ -86,7 +86,7 @@ func (suite *InboxPostTestSuite) TestPostBlock() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -185,7 +185,7 @@ func (suite *InboxPostTestSuite) TestPostUnblock() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -274,7 +274,7 @@ func (suite *InboxPostTestSuite) TestPostUpdate() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -394,7 +394,7 @@ func (suite *InboxPostTestSuite) TestPostDelete() { processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) err = processor.Start(context.Background()) suite.NoError(err) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() diff --git a/internal/api/s2s/user/publickeyget.go b/internal/api/s2s/user/publickeyget.go index 8b9d3aa0..bf711683 100644 --- a/internal/api/s2s/user/publickeyget.go +++ b/internal/api/s2s/user/publickeyget.go @@ -33,7 +33,7 @@ import ( // in the form of a vocab.ActivityStreamsPerson. The account will only contain the id, // public key, username, and type of the account. func (m *Module) PublicKeyGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "PublicKeyGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/repliesget.go b/internal/api/s2s/user/repliesget.go index 13b9061e..b24dead3 100644 --- a/internal/api/s2s/user/repliesget.go +++ b/internal/api/s2s/user/repliesget.go @@ -85,7 +85,7 @@ import ( // '404': // description: not found func (m *Module) StatusRepliesGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusRepliesGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/repliesget_test.go b/internal/api/s2s/user/repliesget_test.go index f8e83374..44717ad4 100644 --- a/internal/api/s2s/user/repliesget_test.go +++ b/internal/api/s2s/user/repliesget_test.go @@ -50,7 +50,7 @@ func (suite *RepliesGetTestSuite) TestGetReplies() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -109,7 +109,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesNext() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() @@ -171,7 +171,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesLast() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() diff --git a/internal/api/s2s/user/statusget.go b/internal/api/s2s/user/statusget.go index 74615424..91c29e3c 100644 --- a/internal/api/s2s/user/statusget.go +++ b/internal/api/s2s/user/statusget.go @@ -29,7 +29,7 @@ import ( // StatusGETHandler serves the target status as an activitystreams NOTE so that other AP servers can parse it. func (m *Module) StatusGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/user.go b/internal/api/s2s/user/user.go index cd57ab14..ef0057f9 100644 --- a/internal/api/s2s/user/user.go +++ b/internal/api/s2s/user/user.go @@ -21,7 +21,6 @@ package user import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -65,15 +64,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new auth module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor) api.FederationModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/s2s/user/user_test.go b/internal/api/s2s/user/user_test.go index 86aa0bdf..26852372 100644 --- a/internal/api/s2s/user/user_test.go +++ b/internal/api/s2s/user/user_test.go @@ -20,7 +20,6 @@ package user_test import ( "git.iim.gay/grufwub/go-store/kv" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/user" "github.com/superseriousbusiness/gotosocial/internal/api/security" @@ -38,7 +37,6 @@ type UserStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter federator federation.Federator processor processing.Processor @@ -75,11 +73,11 @@ func (suite *UserStandardTestSuite) SetupTest() { suite.db = testrig.NewTestDB() suite.tc = testrig.NewTestTypeConverter(suite.db) suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.userModule = user.New(suite.config, suite.processor, suite.log).(*user.Module) - suite.securityModule = security.New(suite.config, suite.db, suite.log).(*security.Module) + suite.userModule = user.New(suite.config, suite.processor).(*user.Module) + suite.securityModule = security.New(suite.config, suite.db).(*security.Module) testrig.StandardDBSetup(suite.db, suite.testAccounts) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/s2s/user/userget.go b/internal/api/s2s/user/userget.go index 105ffd7b..2af692b3 100644 --- a/internal/api/s2s/user/userget.go +++ b/internal/api/s2s/user/userget.go @@ -37,7 +37,7 @@ import ( // And of course, the request should be refused if the account or server making the // request is blocked. func (m *Module) UsersGETHandler(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "UsersGETHandler", "url": c.Request.RequestURI, }) diff --git a/internal/api/s2s/user/userget_test.go b/internal/api/s2s/user/userget_test.go index f560125c..d8d1df14 100644 --- a/internal/api/s2s/user/userget_test.go +++ b/internal/api/s2s/user/userget_test.go @@ -48,7 +48,7 @@ func (suite *UserGetTestSuite) TestGetUser() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) federator := testrig.NewTestFederator(suite.db, tc, suite.storage) processor := testrig.NewTestProcessor(suite.db, suite.storage, federator) - userModule := user.New(suite.config, processor, suite.log).(*user.Module) + userModule := user.New(suite.config, processor).(*user.Module) // setup request recorder := httptest.NewRecorder() diff --git a/internal/api/s2s/webfinger/webfinger.go b/internal/api/s2s/webfinger/webfinger.go index 6d48dc80..c447d730 100644 --- a/internal/api/s2s/webfinger/webfinger.go +++ b/internal/api/s2s/webfinger/webfinger.go @@ -21,7 +21,6 @@ package webfinger import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/processing" @@ -37,15 +36,13 @@ const ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new webfinger module -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.FederationModule { +func New(config *config.Config, processor processing.Processor) api.FederationModule { return &Module{ config: config, processor: processor, - log: log, } } diff --git a/internal/api/s2s/webfinger/webfinger_test.go b/internal/api/s2s/webfinger/webfinger_test.go index 5c8dfd2f..ee1ff660 100644 --- a/internal/api/s2s/webfinger/webfinger_test.go +++ b/internal/api/s2s/webfinger/webfinger_test.go @@ -24,7 +24,6 @@ import ( "time" "git.iim.gay/grufwub/go-store/kv" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger" @@ -43,7 +42,6 @@ type WebfingerStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter federator federation.Federator processor processing.Processor @@ -78,11 +76,11 @@ func (suite *WebfingerStandardTestSuite) SetupTest() { suite.db = testrig.NewTestDB() suite.tc = testrig.NewTestTypeConverter(suite.db) suite.storage = testrig.NewTestStorage() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage) suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator) - suite.webfingerModule = webfinger.New(suite.config, suite.processor, suite.log).(*webfinger.Module) - suite.securityModule = security.New(suite.config, suite.db, suite.log).(*security.Module) + suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module) + suite.securityModule = security.New(suite.config, suite.db).(*security.Module) testrig.StandardDBSetup(suite.db, suite.testAccounts) testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media") } diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go index 01e5e8e8..3552394f 100644 --- a/internal/api/s2s/webfinger/webfingerget.go +++ b/internal/api/s2s/webfinger/webfingerget.go @@ -31,7 +31,7 @@ import ( // WebfingerGETRequest handles requests to, for example, https://example.org/.well-known/webfinger?resource=acct:some_user@example.org func (m *Module) WebfingerGETRequest(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "WebfingerGETRequest", "user-agent": c.Request.UserAgent(), }) diff --git a/internal/api/s2s/webfinger/webfingerget_test.go b/internal/api/s2s/webfinger/webfingerget_test.go index b5de5d88..3b38c5a7 100644 --- a/internal/api/s2s/webfinger/webfingerget_test.go +++ b/internal/api/s2s/webfinger/webfingerget_test.go @@ -65,8 +65,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUser() { func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHost() { suite.config.Host = "gts.example.org" suite.config.AccountDomain = "example.org" - suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.log) - suite.webfingerModule = webfinger.New(suite.config, suite.processor, suite.log).(*webfinger.Module) + suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db) + suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module) targetAccount := accountDomainAccount() if err := suite.db.Put(context.Background(), targetAccount); err != nil { @@ -97,8 +97,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHo func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByAccountDomain() { suite.config.Host = "gts.example.org" suite.config.AccountDomain = "example.org" - suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.log) - suite.webfingerModule = webfinger.New(suite.config, suite.processor, suite.log).(*webfinger.Module) + suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db) + suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module) targetAccount := accountDomainAccount() if err := suite.db.Put(context.Background(), targetAccount); err != nil { diff --git a/internal/api/security/security.go b/internal/api/security/security.go index d8f6b0fe..5ed67746 100644 --- a/internal/api/security/security.go +++ b/internal/api/security/security.go @@ -21,7 +21,6 @@ package security import ( "net/http" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/api" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -33,15 +32,13 @@ const robotsPath = "/robots.txt" // Module implements the ClientAPIModule interface for security middleware type Module struct { config *config.Config - log *logrus.Logger db db.DB } // New returns a new security module -func New(config *config.Config, db db.DB, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, db db.DB) api.ClientModule { return &Module{ config: config, - log: log, db: db, } } diff --git a/internal/api/security/signaturecheck.go b/internal/api/security/signaturecheck.go index be8c87c0..a0f79e44 100644 --- a/internal/api/security/signaturecheck.go +++ b/internal/api/security/signaturecheck.go @@ -1,6 +1,7 @@ package security import ( + "github.com/sirupsen/logrus" "net/http" "net/url" @@ -13,7 +14,7 @@ import ( // that signed the request is permitted to access the server. If it is permitted, the handler will set the key // verifier and the signature in the gin context for use down the line. func (m *Module) SignatureCheck(c *gin.Context) { - l := m.log.WithField("func", "DomainBlockChecker") + l := logrus.WithField("func", "DomainBlockChecker") // create the verifier from the request // if the request is signed, it will have a signature header diff --git a/internal/api/security/useragentblock.go b/internal/api/security/useragentblock.go index 1498d441..bc958619 100644 --- a/internal/api/security/useragentblock.go +++ b/internal/api/security/useragentblock.go @@ -27,7 +27,7 @@ import ( // UserAgentBlock blocks requests with undesired, empty, or invalid user-agent strings. func (m *Module) UserAgentBlock(c *gin.Context) { - l := m.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "UserAgentBlock", }) diff --git a/internal/cliactions/action.go b/internal/cliactions/action.go index 3ba91de8..b72ae92b 100644 --- a/internal/cliactions/action.go +++ b/internal/cliactions/action.go @@ -21,11 +21,10 @@ package cliactions import ( "context" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" ) // GTSAction defines one *action* that can be taken by the gotosocial cli command. // This can be either a long-running action (like server start) or something // shorter like db init or db inspect. -type GTSAction func(context.Context, *config.Config, *logrus.Logger) error +type GTSAction func(context.Context, *config.Config) error diff --git a/internal/cliactions/admin/account/account.go b/internal/cliactions/admin/account/account.go index e9a113f3..5bdee9a4 100644 --- a/internal/cliactions/admin/account/account.go +++ b/internal/cliactions/admin/account/account.go @@ -24,7 +24,6 @@ import ( "fmt" "time" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/cliactions" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -35,8 +34,8 @@ import ( ) // Create creates a new account in the database using the provided flags. -var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } @@ -74,8 +73,8 @@ var Create cliactions.GTSAction = func(ctx context.Context, c *config.Config, lo } // Confirm sets a user to Approved, sets Email to the current UnconfirmedEmail value, and sets ConfirmedAt to now. -var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } @@ -109,8 +108,8 @@ var Confirm cliactions.GTSAction = func(ctx context.Context, c *config.Config, l } // Promote sets a user to admin. -var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } @@ -141,8 +140,8 @@ var Promote cliactions.GTSAction = func(ctx context.Context, c *config.Config, l } // Demote sets admin on a user to false. -var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } @@ -173,8 +172,8 @@ var Demote cliactions.GTSAction = func(ctx context.Context, c *config.Config, lo } // Disable sets Disabled to true on a user. -var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } @@ -205,14 +204,14 @@ var Disable cliactions.GTSAction = func(ctx context.Context, c *config.Config, l } // Suspend suspends the target account, cleanly removing all of its media, followers, following, likes, statuses, etc. -var Suspend cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { +var Suspend cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { // TODO return nil } // Password sets the password of target account. -var Password cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Password cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } diff --git a/internal/cliactions/admin/trans/export.go b/internal/cliactions/admin/trans/export.go index 3d9607ea..89a22a35 100644 --- a/internal/cliactions/admin/trans/export.go +++ b/internal/cliactions/admin/trans/export.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/cliactions" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db/bundb" @@ -31,13 +30,13 @@ import ( ) // Export exports info from the database into a file -var Export cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Export cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } - exporter := trans.NewExporter(dbConn, log) + exporter := trans.NewExporter(dbConn) path, ok := c.ExportCLIFlags[config.TransPathFlag] if !ok { diff --git a/internal/cliactions/admin/trans/import.go b/internal/cliactions/admin/trans/import.go index 7b137ecc..82defde7 100644 --- a/internal/cliactions/admin/trans/import.go +++ b/internal/cliactions/admin/trans/import.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/cliactions" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db/bundb" @@ -31,13 +30,13 @@ import ( ) // Import imports info from a file into the database -var Import cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbConn, err := bundb.NewBunDBService(ctx, c, log) +var Import cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbConn, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } - importer := trans.NewImporter(dbConn, log) + importer := trans.NewImporter(dbConn) path, ok := c.ExportCLIFlags[config.TransPathFlag] if !ok { diff --git a/internal/cliactions/server/server.go b/internal/cliactions/server/server.go index e75eff7c..107d84d2 100644 --- a/internal/cliactions/server/server.go +++ b/internal/cliactions/server/server.go @@ -51,8 +51,8 @@ import ( ) // Start creates and starts a gotosocial server -var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error { - dbService, err := bundb.NewBunDBService(ctx, c, log) +var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config) error { + dbService, err := bundb.NewBunDBService(ctx, c) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } @@ -69,9 +69,9 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log return fmt.Errorf("error creating instance instance: %s", err) } - federatingDB := federatingdb.New(dbService, c, log) + federatingDB := federatingdb.New(dbService, c) - router, err := router.New(ctx, c, dbService, log) + router, err := router.New(ctx, c, dbService) if err != nil { return fmt.Errorf("error creating router: %s", err) } @@ -83,48 +83,48 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log } // build converters and util - typeConverter := typeutils.NewConverter(c, dbService, log) - timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c, log) + typeConverter := typeutils.NewConverter(c, dbService) + timelineManager := timelineprocessing.NewManager(dbService, typeConverter, c) // build backend handlers - mediaHandler := media.New(c, dbService, storage, log) - oauthServer := oauth.New(ctx, dbService, log) - transportController := transport.NewController(c, dbService, &federation.Clock{}, http.DefaultClient, log) - federator := federation.NewFederator(dbService, federatingDB, transportController, c, log, typeConverter, mediaHandler) - processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storage, timelineManager, dbService, log) + mediaHandler := media.New(c, dbService, storage) + oauthServer := oauth.New(ctx, dbService) + transportController := transport.NewController(c, dbService, &federation.Clock{}, http.DefaultClient) + federator := federation.NewFederator(dbService, federatingDB, transportController, c, typeConverter, mediaHandler) + processor := processing.NewProcessor(c, typeConverter, federator, oauthServer, mediaHandler, storage, timelineManager, dbService) if err := processor.Start(ctx); err != nil { return fmt.Errorf("error starting processor: %s", err) } - idp, err := oidc.NewIDP(ctx, c, log) + idp, err := oidc.NewIDP(ctx, c) if err != nil { return fmt.Errorf("error creating oidc idp: %s", err) } // build client api modules - authModule := auth.New(c, dbService, oauthServer, idp, log) - accountModule := account.New(c, processor, log) - instanceModule := instance.New(c, processor, log) - appsModule := app.New(c, processor, log) - followRequestsModule := followrequest.New(c, processor, log) - webfingerModule := webfinger.New(c, processor, log) - nodeInfoModule := nodeinfo.New(c, processor, log) - webBaseModule := web.New(c, processor, log) - usersModule := user.New(c, processor, log) - timelineModule := timeline.New(c, processor, log) - notificationModule := notification.New(c, processor, log) - searchModule := search.New(c, processor, log) - filtersModule := filter.New(c, processor, log) - emojiModule := emoji.New(c, processor, log) - listsModule := list.New(c, processor, log) - mm := mediaModule.New(c, processor, log) - fileServerModule := fileserver.New(c, processor, log) - adminModule := admin.New(c, processor, log) - statusModule := status.New(c, processor, log) - securityModule := security.New(c, dbService, log) - streamingModule := streaming.New(c, processor, log) - favouritesModule := favourites.New(c, processor, log) - blocksModule := blocks.New(c, processor, log) + authModule := auth.New(c, dbService, oauthServer, idp) + accountModule := account.New(c, processor) + instanceModule := instance.New(c, processor) + appsModule := app.New(c, processor) + followRequestsModule := followrequest.New(c, processor) + webfingerModule := webfinger.New(c, processor) + nodeInfoModule := nodeinfo.New(c, processor) + webBaseModule := web.New(c, processor) + usersModule := user.New(c, processor) + timelineModule := timeline.New(c, processor) + notificationModule := notification.New(c, processor) + searchModule := search.New(c, processor) + filtersModule := filter.New(c, processor) + emojiModule := emoji.New(c, processor) + listsModule := list.New(c, processor) + mm := mediaModule.New(c, processor) + fileServerModule := fileserver.New(c, processor) + adminModule := admin.New(c, processor) + statusModule := status.New(c, processor) + securityModule := security.New(c, dbService) + streamingModule := streaming.New(c, processor) + favouritesModule := favourites.New(c, processor) + blocksModule := blocks.New(c, processor) apis := []api.ClientModule{ // modules with middleware go first @@ -174,13 +174,13 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log sigs := make(chan os.Signal, 1) signal.Notify(sigs, os.Interrupt, syscall.SIGTERM) sig := <-sigs - log.Infof("received signal %s, shutting down", sig) + logrus.Infof("received signal %s, shutting down", sig) // close down all running services in order if err := gts.Stop(ctx); err != nil { return fmt.Errorf("error closing gotosocial service: %s", err) } - log.Info("done! exiting...") + logrus.Info("done! exiting...") return nil } diff --git a/internal/cliactions/testrig/testrig.go b/internal/cliactions/testrig/testrig.go index 482ec34f..2993d861 100644 --- a/internal/cliactions/testrig/testrig.go +++ b/internal/cliactions/testrig/testrig.go @@ -43,7 +43,7 @@ import ( ) // Start creates and starts a gotosocial testrig server -var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log *logrus.Logger) error { +var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config) error { c := testrig.NewTestConfig() dbService := testrig.NewTestDB() testrig.StandardDBSetup(dbService, nil) @@ -67,35 +67,35 @@ var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log return fmt.Errorf("error starting processor: %s", err) } - idp, err := oidc.NewIDP(ctx, c, log) + idp, err := oidc.NewIDP(ctx, c) if err != nil { return fmt.Errorf("error creating oidc idp: %s", err) } // build client api modules - authModule := auth.New(c, dbService, oauthServer, idp, log) - accountModule := account.New(c, processor, log) - instanceModule := instance.New(c, processor, log) - appsModule := app.New(c, processor, log) - followRequestsModule := followrequest.New(c, processor, log) - webfingerModule := webfinger.New(c, processor, log) - nodeInfoModule := nodeinfo.New(c, processor, log) - webBaseModule := web.New(c, processor, log) - usersModule := user.New(c, processor, log) - timelineModule := timeline.New(c, processor, log) - notificationModule := notification.New(c, processor, log) - searchModule := search.New(c, processor, log) - filtersModule := filter.New(c, processor, log) - emojiModule := emoji.New(c, processor, log) - listsModule := list.New(c, processor, log) - mm := mediaModule.New(c, processor, log) - fileServerModule := fileserver.New(c, processor, log) - adminModule := admin.New(c, processor, log) - statusModule := status.New(c, processor, log) - securityModule := security.New(c, dbService, log) - streamingModule := streaming.New(c, processor, log) - favouritesModule := favourites.New(c, processor, log) - blocksModule := blocks.New(c, processor, log) + authModule := auth.New(c, dbService, oauthServer, idp) + accountModule := account.New(c, processor) + instanceModule := instance.New(c, processor) + appsModule := app.New(c, processor) + followRequestsModule := followrequest.New(c, processor) + webfingerModule := webfinger.New(c, processor) + nodeInfoModule := nodeinfo.New(c, processor) + webBaseModule := web.New(c, processor) + usersModule := user.New(c, processor) + timelineModule := timeline.New(c, processor) + notificationModule := notification.New(c, processor) + searchModule := search.New(c, processor) + filtersModule := filter.New(c, processor) + emojiModule := emoji.New(c, processor) + listsModule := list.New(c, processor) + mm := mediaModule.New(c, processor) + fileServerModule := fileserver.New(c, processor) + adminModule := admin.New(c, processor) + statusModule := status.New(c, processor) + securityModule := security.New(c, dbService) + streamingModule := streaming.New(c, processor) + favouritesModule := favourites.New(c, processor) + blocksModule := blocks.New(c, processor) apis := []api.ClientModule{ // modules with middleware go first @@ -145,7 +145,7 @@ var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log sigs := make(chan os.Signal, 1) signal.Notify(sigs, os.Interrupt, syscall.SIGTERM) sig := <-sigs - log.Infof("received signal %s, shutting down", sig) + logrus.Infof("received signal %s, shutting down", sig) testrig.StandardDBTeardown(dbService) testrig.StandardStorageTeardown(storageBackend) @@ -155,6 +155,6 @@ var Start cliactions.GTSAction = func(ctx context.Context, _ *config.Config, log return fmt.Errorf("error closing gotosocial service: %s", err) } - log.Info("done! exiting...") + logrus.Info("done! exiting...") return nil } diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go index a2028f8f..79ef4d14 100644 --- a/internal/db/bundb/admin.go +++ b/internal/db/bundb/admin.go @@ -24,6 +24,7 @@ import ( "crypto/rsa" "database/sql" "fmt" + "github.com/sirupsen/logrus" "net" "net/mail" "strings" @@ -86,7 +87,7 @@ func (a *adminDB) IsEmailAvailable(ctx context.Context, email string) (bool, db. func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, requireApproval bool, email string, password string, signUpIP net.IP, locale string, appID string, emailVerified bool, admin bool) (*gtsmodel.User, db.Error) { key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { - a.conn.log.Errorf("error creating new rsa key: %s", err) + logrus.Errorf("error creating new rsa key: %s", err) return nil, err } @@ -183,7 +184,7 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { WhereGroup(" AND ", whereEmptyOrNull("domain")) count, err := existsQ.Count(ctx) if err != nil && count == 1 { - a.conn.log.Infof("instance account %s already exists", username) + logrus.Infof("instance account %s already exists", username) return nil } else if err != sql.ErrNoRows { return a.conn.ProcessError(err) @@ -191,7 +192,7 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { - a.conn.log.Errorf("error creating new rsa key: %s", err) + logrus.Errorf("error creating new rsa key: %s", err) return err } @@ -226,7 +227,7 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { return a.conn.ProcessError(err) } - a.conn.log.Infof("instance account %s CREATED with id %s", username, acct.ID) + logrus.Infof("instance account %s CREATED with id %s", username, acct.ID) return nil } @@ -244,7 +245,7 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { return err } if exists { - a.conn.log.Infof("instance entry already exists") + logrus.Infof("instance entry already exists") return nil } @@ -269,6 +270,6 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { return a.conn.ProcessError(err) } - a.conn.log.Infof("created instance instance %s with id %s", domain, i.ID) + logrus.Infof("created instance instance %s with id %s", domain, i.ID) return nil } diff --git a/internal/db/bundb/basic.go b/internal/db/bundb/basic.go index e5a1fbaf..464d40e3 100644 --- a/internal/db/bundb/basic.go +++ b/internal/db/bundb/basic.go @@ -21,6 +21,7 @@ package bundb import ( "context" "errors" + "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -165,6 +166,6 @@ func (b *basicDB) IsHealthy(ctx context.Context) db.Error { } func (b *basicDB) Stop(ctx context.Context) db.Error { - b.conn.log.Info("closing db connection") + logrus.Info("closing db connection") return b.conn.Close() } diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go index e6ebe5d8..5bcab543 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -78,8 +78,8 @@ type bunDBService struct { conn *DBConn } -func doMigration(ctx context.Context, db *bun.DB, log *logrus.Logger) error { - l := log.WithField("func", "doMigration") +func doMigration(ctx context.Context, db *bun.DB) error { + l := logrus.WithField("func", "doMigration") migrator := migrate.NewMigrator(db, migrations.Migrations) @@ -106,7 +106,7 @@ func doMigration(ctx context.Context, db *bun.DB, log *logrus.Logger) error { // NewBunDBService returns a bunDB derived from the provided config, which implements the go-fed DB interface. // Under the hood, it uses https://github.com/uptrace/bun to create and maintain a database connection. -func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger) (db.DB, error) { +func NewBunDBService(ctx context.Context, c *config.Config) (db.DB, error) { var sqldb *sql.DB var conn *DBConn @@ -120,7 +120,7 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger) } sqldb = stdlib.OpenDB(*opts) tweakConnectionValues(sqldb) - conn = WrapDBConn(bun.NewDB(sqldb, pgdialect.New()), log) + conn = WrapDBConn(bun.NewDB(sqldb, pgdialect.New())) case dbTypeSqlite: // SQLITE @@ -138,10 +138,10 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger) return nil, fmt.Errorf("could not open sqlite db: %s", err) } tweakConnectionValues(sqldb) - conn = WrapDBConn(bun.NewDB(sqldb, sqlitedialect.New()), log) + conn = WrapDBConn(bun.NewDB(sqldb, sqlitedialect.New())) if c.DBConfig.Address == "file::memory:?cache=shared" { - log.Warn("sqlite in-memory database should only be used for debugging") + logrus.Warn("sqlite in-memory database should only be used for debugging") // don't close connections on disconnect -- otherwise // the SQLite database will be deleted when there @@ -152,23 +152,23 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger) return nil, fmt.Errorf("database type %s not supported for bundb", strings.ToLower(c.DBConfig.Type)) } - if log.Level >= logrus.TraceLevel { + if logrus.GetLevel() >= logrus.TraceLevel { // add a hook to just log queries and the time they take - conn.DB.AddQueryHook(newDebugQueryHook(log)) + conn.DB.AddQueryHook(newDebugQueryHook()) } // actually *begin* the connection so that we can tell if the db is there and listening if err := conn.Ping(); err != nil { return nil, fmt.Errorf("db connection error: %s", err) } - log.Info("connected to database") + logrus.Info("connected to database") for _, t := range registerTables { // https://bun.uptrace.dev/orm/many-to-many-relation/ conn.RegisterModel(t) } - if err := doMigration(ctx, conn.DB, log); err != nil { + if err := doMigration(ctx, conn.DB); err != nil { return nil, fmt.Errorf("db migration error: %s", err) } @@ -398,7 +398,7 @@ func (ps *bunDBService) MentionStringsToMentions(ctx context.Context, targetAcco if err != nil { if err == sql.ErrNoRows { // no result found for this username/domain so just don't include it as a mencho and carry on about our business - ps.conn.log.Debugf("no account found with username '%s' and domain '%s', skipping it", username, domain) + logrus.Debugf("no account found with username '%s' and domain '%s', skipping it", username, domain) continue } // a serious error has happened so bail @@ -464,7 +464,7 @@ func (ps *bunDBService) EmojiStringsToEmojis(ctx context.Context, emojis []strin if err != nil { if err == sql.ErrNoRows { // no result found for this username/domain so just don't include it as an emoji and carry on about our business - ps.conn.log.Debugf("no emoji found with shortcode %s, skipping it", e) + logrus.Debugf("no emoji found with shortcode %s, skipping it", e) continue } // a serious error has happened so bail diff --git a/internal/db/bundb/bundb_test.go b/internal/db/bundb/bundb_test.go index 3fa74530..d4655a25 100644 --- a/internal/db/bundb/bundb_test.go +++ b/internal/db/bundb/bundb_test.go @@ -19,7 +19,6 @@ package bundb_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 BunDBStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger // standard suite models testTokens map[string]*gtsmodel.Token @@ -61,7 +59,7 @@ func (suite *BunDBStandardTestSuite) SetupSuite() { func (suite *BunDBStandardTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() testrig.StandardDBSetup(suite.db, suite.testAccounts) } diff --git a/internal/db/bundb/conn.go b/internal/db/bundb/conn.go index aeb1b5db..3b5a3ac9 100644 --- a/internal/db/bundb/conn.go +++ b/internal/db/bundb/conn.go @@ -4,7 +4,6 @@ import ( "context" "database/sql" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/uptrace/bun" "github.com/uptrace/bun/dialect" @@ -15,12 +14,11 @@ type DBConn struct { // TODO: move *Config here, no need to be in each struct type errProc func(error) db.Error // errProc is the SQL-type specific error processor - log *logrus.Logger // log is the logger passed with this DBConn *bun.DB // DB is the underlying bun.DB connection } // WrapDBConn @TODO -func WrapDBConn(dbConn *bun.DB, log *logrus.Logger) *DBConn { +func WrapDBConn(dbConn *bun.DB) *DBConn { var errProc func(error) db.Error switch dbConn.Dialect().Name() { case dialect.PG: @@ -32,7 +30,6 @@ func WrapDBConn(dbConn *bun.DB, log *logrus.Logger) *DBConn { } return &DBConn{ errProc: errProc, - log: log, DB: dbConn, } } diff --git a/internal/db/bundb/instance.go b/internal/db/bundb/instance.go index 4e26fc7c..ea507ad4 100644 --- a/internal/db/bundb/instance.go +++ b/internal/db/bundb/instance.go @@ -20,6 +20,7 @@ package bundb import ( "context" + "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -98,7 +99,7 @@ func (i *instanceDB) CountInstanceDomains(ctx context.Context, domain string) (i } func (i *instanceDB) GetInstanceAccounts(ctx context.Context, domain string, maxID string, limit int) ([]*gtsmodel.Account, db.Error) { - i.conn.log.Debug("GetAccountsForInstance") + logrus.Debug("GetAccountsForInstance") accounts := []*gtsmodel.Account{} diff --git a/internal/db/bundb/trace.go b/internal/db/bundb/trace.go index 82b50c05..b13adf1b 100644 --- a/internal/db/bundb/trace.go +++ b/internal/db/bundb/trace.go @@ -27,26 +27,24 @@ import ( "github.com/uptrace/bun" ) -func newDebugQueryHook(log *logrus.Logger) bun.QueryHook { +func newDebugQueryHook() bun.QueryHook { return &debugQueryHook{ - log: log, } } // debugQueryHook implements bun.QueryHook type debugQueryHook struct { - log *logrus.Logger } -func (q *debugQueryHook) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context { +func (q *debugQueryHook) BeforeQuery(ctx context.Context, _ *bun.QueryEvent) context.Context { // do nothing return ctx } // AfterQuery logs the time taken to query, the operation (select, update, etc), and the query itself as translated by bun. -func (q *debugQueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) { +func (q *debugQueryHook) AfterQuery(_ context.Context, event *bun.QueryEvent) { dur := time.Since(event.StartTime).Round(time.Microsecond) - l := q.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "duration": dur, "operation": event.Operation(), }) diff --git a/internal/federation/authenticate.go b/internal/federation/authenticate.go index da5d2b93..78cfe2b5 100644 --- a/internal/federation/authenticate.go +++ b/internal/federation/authenticate.go @@ -25,6 +25,7 @@ import ( "encoding/pem" "errors" "fmt" + "github.com/sirupsen/logrus" "net/url" "strings" @@ -112,7 +113,7 @@ func getPublicKeyFromResponse(c context.Context, b []byte, keyID *url.URL) (voca // Also note that this function *does not* dereference the remote account that the signature key is associated with. // Other functions should use the returned URL to dereference the remote account, if required. func (f *federator) AuthenticateFederatedRequest(ctx context.Context, requestedUsername string) (*url.URL, bool, error) { - l := f.log.WithField("func", "AuthenticateFederatedRequest") + l := logrus.WithField("func", "AuthenticateFederatedRequest") var publicKey interface{} var pkOwnerURI *url.URL diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go index 6acb3b06..7d8e2ff9 100644 --- a/internal/federation/dereferencing/account.go +++ b/internal/federation/dereferencing/account.go @@ -59,7 +59,7 @@ func (d *deref) EnrichRemoteAccount(ctx context.Context, username string, accoun updated, err := d.db.UpdateAccount(ctx, account) if err != nil { - d.log.Errorf("EnrichRemoteAccount: error updating account: %s", err) + logrus.Errorf("EnrichRemoteAccount: error updating account: %s", err) return account, nil } @@ -203,7 +203,7 @@ func (d *deref) dereferenceAccountable(ctx context.Context, username string, rem // PopulateAccountFields populates any fields on the given account that weren't populated by the initial // dereferencing. This includes things like header and avatar etc. func (d *deref) PopulateAccountFields(ctx context.Context, account *gtsmodel.Account, requestingUsername string, refresh bool) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "PopulateAccountFields", "requestingUsername": requestingUsername, }) diff --git a/internal/federation/dereferencing/attachment.go b/internal/federation/dereferencing/attachment.go index fd0cfba1..3a4213cd 100644 --- a/internal/federation/dereferencing/attachment.go +++ b/internal/federation/dereferencing/attachment.go @@ -34,7 +34,7 @@ func (d *deref) GetRemoteAttachment(ctx context.Context, requestingUsername stri } remoteAttachmentURL := minAttachment.RemoteURL - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "username": requestingUsername, "remoteAttachmentURL": remoteAttachmentURL, }) diff --git a/internal/federation/dereferencing/dereferencer.go b/internal/federation/dereferencing/dereferencer.go index ea347b30..76fd830a 100644 --- a/internal/federation/dereferencing/dereferencer.go +++ b/internal/federation/dereferencing/dereferencer.go @@ -23,7 +23,6 @@ import ( "net/url" "sync" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -79,7 +78,6 @@ type Dereferencer interface { } type deref struct { - log *logrus.Logger db db.DB typeConverter typeutils.TypeConverter transportController transport.Controller @@ -90,9 +88,8 @@ type deref struct { } // NewDereferencer returns a Dereferencer initialized with the given parameters. -func NewDereferencer(config *config.Config, db db.DB, typeConverter typeutils.TypeConverter, transportController transport.Controller, mediaHandler media.Handler, log *logrus.Logger) Dereferencer { +func NewDereferencer(config *config.Config, db db.DB, typeConverter typeutils.TypeConverter, transportController transport.Controller, mediaHandler media.Handler) Dereferencer { return &deref{ - log: log, db: db, typeConverter: typeConverter, transportController: transportController, diff --git a/internal/federation/dereferencing/dereferencer_test.go b/internal/federation/dereferencing/dereferencer_test.go index 0eeabc64..051bf95c 100644 --- a/internal/federation/dereferencing/dereferencer_test.go +++ b/internal/federation/dereferencing/dereferencer_test.go @@ -41,7 +41,6 @@ type DereferencerStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger storage *kv.KVStore testRemoteStatuses map[string]vocab.ActivityStreamsNote @@ -64,14 +63,9 @@ func (suite *DereferencerStandardTestSuite) SetupSuite() { func (suite *DereferencerStandardTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.storage = testrig.NewTestStorage() - suite.dereferencer = dereferencing.NewDereferencer(suite.config, - suite.db, - testrig.NewTestTypeConverter(suite.db), - suite.mockTransportController(), - testrig.NewTestMediaHandler(suite.db, suite.storage), - suite.log) + suite.dereferencer = dereferencing.NewDereferencer(suite.config, suite.db, testrig.NewTestTypeConverter(suite.db), suite.mockTransportController(), testrig.NewTestMediaHandler(suite.db, suite.storage)) testrig.StandardDBSetup(suite.db, nil) } @@ -85,7 +79,7 @@ func (suite *DereferencerStandardTestSuite) TearDownTest() { // or note or attachment that we have stored, then just a 200 code will be returned, with an empty body. func (suite *DereferencerStandardTestSuite) mockTransportController() transport.Controller { do := func(req *http.Request) (*http.Response, error) { - suite.log.Debugf("received request for %s", req.URL) + logrus.Debugf("received request for %s", req.URL) responseBytes := []byte{} responseType := "" @@ -140,7 +134,7 @@ func (suite *DereferencerStandardTestSuite) mockTransportController() transport. if len(responseBytes) != 0 { // we found something, so print what we're going to return - suite.log.Debugf("returning response %s", string(responseBytes)) + logrus.Debugf("returning response %s", string(responseBytes)) } responseLength = len(responseBytes) diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 435bc921..c4102a8f 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -236,7 +236,7 @@ func (d *deref) dereferenceStatusable(ctx context.Context, username string, remo // and attach them to the status. The status itself will not be added to the database yet, // that's up the caller to do. func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Status, requestingUsername string, includeParent bool) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "dereferenceStatusFields", "status": fmt.Sprintf("%+v", status), }) @@ -292,8 +292,6 @@ func (d *deref) populateStatusFields(ctx context.Context, status *gtsmodel.Statu } func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Status, requestingUsername string) error { - l := d.log - // At this point, mentions should have the namestring and mentionedAccountURI set on them. // We can use these to find the accounts. @@ -302,20 +300,20 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta for _, m := range status.Mentions { if m.ID != "" { // we've already populated this mention, since it has an ID - l.Debug("populateStatusMentions: mention already populated") + logrus.Debug("populateStatusMentions: mention already populated") mentionIDs = append(mentionIDs, m.ID) newMentions = append(newMentions, m) continue } if m.TargetAccountURI == "" { - l.Debug("populateStatusMentions: target URI not set on mention") + logrus.Debug("populateStatusMentions: target URI not set on mention") continue } targetAccountURI, err := url.Parse(m.TargetAccountURI) if err != nil { - l.Debugf("populateStatusMentions: error parsing mentioned account uri %s: %s", m.TargetAccountURI, err) + logrus.Debugf("populateStatusMentions: error parsing mentioned account uri %s: %s", m.TargetAccountURI, err) continue } @@ -326,7 +324,7 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta if a, err := d.db.GetAccountByURI(ctx, targetAccountURI.String()); err != nil { errs = append(errs, err.Error()) } else { - l.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURI", targetAccountURI, a.ID) + logrus.Debugf("populateStatusMentions: got target account %s with id %s through GetAccountByURI", targetAccountURI, a.ID) targetAccount = a } @@ -336,13 +334,13 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta if a, _, err := d.GetRemoteAccount(ctx, requestingUsername, targetAccountURI, false); err != nil { errs = append(errs, err.Error()) } else { - l.Debugf("populateStatusMentions: got target account %s with id %s through GetRemoteAccount", targetAccountURI, a.ID) + logrus.Debugf("populateStatusMentions: got target account %s with id %s through GetRemoteAccount", targetAccountURI, a.ID) targetAccount = a } } if targetAccount == nil { - l.Debugf("populateStatusMentions: couldn't get target account %s: %s", m.TargetAccountURI, strings.Join(errs, " : ")) + logrus.Debugf("populateStatusMentions: couldn't get target account %s: %s", m.TargetAccountURI, strings.Join(errs, " : ")) continue } @@ -382,8 +380,6 @@ func (d *deref) populateStatusMentions(ctx context.Context, status *gtsmodel.Sta } func (d *deref) populateStatusAttachments(ctx context.Context, status *gtsmodel.Status, requestingUsername string) error { - l := d.log - // At this point we should know: // * the media type of the file we're looking for (a.File.ContentType) // * the file type (a.Type) @@ -399,7 +395,7 @@ func (d *deref) populateStatusAttachments(ctx context.Context, status *gtsmodel. attachment, err := d.GetRemoteAttachment(ctx, requestingUsername, a) if err != nil { - l.Errorf("populateStatusAttachments: couldn't get remote attachment %s: %s", a.RemoteURL, err) + logrus.Errorf("populateStatusAttachments: couldn't get remote attachment %s: %s", a.RemoteURL, err) continue } diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go index 87cc4291..4912bc59 100644 --- a/internal/federation/dereferencing/thread.go +++ b/internal/federation/dereferencing/thread.go @@ -35,7 +35,7 @@ import ( // presented by remote instances as part of their replies collections, and will likely involve making several calls to // multiple different hosts. func (d *deref) DereferenceThread(ctx context.Context, username string, statusIRI *url.URL) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DereferenceThread", "username": username, "statusIRI": statusIRI.String(), @@ -69,7 +69,7 @@ func (d *deref) DereferenceThread(ctx context.Context, username string, statusIR // iterateAncestors has the goal of reaching the oldest ancestor of a given status, and stashing all statuses along the way. func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI url.URL) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "iterateAncestors", "username": username, "statusIRI": statusIRI.String(), @@ -121,7 +121,7 @@ func (d *deref) iterateAncestors(ctx context.Context, username string, statusIRI } func (d *deref) iterateDescendants(ctx context.Context, username string, statusIRI url.URL, statusable ap.Statusable) error { - l := d.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "iterateDescendants", "username": username, "statusIRI": statusIRI.String(), diff --git a/internal/federation/federatingdb/accept.go b/internal/federation/federatingdb/accept.go index 0d2d3a27..8d295161 100644 --- a/internal/federation/federatingdb/accept.go +++ b/internal/federation/federatingdb/accept.go @@ -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 diff --git a/internal/federation/federatingdb/announce.go b/internal/federation/federatingdb/announce.go index 49ec8450..7a40cd05 100644 --- a/internal/federation/federatingdb/announce.go +++ b/internal/federation/federatingdb/announce.go @@ -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 diff --git a/internal/federation/federatingdb/create.go b/internal/federation/federatingdb/create.go index 4262dfcb..862f8447 100644 --- a/internal/federation/federatingdb/create.go +++ b/internal/federation/federatingdb/create.go @@ -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, diff --git a/internal/federation/federatingdb/db.go b/internal/federation/federatingdb/db.go index 8d41d082..039c7016 100644 --- a/internal/federation/federatingdb/db.go +++ b/internal/federation/federatingdb/db.go @@ -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 diff --git a/internal/federation/federatingdb/delete.go b/internal/federation/federatingdb/delete.go index 77c3f502..7d41d1b7 100644 --- a/internal/federation/federatingdb/delete.go +++ b/internal/federation/federatingdb/delete.go @@ -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, diff --git a/internal/federation/federatingdb/exists.go b/internal/federation/federatingdb/exists.go index ec5599c2..01c14a72 100644 --- a/internal/federation/federatingdb/exists.go +++ b/internal/federation/federatingdb/exists.go @@ -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, diff --git a/internal/federation/federatingdb/federatingdb_test.go b/internal/federation/federatingdb/federatingdb_test.go index 3c22480f..9198266e 100644 --- a/internal/federation/federatingdb/federatingdb_test.go +++ b/internal/federation/federatingdb/federatingdb_test.go @@ -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) } diff --git a/internal/federation/federatingdb/followers.go b/internal/federation/federatingdb/followers.go index 61c5d428..2eccf167 100644 --- a/internal/federation/federatingdb/followers.go +++ b/internal/federation/federatingdb/followers.go @@ -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, diff --git a/internal/federation/federatingdb/following.go b/internal/federation/federatingdb/following.go index 2cc02483..cc611171 100644 --- a/internal/federation/federatingdb/following.go +++ b/internal/federation/federatingdb/following.go @@ -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, diff --git a/internal/federation/federatingdb/get.go b/internal/federation/federatingdb/get.go index 505891ca..6c629d71 100644 --- a/internal/federation/federatingdb/get.go +++ b/internal/federation/federatingdb/get.go @@ -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, diff --git a/internal/federation/federatingdb/owns.go b/internal/federation/federatingdb/owns.go index 04a41749..8846c52b 100644 --- a/internal/federation/federatingdb/owns.go +++ b/internal/federation/federatingdb/owns.go @@ -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, diff --git a/internal/federation/federatingdb/undo.go b/internal/federation/federatingdb/undo.go index 3d4cb1d5..934b5970 100644 --- a/internal/federation/federatingdb/undo.go +++ b/internal/federation/federatingdb/undo.go @@ -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 diff --git a/internal/federation/federatingdb/update.go b/internal/federation/federatingdb/update.go index b3a27b46..646b155d 100644 --- a/internal/federation/federatingdb/update.go +++ b/internal/federation/federatingdb/update.go @@ -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 diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go index 49a95a44..3fd9653a 100644 --- a/internal/federation/federatingdb/util.go +++ b/internal/federation/federatingdb/util.go @@ -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 diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go index afa763d9..ea908460 100644 --- a/internal/federation/federatingprotocol.go +++ b/internal/federation/federatingprotocol.go @@ -61,7 +61,7 @@ import ( // write a response to the ResponseWriter as is expected that the caller // to PostInbox will do so when handling the error. func (f *federator) PostInboxRequestBodyHook(ctx context.Context, r *http.Request, activity pub.Activity) (context.Context, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "PostInboxRequestBodyHook", "useragent": r.UserAgent(), "url": r.URL.String(), @@ -93,7 +93,7 @@ func (f *federator) PostInboxRequestBodyHook(ctx context.Context, r *http.Reques // authenticated must be true and error nil. The request will continue // to be processed. func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWriter, r *http.Request) (context.Context, bool, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "AuthenticatePostInbox", "useragent": r.UserAgent(), "url": r.URL.String(), @@ -177,7 +177,7 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr // blocked must be false and error nil. The request will continue // to be processed. func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "Blocked", }) l.Debugf("entering BLOCKED function with IRI list: %+v", actorIRIs) @@ -185,7 +185,7 @@ func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, er receivingAccountI := ctx.Value(util.APReceivingAccount) receivingAccount, ok := receivingAccountI.(*gtsmodel.Account) if !ok { - f.log.Errorf("receiving account not set on request context") + l.Errorf("receiving account not set on request context") return false, errors.New("receiving account not set on request context, so couldn't determine blocks") } @@ -276,7 +276,7 @@ func (f *federator) FederatingCallbacks(ctx context.Context) (wrapped pub.Federa // type and extension, so the unhandled ones are passed to // DefaultCallback. func (f *federator) DefaultCallback(ctx context.Context, activity pub.Activity) error { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "DefaultCallback", "aptype": activity.GetTypeName(), }) diff --git a/internal/federation/federator.go b/internal/federation/federator.go index a385c450..2813f6ff 100644 --- a/internal/federation/federator.go +++ b/internal/federation/federator.go @@ -23,7 +23,6 @@ import ( "net/url" "github.com/go-fed/activity/pub" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -83,12 +82,11 @@ type federator struct { dereferencer dereferencing.Dereferencer mediaHandler media.Handler actor pub.FederatingActor - log *logrus.Logger } // NewFederator returns a new federator -func NewFederator(db db.DB, federatingDB federatingdb.DB, transportController transport.Controller, config *config.Config, log *logrus.Logger, typeConverter typeutils.TypeConverter, mediaHandler media.Handler) Federator { - dereferencer := dereferencing.NewDereferencer(config, db, typeConverter, transportController, mediaHandler, log) +func NewFederator(db db.DB, federatingDB federatingdb.DB, transportController transport.Controller, config *config.Config, typeConverter typeutils.TypeConverter, mediaHandler media.Handler) Federator { + dereferencer := dereferencing.NewDereferencer(config, db, typeConverter, transportController, mediaHandler) clock := &Clock{} f := &federator{ @@ -100,7 +98,6 @@ func NewFederator(db db.DB, federatingDB federatingdb.DB, transportController tr transportController: transportController, dereferencer: dereferencer, mediaHandler: mediaHandler, - log: log, } actor := newFederatingActor(f, f, federatingDB, clock) f.actor = actor diff --git a/internal/federation/federator_test.go b/internal/federation/federator_test.go index 76e16a04..04c3b344 100644 --- a/internal/federation/federator_test.go +++ b/internal/federation/federator_test.go @@ -27,7 +27,6 @@ import ( "git.iim.gay/grufwub/go-store/kv" "github.com/go-fed/activity/pub" "github.com/go-fed/httpsig" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" @@ -44,7 +43,6 @@ type ProtocolTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger storage *kv.KVStore typeConverter typeutils.TypeConverter accounts map[string]*gtsmodel.Account @@ -56,7 +54,7 @@ func (suite *ProtocolTestSuite) SetupSuite() { // setup standard items suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.storage = testrig.NewTestStorage() suite.typeConverter = testrig.NewTestTypeConverter(suite.db) suite.accounts = testrig.NewTestAccounts() @@ -82,7 +80,7 @@ func (suite *ProtocolTestSuite) TestPostInboxRequestBodyHook() { return nil, nil }), suite.db) // setup module being tested - federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.log, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) + federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) // setup request ctx := context.Background() @@ -111,7 +109,7 @@ func (suite *ProtocolTestSuite) TestAuthenticatePostInbox() { tc := testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db) // now setup module being tested, with the mock transport controller - federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.log, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) + federator := federation.NewFederator(suite.db, testrig.NewTestFederatingDB(suite.db), tc, suite.config, suite.typeConverter, testrig.NewTestMediaHandler(suite.db, suite.storage)) request := httptest.NewRequest(http.MethodPost, "http://localhost:8080/users/the_mighty_zork/inbox", nil) // we need these headers for the request to be validated diff --git a/internal/log/log.go b/internal/log/log.go index b71e62e1..b0614636 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -25,32 +25,29 @@ import ( "github.com/sirupsen/logrus" ) -// New returns a new logrus logger with the specified level, -// or an error if that level can't be parsed. It also sets -// the output to log.outputSplitter, so you get error logs -// on stderr and normal logs on stdout. -func New(level string) (*logrus.Logger, error) { - log := logrus.New() - - log.SetOutput(&outputSplitter{}) +// Initialize initializes the global Logrus logger to the specified level +// It also sets the output to log.outputSplitter, +// so you get error logs on stderr and normal logs on stdout. +func Initialize(level string) error { + logrus.SetOutput(&outputSplitter{}) logLevel, err := logrus.ParseLevel(level) if err != nil { - return nil, err + return err } - log.SetLevel(logLevel) + logrus.SetLevel(logLevel) if logLevel == logrus.TraceLevel { - log.SetReportCaller(true) + logrus.SetReportCaller(true) } - log.SetFormatter(&logrus.TextFormatter{ + logrus.SetFormatter(&logrus.TextFormatter{ DisableColors: true, DisableQuote: true, FullTimestamp: true, }) - return log, nil + return nil } // outputSplitter implements the io.Writer interface for use with Logrus, and simply diff --git a/internal/media/handler.go b/internal/media/handler.go index 429dee88..fb4ed307 100644 --- a/internal/media/handler.go +++ b/internal/media/handler.go @@ -87,16 +87,14 @@ type mediaHandler struct { config *config.Config db db.DB storage *kv.KVStore - log *logrus.Logger } -// New returns a new handler with the given config, db, storage, and logger -func New(config *config.Config, database db.DB, storage *kv.KVStore, log *logrus.Logger) Handler { +// New returns a new handler with the given config, db, and storage +func New(config *config.Config, database db.DB, storage *kv.KVStore) Handler { return &mediaHandler{ config: config, db: database, storage: storage, - log: log, } } @@ -108,7 +106,7 @@ func New(config *config.Config, database db.DB, storage *kv.KVStore, log *logrus // puts it in whatever storage backend we're using, sets the relevant fields in the database for the new image, // and then returns information to the caller about the new header. func (mh *mediaHandler) ProcessHeaderOrAvatar(ctx context.Context, attachment []byte, accountID string, mediaType Type, remoteURL string) (*gtsmodel.MediaAttachment, error) { - l := mh.log.WithField("func", "SetHeaderForAccountID") + l := logrus.WithField("func", "SetHeaderForAccountID") if mediaType != Header && mediaType != Avatar { return nil, errors.New("header or avatar not selected") diff --git a/internal/media/util_test.go b/internal/media/util_test.go index 9ba0f76e..c54fb6f2 100644 --- a/internal/media/util_test.go +++ b/internal/media/util_test.go @@ -19,16 +19,16 @@ package media import ( + "github.com/sirupsen/logrus" + "github.com/superseriousbusiness/gotosocial/internal/log" "io/ioutil" "testing" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" ) type MediaUtilTestSuite struct { suite.Suite - log *logrus.Logger } /* @@ -37,10 +37,12 @@ type MediaUtilTestSuite struct { // SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout func (suite *MediaUtilTestSuite) SetupSuite() { - // some of our subsequent entities need a log so create this here - log := logrus.New() - log.SetLevel(logrus.TraceLevel) - suite.log = log + // doesn't use testrig.InitTestLog() helper to prevent import cycle + err := log.Initialize(logrus.TraceLevel.String()) + if err != nil { + panic(err) + } + } func (suite *MediaUtilTestSuite) TearDownSuite() { diff --git a/internal/oauth/server.go b/internal/oauth/server.go index 0386ade4..5d8a6ff3 100644 --- a/internal/oauth/server.go +++ b/internal/oauth/server.go @@ -62,12 +62,11 @@ type Server interface { // s fulfils the Server interface using the underlying oauth2 server type s struct { server *server.Server - log *logrus.Logger } // New returns a new oauth server that implements the Server interface -func New(ctx context.Context, database db.Basic, log *logrus.Logger) Server { - ts := newTokenStore(ctx, database, log) +func New(ctx context.Context, database db.Basic) Server { + ts := newTokenStore(ctx, database) cs := NewClientStore(database) manager := manage.NewDefaultManager() @@ -95,12 +94,12 @@ func New(ctx context.Context, database db.Basic, log *logrus.Logger) Server { srv := server.NewServer(sc, manager) srv.SetInternalErrorHandler(func(err error) *errors.Response { - log.Errorf("internal oauth error: %s", err) + logrus.Errorf("internal oauth error: %s", err) return nil }) srv.SetResponseErrorHandler(func(re *errors.Response) { - log.Errorf("internal response error: %s", re.Error) + logrus.Errorf("internal response error: %s", re.Error) }) srv.SetUserAuthorizationHandler(func(w http.ResponseWriter, r *http.Request) (string, error) { @@ -113,7 +112,6 @@ func New(ctx context.Context, database db.Basic, log *logrus.Logger) Server { srv.SetClientInfoHandler(server.ClientFormHandler) return &s{ server: srv, - log: log, } } @@ -153,7 +151,7 @@ func (s *s) GenerateUserAccessToken(ctx context.Context, ti oauth2.TokenInfo, cl if authToken == nil { return nil, errors.New("generated auth token was empty") } - s.log.Tracef("obtained auth token: %+v", authToken) + logrus.Tracef("obtained auth token: %+v", authToken) accessToken, err := s.server.Manager.GenerateAccessToken(ctx, oauth2.AuthorizationCode, &oauth2.TokenGenerateRequest{ ClientID: authToken.GetClientID(), @@ -169,7 +167,7 @@ func (s *s) GenerateUserAccessToken(ctx context.Context, ti oauth2.TokenInfo, cl if accessToken == nil { return nil, errors.New("generated user-level access token was empty") } - s.log.Tracef("obtained user-level access token: %+v", accessToken) + logrus.Tracef("obtained user-level access token: %+v", accessToken) return accessToken, nil } diff --git a/internal/oauth/tokenstore.go b/internal/oauth/tokenstore.go index 94578dba..a198b011 100644 --- a/internal/oauth/tokenstore.go +++ b/internal/oauth/tokenstore.go @@ -36,35 +36,33 @@ import ( type tokenStore struct { oauth2.TokenStore db db.Basic - log *logrus.Logger } // newTokenStore returns a token store that satisfies the oauth2.TokenStore interface. // // In order to allow tokens to 'expire', it will also set off a goroutine that iterates through // the tokens in the DB once per minute and deletes any that have expired. -func newTokenStore(ctx context.Context, db db.Basic, log *logrus.Logger) oauth2.TokenStore { +func newTokenStore(ctx context.Context, db db.Basic) oauth2.TokenStore { ts := &tokenStore{ db: db, - log: log, } // set the token store to clean out expired tokens once per minute, or return if we're done - go func(ctx context.Context, ts *tokenStore, log *logrus.Logger) { + go func(ctx context.Context, ts *tokenStore) { cleanloop: for { select { case <-ctx.Done(): - log.Info("breaking cleanloop") + logrus.Info("breaking cleanloop") break cleanloop case <-time.After(1 * time.Minute): - log.Trace("sweeping out old oauth entries broom broom") + logrus.Trace("sweeping out old oauth entries broom broom") if err := ts.sweep(ctx); err != nil { - log.Errorf("error while sweeping oauth entries: %s", err) + logrus.Errorf("error while sweeping oauth entries: %s", err) } } } - }(ctx, ts, log) + }(ctx, ts) return ts } diff --git a/internal/oidc/handlecallback.go b/internal/oidc/handlecallback.go index 2fbdc930..98a6b066 100644 --- a/internal/oidc/handlecallback.go +++ b/internal/oidc/handlecallback.go @@ -22,10 +22,11 @@ import ( "context" "errors" "fmt" + "github.com/sirupsen/logrus" ) func (i *idp) HandleCallback(ctx context.Context, code string) (*Claims, error) { - l := i.log.WithField("func", "HandleCallback") + l := logrus.WithField("func", "HandleCallback") if code == "" { return nil, errors.New("code was empty string") } diff --git a/internal/oidc/idp.go b/internal/oidc/idp.go index 9a615997..3032d15d 100644 --- a/internal/oidc/idp.go +++ b/internal/oidc/idp.go @@ -23,7 +23,6 @@ import ( "fmt" "github.com/coreos/go-oidc/v3/oidc" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "golang.org/x/oauth2" ) @@ -49,14 +48,13 @@ type idp struct { oauth2Config oauth2.Config provider *oidc.Provider oidcConf *oidc.Config - log *logrus.Logger } -// NewIDP returns a new IDP configured with the given config and logger. +// NewIDP returns a new IDP configured with the given config. // If the passed config contains a nil value for the OIDCConfig, or OIDCConfig.Enabled // is set to false, then nil, nil will be returned. If OIDCConfig.Enabled is true, // then the other OIDC config fields must also be set. -func NewIDP(ctx context.Context, config *config.Config, log *logrus.Logger) (IDP, error) { +func NewIDP(ctx context.Context, config *config.Config) (IDP, error) { // oidc isn't enabled so we don't need to do anything if config.OIDCConfig == nil || !config.OIDCConfig.Enabled { @@ -116,6 +114,5 @@ func NewIDP(ctx context.Context, config *config.Config, log *logrus.Logger) (IDP oauth2Config: oauth2Config, oidcConf: oidcConf, provider: provider, - log: log, }, nil } diff --git a/internal/processing/account/account.go b/internal/processing/account/account.go index 831607d9..e88cd3a9 100644 --- a/internal/processing/account/account.go +++ b/internal/processing/account/account.go @@ -22,7 +22,6 @@ import ( "context" "mime/multipart" - "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -87,21 +86,19 @@ type processor struct { formatter text.Formatter db db.DB federator federation.Federator - log *logrus.Logger } // New returns a new account processor. -func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, oauthServer oauth.Server, fromClientAPI chan messages.FromClientAPI, federator federation.Federator, config *config.Config, log *logrus.Logger) Processor { +func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, oauthServer oauth.Server, fromClientAPI chan messages.FromClientAPI, federator federation.Federator, config *config.Config) Processor { return &processor{ tc: tc, config: config, mediaHandler: mediaHandler, fromClientAPI: fromClientAPI, oauthServer: oauthServer, - filter: visibility.NewFilter(db, log), - formatter: text.NewFormatter(config, db, log), + filter: visibility.NewFilter(db), + formatter: text.NewFormatter(config, db), db: db, federator: federator, - log: log, } } diff --git a/internal/processing/account/account_test.go b/internal/processing/account/account_test.go index cfc7130c..f1829094 100644 --- a/internal/processing/account/account_test.go +++ b/internal/processing/account/account_test.go @@ -21,7 +21,6 @@ package account_test import ( "git.iim.gay/grufwub/go-store/kv" "github.com/go-fed/activity/pub" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -41,7 +40,6 @@ type AccountStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger tc typeutils.TypeConverter storage *kv.KVStore mediaHandler media.Handler @@ -77,7 +75,7 @@ func (suite *AccountStandardTestSuite) SetupSuite() { func (suite *AccountStandardTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.tc = testrig.NewTestTypeConverter(suite.db) suite.storage = testrig.NewTestStorage() suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) @@ -86,7 +84,7 @@ func (suite *AccountStandardTestSuite) SetupTest() { suite.httpClient = testrig.NewMockHTTPClient(nil) suite.transportController = testrig.NewTestTransportController(suite.httpClient, suite.db) suite.federator = testrig.NewTestFederator(suite.db, suite.transportController, suite.storage) - suite.accountProcessor = account.New(suite.db, suite.tc, suite.mediaHandler, suite.oauthServer, suite.fromClientAPIChan, suite.federator, suite.config, suite.log) + suite.accountProcessor = account.New(suite.db, suite.tc, suite.mediaHandler, suite.oauthServer, suite.fromClientAPIChan, suite.federator, suite.config) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../testrig/media") } diff --git a/internal/processing/account/create.go b/internal/processing/account/create.go index 9eb61899..56557af4 100644 --- a/internal/processing/account/create.go +++ b/internal/processing/account/create.go @@ -21,6 +21,7 @@ package account import ( "context" "fmt" + "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -29,7 +30,7 @@ import ( ) func (p *processor) Create(ctx context.Context, applicationToken oauth2.TokenInfo, application *gtsmodel.Application, form *apimodel.AccountCreateRequest) (*apimodel.Token, error) { - l := p.log.WithField("func", "accountCreate") + l := logrus.WithField("func", "accountCreate") emailAvailable, err := p.db.IsEmailAvailable(ctx, form.Email) if err != nil { diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go index 632f4975..4be0c859 100644 --- a/internal/processing/account/delete.go +++ b/internal/processing/account/delete.go @@ -58,7 +58,7 @@ func (p *processor) Delete(ctx context.Context, account *gtsmodel.Account, origi if account.Domain != "" { fields["domain"] = account.Domain } - l := p.log.WithFields(fields) + l := logrus.WithFields(fields) l.Debug("beginning account delete process") diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go index 1ab25787..54bf372e 100644 --- a/internal/processing/account/update.go +++ b/internal/processing/account/update.go @@ -23,6 +23,7 @@ import ( "context" "errors" "fmt" + "github.com/sirupsen/logrus" "io" "mime/multipart" @@ -37,7 +38,7 @@ import ( ) func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, error) { - l := p.log.WithField("func", "AccountUpdate") + l := logrus.WithField("func", "AccountUpdate") if form.Discoverable != nil { account.Discoverable = *form.Discoverable diff --git a/internal/processing/admin/admin.go b/internal/processing/admin/admin.go index 92f69f06..1aaaced5 100644 --- a/internal/processing/admin/admin.go +++ b/internal/processing/admin/admin.go @@ -22,7 +22,6 @@ import ( "context" "mime/multipart" - "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -49,17 +48,15 @@ type processor struct { mediaHandler media.Handler fromClientAPI chan messages.FromClientAPI db db.DB - log *logrus.Logger } // New returns a new admin processor. -func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, fromClientAPI chan messages.FromClientAPI, config *config.Config, log *logrus.Logger) Processor { +func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, fromClientAPI chan messages.FromClientAPI, config *config.Config) Processor { return &processor{ tc: tc, config: config, mediaHandler: mediaHandler, fromClientAPI: fromClientAPI, db: db, - log: log, } } diff --git a/internal/processing/admin/createdomainblock.go b/internal/processing/admin/createdomainblock.go index 399007fe..f544a84b 100644 --- a/internal/processing/admin/createdomainblock.go +++ b/internal/processing/admin/createdomainblock.go @@ -87,7 +87,7 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc // 2. Delete the instance account for that instance if it exists. // 3. Select all accounts from this instance and pass them through the delete functionality of the processor. func (p *processor) initiateDomainBlockSideEffects(ctx context.Context, account *gtsmodel.Account, block *gtsmodel.DomainBlock) { - l := p.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "domainBlockProcessSideEffects", "domain": block.Domain, }) diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go index 449cc6f0..8a36fb9b 100644 --- a/internal/processing/fromfederator.go +++ b/internal/processing/fromfederator.go @@ -35,7 +35,7 @@ import ( // and directs the message into the appropriate side effect handler function, or simply does nothing if there's // no handler function defined for the combination of Activity and Object. func (p *processor) ProcessFromFederator(ctx context.Context, federatorMsg messages.FromFederator) error { - l := p.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "processFromFederator", "APActivityType": federatorMsg.APActivityType, "APObjectType": federatorMsg.APObjectType, diff --git a/internal/processing/media/media.go b/internal/processing/media/media.go index 4c841648..e7c9a6e0 100644 --- a/internal/processing/media/media.go +++ b/internal/processing/media/media.go @@ -22,7 +22,6 @@ import ( "context" "git.iim.gay/grufwub/go-store/kv" - "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -49,17 +48,15 @@ type processor struct { mediaHandler media.Handler storage *kv.KVStore db db.DB - log *logrus.Logger } // New returns a new media processor. -func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, storage *kv.KVStore, config *config.Config, log *logrus.Logger) Processor { +func New(db db.DB, tc typeutils.TypeConverter, mediaHandler media.Handler, storage *kv.KVStore, config *config.Config) Processor { return &processor{ tc: tc, config: config, mediaHandler: mediaHandler, storage: storage, db: db, - log: log, } } diff --git a/internal/processing/notification.go b/internal/processing/notification.go index 27280a97..0710f226 100644 --- a/internal/processing/notification.go +++ b/internal/processing/notification.go @@ -20,6 +20,7 @@ package processing import ( "context" + "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/gtserror" @@ -27,7 +28,7 @@ import ( ) func (p *processor) NotificationsGet(ctx context.Context, authed *oauth.Auth, limit int, maxID string, sinceID string) ([]*apimodel.Notification, gtserror.WithCode) { - l := p.log.WithField("func", "NotificationsGet") + l := logrus.WithField("func", "NotificationsGet") notifs, err := p.db.GetNotifications(ctx, authed.Account.ID, limit, maxID, sinceID) if err != nil { diff --git a/internal/processing/processor.go b/internal/processing/processor.go index c643738c..5732ad09 100644 --- a/internal/processing/processor.go +++ b/internal/processing/processor.go @@ -229,7 +229,6 @@ type processor struct { fromFederator chan messages.FromFederator federator federation.Federator stop chan interface{} - log *logrus.Logger config *config.Config tc typeutils.TypeConverter oauthServer oauth.Server @@ -250,23 +249,22 @@ type processor struct { mediaProcessor mediaProcessor.Processor } -// NewProcessor returns a new Processor that uses the given federator and logger -func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage *kv.KVStore, timelineManager timeline.Manager, db db.DB, log *logrus.Logger) Processor { +// NewProcessor returns a new Processor that uses the given federator +func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator federation.Federator, oauthServer oauth.Server, mediaHandler media.Handler, storage *kv.KVStore, timelineManager timeline.Manager, db db.DB) Processor { fromClientAPI := make(chan messages.FromClientAPI, 1000) fromFederator := make(chan messages.FromFederator, 1000) - statusProcessor := status.New(db, tc, config, fromClientAPI, log) - streamingProcessor := streaming.New(db, oauthServer, log) - accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator, config, log) - adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI, config, log) - mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage, config, log) + statusProcessor := status.New(db, tc, config, fromClientAPI) + streamingProcessor := streaming.New(db, oauthServer) + accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator, config) + adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI, config) + mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage, config) return &processor{ fromClientAPI: fromClientAPI, fromFederator: fromFederator, federator: federator, stop: make(chan interface{}), - log: log, config: config, tc: tc, oauthServer: oauthServer, @@ -274,7 +272,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f storage: storage, timelineManager: timelineManager, db: db, - filter: visibility.NewFilter(db, log), + filter: visibility.NewFilter(db), accountProcessor: accountProcessor, adminProcessor: adminProcessor, @@ -291,17 +289,17 @@ func (p *processor) Start(ctx context.Context) error { for { select { case clientMsg := <-p.fromClientAPI: - p.log.Tracef("received message FROM client API: %+v", clientMsg) + logrus.Tracef("received message FROM client API: %+v", clientMsg) go func() { if err := p.ProcessFromClientAPI(ctx, clientMsg); err != nil { - p.log.Error(err) + logrus.Error(err) } }() case federatorMsg := <-p.fromFederator: - p.log.Tracef("received message FROM federator: %+v", federatorMsg) + logrus.Tracef("received message FROM federator: %+v", federatorMsg) go func() { if err := p.ProcessFromFederator(ctx, federatorMsg); err != nil { - p.log.Error(err) + logrus.Error(err) } }() case <-p.stop: diff --git a/internal/processing/processor_test.go b/internal/processing/processor_test.go index 7a1db442..f2a9e455 100644 --- a/internal/processing/processor_test.go +++ b/internal/processing/processor_test.go @@ -28,7 +28,6 @@ import ( "git.iim.gay/grufwub/go-store/kv" "github.com/go-fed/activity/streams" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -48,7 +47,6 @@ type ProcessingStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger storage *kv.KVStore typeconverter typeutils.TypeConverter transportController transport.Controller @@ -100,7 +98,7 @@ func (suite *ProcessingStandardTestSuite) SetupSuite() { func (suite *ProcessingStandardTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.storage = testrig.NewTestStorage() suite.typeconverter = testrig.NewTestTypeConverter(suite.db) @@ -190,16 +188,7 @@ func (suite *ProcessingStandardTestSuite) SetupTest() { suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage) suite.timelineManager = testrig.NewTestTimelineManager(suite.db) - suite.processor = processing.NewProcessor( - suite.config, - suite.typeconverter, - suite.federator, - suite.oauthServer, - suite.mediaHandler, - suite.storage, - suite.timelineManager, - suite.db, - suite.log) + suite.processor = processing.NewProcessor(suite.config, suite.typeconverter, suite.federator, suite.oauthServer, suite.mediaHandler, suite.storage, suite.timelineManager, suite.db) testrig.StandardDBSetup(suite.db, suite.testAccounts) testrig.StandardStorageSetup(suite.storage, "../../testrig/media") diff --git a/internal/processing/search.go b/internal/processing/search.go index c5bfd722..a7331539 100644 --- a/internal/processing/search.go +++ b/internal/processing/search.go @@ -34,7 +34,7 @@ import ( ) func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, searchQuery *apimodel.SearchQuery) (*apimodel.SearchResult, gtserror.WithCode) { - l := p.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "SearchGet", "query": searchQuery.Query, }) @@ -116,7 +116,7 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, searchQue } func (p *processor) searchStatusByURI(ctx context.Context, authed *oauth.Auth, uri *url.URL, resolve bool) (*gtsmodel.Status, error) { - l := p.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "searchStatusByURI", "uri": uri.String(), "resolve": resolve, diff --git a/internal/processing/status/status.go b/internal/processing/status/status.go index 10faa569..666c237b 100644 --- a/internal/processing/status/status.go +++ b/internal/processing/status/status.go @@ -21,7 +21,6 @@ package status import ( "context" - "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -77,18 +76,16 @@ type processor struct { filter visibility.Filter formatter text.Formatter fromClientAPI chan messages.FromClientAPI - log *logrus.Logger } // New returns a new status processor. -func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, fromClientAPI chan messages.FromClientAPI, log *logrus.Logger) Processor { +func New(db db.DB, tc typeutils.TypeConverter, config *config.Config, fromClientAPI chan messages.FromClientAPI) Processor { return &processor{ tc: tc, config: config, db: db, - filter: visibility.NewFilter(db, log), - formatter: text.NewFormatter(config, db, log), + filter: visibility.NewFilter(db), + formatter: text.NewFormatter(config, db), fromClientAPI: fromClientAPI, - log: log, } } diff --git a/internal/processing/status/status_test.go b/internal/processing/status/status_test.go index 707a4843..c5c43905 100644 --- a/internal/processing/status/status_test.go +++ b/internal/processing/status/status_test.go @@ -19,7 +19,6 @@ package status_test import ( - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -34,7 +33,6 @@ type StatusStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger typeConverter typeutils.TypeConverter fromClientAPIChan chan messages.FromClientAPI diff --git a/internal/processing/status/util_test.go b/internal/processing/status/util_test.go index f80cf934..37e2f2df 100644 --- a/internal/processing/status/util_test.go +++ b/internal/processing/status/util_test.go @@ -67,10 +67,10 @@ func (suite *UtilTestSuite) SetupSuite() { func (suite *UtilTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() suite.typeConverter = testrig.NewTestTypeConverter(suite.db) suite.fromClientAPIChan = make(chan messages.FromClientAPI, 100) - suite.status = status.New(suite.db, suite.typeConverter, suite.config, suite.fromClientAPIChan, suite.log) + suite.status = status.New(suite.db, suite.typeConverter, suite.config, suite.fromClientAPIChan) testrig.StandardDBSetup(suite.db, nil) } diff --git a/internal/processing/streaming/openstream.go b/internal/processing/streaming/openstream.go index 74b6486f..706cc067 100644 --- a/internal/processing/streaming/openstream.go +++ b/internal/processing/streaming/openstream.go @@ -31,7 +31,7 @@ import ( ) func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode) { - l := p.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "OpenStreamForAccount", "account": account.ID, "streamType": streamType, diff --git a/internal/processing/streaming/streaming.go b/internal/processing/streaming/streaming.go index abce30cd..604ec126 100644 --- a/internal/processing/streaming/streaming.go +++ b/internal/processing/streaming/streaming.go @@ -22,7 +22,6 @@ import ( "context" "sync" - "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtserror" @@ -47,16 +46,14 @@ type Processor interface { type processor struct { db db.DB - log *logrus.Logger oauthServer oauth.Server streamMap *sync.Map } // New returns a new status processor. -func New(db db.DB, oauthServer oauth.Server, log *logrus.Logger) Processor { +func New(db db.DB, oauthServer oauth.Server) Processor { return &processor{ db: db, - log: log, oauthServer: oauthServer, streamMap: &sync.Map{}, } diff --git a/internal/processing/streaming/streaming_test.go b/internal/processing/streaming/streaming_test.go index acc090b0..cbb899d1 100644 --- a/internal/processing/streaming/streaming_test.go +++ b/internal/processing/streaming/streaming_test.go @@ -19,7 +19,6 @@ package streaming_test import ( - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -34,7 +33,6 @@ type StreamingTestSuite struct { testTokens map[string]*gtsmodel.Token db db.DB oauthServer oauth.Server - log *logrus.Logger streamingProcessor streaming.Processor } @@ -44,8 +42,8 @@ func (suite *StreamingTestSuite) SetupTest() { suite.testTokens = testrig.NewTestTokens() suite.db = testrig.NewTestDB() suite.oauthServer = testrig.NewTestOauthServer(suite.db) - suite.log = testrig.NewTestLog() - suite.streamingProcessor = streaming.New(suite.db, suite.oauthServer, suite.log) + testrig.InitTestLog() + suite.streamingProcessor = streaming.New(suite.db, suite.oauthServer) testrig.StandardDBSetup(suite.db, suite.testAccounts) } diff --git a/internal/processing/timeline.go b/internal/processing/timeline.go index 249ef542..64238225 100644 --- a/internal/processing/timeline.go +++ b/internal/processing/timeline.go @@ -21,6 +21,7 @@ package processing import ( "context" "fmt" + "github.com/sirupsen/logrus" "net/url" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" @@ -129,7 +130,7 @@ func (p *processor) FavedTimelineGet(ctx context.Context, authed *oauth.Auth, ma } func (p *processor) filterPublicStatuses(ctx context.Context, authed *oauth.Auth, statuses []*gtsmodel.Status) ([]*apimodel.Status, error) { - l := p.log.WithField("func", "filterPublicStatuses") + l := logrus.WithField("func", "filterPublicStatuses") apiStatuses := []*apimodel.Status{} for _, s := range statuses { @@ -164,7 +165,7 @@ func (p *processor) filterPublicStatuses(ctx context.Context, authed *oauth.Auth } func (p *processor) filterFavedStatuses(ctx context.Context, authed *oauth.Auth, statuses []*gtsmodel.Status) ([]*apimodel.Status, error) { - l := p.log.WithField("func", "filterFavedStatuses") + l := logrus.WithField("func", "filterFavedStatuses") apiStatuses := []*apimodel.Status{} for _, s := range statuses { diff --git a/internal/router/logger.go b/internal/router/logger.go index 154f5c68..e45ccd12 100644 --- a/internal/router/logger.go +++ b/internal/router/logger.go @@ -30,7 +30,7 @@ var skipPaths = map[string]interface{}{ "/api/v1/streaming": nil, } -func loggerWithConfig(log *logrus.Logger) gin.HandlerFunc { +func loggingMiddleware() gin.HandlerFunc { logHandler := func(c *gin.Context) { start := time.Now() path := c.Request.URL.Path @@ -52,7 +52,7 @@ func loggerWithConfig(log *logrus.Logger) gin.HandlerFunc { path = path + "?" + raw } - l := log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "latency": latency, "clientIP": clientIP, "userAgent": userAgent, diff --git a/internal/router/router.go b/internal/router/router.go index cd6b7469..130832f7 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -56,7 +56,6 @@ type Router interface { // router fulfils the Router interface using gin and logrus type router struct { - logger *logrus.Logger engine *gin.Engine srv *http.Server config *config.Config @@ -74,21 +73,21 @@ func (r *router) Start() { // serve the http handler on the selected letsencrypt port, for receiving letsencrypt requests and solving their devious riddles go func() { if err := http.ListenAndServe(fmt.Sprintf(":%d", r.config.LetsEncryptConfig.Port), r.certManager.HTTPHandler(http.HandlerFunc(httpsRedirect))); err != nil && err != http.ErrServerClosed { - r.logger.Fatalf("listen: %s", err) + logrus.Fatalf("listen: %s", err) } }() // and serve the actual TLS handler go func() { if err := r.srv.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed { - r.logger.Fatalf("listen: %s", err) + logrus.Fatalf("listen: %s", err) } }() } else { // no tls required go func() { if err := r.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { - r.logger.Fatalf("listen: %s", err) + logrus.Fatalf("listen: %s", err) } }() } @@ -99,18 +98,18 @@ func (r *router) Stop(ctx context.Context) error { return r.srv.Shutdown(ctx) } -// New returns a new Router with the specified configuration, using the given logrus logger. +// New returns a new Router with the specified configuration. // // The given DB is only used in the New function for parsing config values, and is not otherwise // pinned to the router. -func New(ctx context.Context, cfg *config.Config, db db.DB, logger *logrus.Logger) (Router, error) { +func New(ctx context.Context, cfg *config.Config, db db.DB) (Router, error) { gin.SetMode(gin.ReleaseMode) // create the actual engine here -- this is the core request routing handler for gts engine := gin.New() - engine.Use(gin.RecoveryWithWriter(logger.Writer())) - engine.Use(loggerWithConfig(logger)) + engine.Use(gin.RecoveryWithWriter(logrus.StandardLogger().Writer())) + engine.Use(loggingMiddleware()) // 8 MiB engine.MaxMultipartMemory = 8 << 20 @@ -164,7 +163,6 @@ func New(ctx context.Context, cfg *config.Config, db db.DB, logger *logrus.Logge } return &router{ - logger: logger, engine: engine, srv: s, config: cfg, diff --git a/internal/text/common.go b/internal/text/common.go index d57e5775..1c7d5290 100644 --- a/internal/text/common.go +++ b/internal/text/common.go @@ -21,6 +21,7 @@ package text import ( "context" "fmt" + "github.com/sirupsen/logrus" "html" "strings" @@ -100,7 +101,7 @@ func (f *formatter) ReplaceMentions(ctx context.Context, in string, mentions []* if menchie.TargetAccount == nil { a, err := f.db.GetAccountByID(ctx, menchie.TargetAccountID) if err != nil { - f.log.Errorf("error getting account with id %s from the db: %s", menchie.TargetAccountID, err) + logrus.Errorf("error getting account with id %s from the db: %s", menchie.TargetAccountID, err) return match } menchie.TargetAccount = a diff --git a/internal/text/common_test.go b/internal/text/common_test.go index cb6d95c1..19851956 100644 --- a/internal/text/common_test.go +++ b/internal/text/common_test.go @@ -89,8 +89,7 @@ func (suite *CommonTestSuite) SetupSuite() { func (suite *CommonTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() - suite.formatter = text.NewFormatter(suite.config, suite.db, suite.log) + suite.formatter = text.NewFormatter(suite.config, suite.db) testrig.StandardDBSetup(suite.db, nil) } diff --git a/internal/text/formatter.go b/internal/text/formatter.go index 769ecafb..b0988e9f 100644 --- a/internal/text/formatter.go +++ b/internal/text/formatter.go @@ -21,7 +21,6 @@ package text import ( "context" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -45,14 +44,12 @@ type Formatter interface { type formatter struct { cfg *config.Config db db.DB - log *logrus.Logger } // NewFormatter returns a new Formatter interface for parsing statuses and other text input into nice html. -func NewFormatter(cfg *config.Config, db db.DB, log *logrus.Logger) Formatter { +func NewFormatter(cfg *config.Config, db db.DB) Formatter { return &formatter{ cfg: cfg, db: db, - log: log, } } diff --git a/internal/text/formatter_test.go b/internal/text/formatter_test.go index 228da4ec..d01f1418 100644 --- a/internal/text/formatter_test.go +++ b/internal/text/formatter_test.go @@ -19,7 +19,6 @@ package text_test import ( - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -33,7 +32,6 @@ type TextStandardTestSuite struct { suite.Suite config *config.Config db db.DB - log *logrus.Logger // standard suite models testTokens map[string]*gtsmodel.Token diff --git a/internal/text/link_test.go b/internal/text/link_test.go index f8d6a1ad..0709e4ad 100644 --- a/internal/text/link_test.go +++ b/internal/text/link_test.go @@ -84,8 +84,7 @@ func (suite *LinkTestSuite) SetupSuite() { func (suite *LinkTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() - suite.formatter = text.NewFormatter(suite.config, suite.db, suite.log) + suite.formatter = text.NewFormatter(suite.config, suite.db) testrig.StandardDBSetup(suite.db, nil) } diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index 085f211d..3faa69c0 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -82,8 +82,7 @@ func (suite *MarkdownTestSuite) SetupSuite() { func (suite *MarkdownTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() - suite.formatter = text.NewFormatter(suite.config, suite.db, suite.log) + suite.formatter = text.NewFormatter(suite.config, suite.db) testrig.StandardDBSetup(suite.db, suite.testAccounts) } diff --git a/internal/text/plain_test.go b/internal/text/plain_test.go index 62c43406..b353fb28 100644 --- a/internal/text/plain_test.go +++ b/internal/text/plain_test.go @@ -64,8 +64,7 @@ func (suite *PlainTestSuite) SetupSuite() { func (suite *PlainTestSuite) SetupTest() { suite.config = testrig.NewTestConfig() suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() - suite.formatter = text.NewFormatter(suite.config, suite.db, suite.log) + suite.formatter = text.NewFormatter(suite.config, suite.db) testrig.StandardDBSetup(suite.db, nil) } diff --git a/internal/timeline/get.go b/internal/timeline/get.go index a00613dc..e1ad5cc9 100644 --- a/internal/timeline/get.go +++ b/internal/timeline/get.go @@ -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, diff --git a/internal/timeline/get_test.go b/internal/timeline/get_test.go index 6c4a58c7..22b2c5be 100644 --- a/internal/timeline/get_test.go +++ b/internal/timeline/get_test.go @@ -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()) } diff --git a/internal/timeline/index.go b/internal/timeline/index.go index 7d7dc887..5cd60b16 100644 --- a/internal/timeline/index.go +++ b/internal/timeline/index.go @@ -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, diff --git a/internal/timeline/index_test.go b/internal/timeline/index_test.go index 2a6429b3..681f7617 100644 --- a/internal/timeline/index_test.go +++ b/internal/timeline/index_test.go @@ -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()) } diff --git a/internal/timeline/manager.go b/internal/timeline/manager.go index 7f42e2f5..5d41d72a 100644 --- a/internal/timeline/manager.go +++ b/internal/timeline/manager.go @@ -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 } diff --git a/internal/timeline/manager_test.go b/internal/timeline/manager_test.go index a67a8ae5..072761cd 100644 --- a/internal/timeline/manager_test.go +++ b/internal/timeline/manager_test.go @@ -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) diff --git a/internal/timeline/prepare.go b/internal/timeline/prepare.go index ee8175a5..7e5a712e 100644 --- a/internal/timeline/prepare.go +++ b/internal/timeline/prepare.go @@ -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, }) diff --git a/internal/timeline/remove.go b/internal/timeline/remove.go index 031dace1..bd62ed8b 100644 --- a/internal/timeline/remove.go +++ b/internal/timeline/remove.go @@ -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, diff --git a/internal/timeline/timeline.go b/internal/timeline/timeline.go index 5f5fa1b4..12c36a7f 100644 --- a/internal/timeline/timeline.go +++ b/internal/timeline/timeline.go @@ -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 := >smodel.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 } diff --git a/internal/timeline/timeline_test.go b/internal/timeline/timeline_test.go index 4f997cb1..517575f3 100644 --- a/internal/timeline/timeline_test.go +++ b/internal/timeline/timeline_test.go @@ -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 diff --git a/internal/trans/exporter.go b/internal/trans/exporter.go index 3dc0558f..d6d5678d 100644 --- a/internal/trans/exporter.go +++ b/internal/trans/exporter.go @@ -21,7 +21,6 @@ package trans import ( "context" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" ) @@ -32,15 +31,13 @@ type Exporter interface { type exporter struct { db db.DB - log *logrus.Logger writtenIDs map[string]bool } -// NewExporter returns a new Exporter that will use the given db and logger. -func NewExporter(db db.DB, log *logrus.Logger) Exporter { +// NewExporter returns a new Exporter that will use the given db. +func NewExporter(db db.DB) Exporter { return &exporter{ db: db, - log: log, writtenIDs: make(map[string]bool), } } diff --git a/internal/trans/exportminimal_test.go b/internal/trans/exportminimal_test.go index 2bffffcf..e0179386 100644 --- a/internal/trans/exportminimal_test.go +++ b/internal/trans/exportminimal_test.go @@ -38,7 +38,7 @@ func (suite *ExportMinimalTestSuite) TestExportMinimalOK() { tempFilePath := fmt.Sprintf("%s/%s", suite.T().TempDir(), uuid.NewString()) // export to the tempFilePath - exporter := trans.NewExporter(suite.db, suite.log) + exporter := trans.NewExporter(suite.db) err := exporter.ExportMinimal(context.Background(), tempFilePath) suite.NoError(err) diff --git a/internal/trans/import.go b/internal/trans/import.go index 74624e54..f93b50f9 100644 --- a/internal/trans/import.go +++ b/internal/trans/import.go @@ -23,6 +23,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/sirupsen/logrus" "io" "os" @@ -47,7 +48,7 @@ func (i *importer) Import(ctx context.Context, path string) error { err := decoder.Decode(&entry) if err != nil { if err == io.EOF { - i.log.Infof("Import: reached end of file") + logrus.Infof("Import: reached end of file") return neatClose(file) } return fmt.Errorf("Import: error decoding in readLoop: %s", err) @@ -73,7 +74,7 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.Entry) error if err := i.putInDB(ctx, account); err != nil { return fmt.Errorf("inputEntry: error adding account to database: %s", err) } - i.log.Infof("inputEntry: added account with id %s", account.ID) + logrus.Infof("inputEntry: added account with id %s", account.ID) return nil case transmodel.TransBlock: block, err := i.blockDecode(entry) @@ -83,7 +84,7 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.Entry) error if err := i.putInDB(ctx, block); err != nil { return fmt.Errorf("inputEntry: error adding block to database: %s", err) } - i.log.Infof("inputEntry: added block with id %s", block.ID) + logrus.Infof("inputEntry: added block with id %s", block.ID) return nil case transmodel.TransDomainBlock: block, err := i.domainBlockDecode(entry) @@ -93,7 +94,7 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.Entry) error if err := i.putInDB(ctx, block); err != nil { return fmt.Errorf("inputEntry: error adding domain block to database: %s", err) } - i.log.Infof("inputEntry: added domain block with id %s", block.ID) + logrus.Infof("inputEntry: added domain block with id %s", block.ID) return nil case transmodel.TransFollow: follow, err := i.followDecode(entry) @@ -103,7 +104,7 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.Entry) error if err := i.putInDB(ctx, follow); err != nil { return fmt.Errorf("inputEntry: error adding follow to database: %s", err) } - i.log.Infof("inputEntry: added follow with id %s", follow.ID) + logrus.Infof("inputEntry: added follow with id %s", follow.ID) return nil case transmodel.TransFollowRequest: fr, err := i.followRequestDecode(entry) @@ -113,7 +114,7 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.Entry) error if err := i.putInDB(ctx, fr); err != nil { return fmt.Errorf("inputEntry: error adding follow request to database: %s", err) } - i.log.Infof("inputEntry: added follow request with id %s", fr.ID) + logrus.Infof("inputEntry: added follow request with id %s", fr.ID) return nil case transmodel.TransInstance: inst, err := i.instanceDecode(entry) @@ -123,7 +124,7 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.Entry) error if err := i.putInDB(ctx, inst); err != nil { return fmt.Errorf("inputEntry: error adding instance to database: %s", err) } - i.log.Infof("inputEntry: added instance with id %s", inst.ID) + logrus.Infof("inputEntry: added instance with id %s", inst.ID) return nil case transmodel.TransUser: user, err := i.userDecode(entry) @@ -133,11 +134,11 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.Entry) error if err := i.putInDB(ctx, user); err != nil { return fmt.Errorf("inputEntry: error adding user to database: %s", err) } - i.log.Infof("inputEntry: added user with id %s", user.ID) + logrus.Infof("inputEntry: added user with id %s", user.ID) return nil } - i.log.Errorf("inputEntry: didn't recognize transtype '%s', skipping it", t) + logrus.Errorf("inputEntry: didn't recognize transtype '%s', skipping it", t) return nil } diff --git a/internal/trans/import_test.go b/internal/trans/import_test.go index 137a5fae..c8ceb614 100644 --- a/internal/trans/import_test.go +++ b/internal/trans/import_test.go @@ -42,7 +42,7 @@ func (suite *ImportMinimalTestSuite) TestImportMinimalOK() { tempFilePath := fmt.Sprintf("%s/%s", suite.T().TempDir(), uuid.NewString()) // export to the tempFilePath - exporter := trans.NewExporter(suite.db, suite.log) + exporter := trans.NewExporter(suite.db) err := exporter.ExportMinimal(ctx, tempFilePath) suite.NoError(err) @@ -57,7 +57,7 @@ func (suite *ImportMinimalTestSuite) TestImportMinimalOK() { newDB := testrig.NewTestDB() testrig.CreateTestTables(newDB) - importer := trans.NewImporter(newDB, suite.log) + importer := trans.NewImporter(newDB) err = importer.Import(ctx, tempFilePath) suite.NoError(err) diff --git a/internal/trans/importer.go b/internal/trans/importer.go index ea8866f5..81029a09 100644 --- a/internal/trans/importer.go +++ b/internal/trans/importer.go @@ -21,7 +21,6 @@ package trans import ( "context" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" ) @@ -32,13 +31,11 @@ type Importer interface { type importer struct { db db.DB - log *logrus.Logger } -// NewImporter returns a new Importer interface that uses the given db and logger. -func NewImporter(db db.DB, log *logrus.Logger) Importer { +// NewImporter returns a new Importer interface that uses the given db. +func NewImporter(db db.DB) Importer { return &importer{ db: db, - log: log, } } diff --git a/internal/trans/trans_test.go b/internal/trans/trans_test.go index 4a231486..3e3dfe4a 100644 --- a/internal/trans/trans_test.go +++ b/internal/trans/trans_test.go @@ -19,7 +19,6 @@ package trans_test import ( - "github.com/sirupsen/logrus" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/testrig" @@ -28,12 +27,11 @@ import ( type TransTestSuite struct { suite.Suite db db.DB - log *logrus.Logger } func (suite *TransTestSuite) SetupTest() { suite.db = testrig.NewTestDB() - suite.log = testrig.NewTestLog() + testrig.InitTestLog() testrig.StandardDBSetup(suite.db, nil) } diff --git a/internal/transport/controller.go b/internal/transport/controller.go index c2f5026e..9b22928d 100644 --- a/internal/transport/controller.go +++ b/internal/transport/controller.go @@ -26,7 +26,6 @@ import ( "github.com/go-fed/activity/pub" "github.com/go-fed/httpsig" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" ) @@ -43,18 +42,16 @@ type controller struct { clock pub.Clock client pub.HttpClient appAgent string - log *logrus.Logger } // NewController returns an implementation of the Controller interface for creating new transports -func NewController(config *config.Config, db db.DB, clock pub.Clock, client pub.HttpClient, log *logrus.Logger) Controller { +func NewController(config *config.Config, db db.DB, clock pub.Clock, client pub.HttpClient) Controller { return &controller{ config: config, db: db, clock: clock, client: client, appAgent: fmt.Sprintf("%s %s", config.ApplicationName, config.Host), - log: log, } } @@ -87,7 +84,6 @@ func (c *controller) NewTransport(pubKeyID string, privkey crypto.PrivateKey) (T sigTransport: sigTransport, getSigner: getSigner, getSignerMu: &sync.Mutex{}, - log: c.log, }, nil } diff --git a/internal/transport/deliver.go b/internal/transport/deliver.go index fd0fb576..5a522874 100644 --- a/internal/transport/deliver.go +++ b/internal/transport/deliver.go @@ -20,6 +20,7 @@ package transport import ( "context" + "github.com/sirupsen/logrus" "net/url" ) @@ -28,7 +29,7 @@ func (t *transport) BatchDeliver(ctx context.Context, b []byte, recipients []*ur } func (t *transport) Deliver(ctx context.Context, b []byte, to *url.URL) error { - l := t.log.WithField("func", "Deliver") + l := logrus.WithField("func", "Deliver") l.Debugf("performing POST to %s", to.String()) return t.sigTransport.Deliver(ctx, b, to) } diff --git a/internal/transport/dereference.go b/internal/transport/dereference.go index 85fa370e..477440a7 100644 --- a/internal/transport/dereference.go +++ b/internal/transport/dereference.go @@ -20,11 +20,12 @@ package transport import ( "context" + "github.com/sirupsen/logrus" "net/url" ) func (t *transport) Dereference(ctx context.Context, iri *url.URL) ([]byte, error) { - l := t.log.WithField("func", "Dereference") + l := logrus.WithField("func", "Dereference") l.Debugf("performing GET to %s", iri.String()) return t.sigTransport.Dereference(ctx, iri) } diff --git a/internal/transport/derefinstance.go b/internal/transport/derefinstance.go index 673881b0..a2610f54 100644 --- a/internal/transport/derefinstance.go +++ b/internal/transport/derefinstance.go @@ -23,6 +23,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/sirupsen/logrus" "io/ioutil" "net/http" "net/url" @@ -36,7 +37,7 @@ import ( ) func (t *transport) DereferenceInstance(ctx context.Context, iri *url.URL) (*gtsmodel.Instance, error) { - l := t.log.WithField("func", "DereferenceInstance") + l := logrus.WithField("func", "DereferenceInstance") var i *gtsmodel.Instance var err error @@ -78,7 +79,7 @@ func (t *transport) DereferenceInstance(ctx context.Context, iri *url.URL) (*gts } func dereferenceByAPIV1Instance(ctx context.Context, t *transport, iri *url.URL) (*gtsmodel.Instance, error) { - l := t.log.WithField("func", "dereferenceByAPIV1Instance") + l := logrus.WithField("func", "dereferenceByAPIV1Instance") cleanIRI := &url.URL{ Scheme: iri.Scheme, @@ -235,7 +236,7 @@ func dereferenceByNodeInfo(c context.Context, t *transport, iri *url.URL) (*gtsm } func callNodeInfoWellKnown(ctx context.Context, t *transport, iri *url.URL) (*url.URL, error) { - l := t.log.WithField("func", "callNodeInfoWellKnown") + l := logrus.WithField("func", "callNodeInfoWellKnown") cleanIRI := &url.URL{ Scheme: iri.Scheme, @@ -300,7 +301,7 @@ func callNodeInfoWellKnown(ctx context.Context, t *transport, iri *url.URL) (*ur } func callNodeInfo(ctx context.Context, t *transport, iri *url.URL) (*apimodel.Nodeinfo, error) { - l := t.log.WithField("func", "callNodeInfo") + l := logrus.WithField("func", "callNodeInfo") l.Debugf("performing GET to %s", iri.String()) req, err := http.NewRequestWithContext(ctx, "GET", iri.String(), nil) diff --git a/internal/transport/derefmedia.go b/internal/transport/derefmedia.go index e265bfdd..e1b6df15 100644 --- a/internal/transport/derefmedia.go +++ b/internal/transport/derefmedia.go @@ -21,13 +21,14 @@ package transport import ( "context" "fmt" + "github.com/sirupsen/logrus" "io/ioutil" "net/http" "net/url" ) func (t *transport) DereferenceMedia(ctx context.Context, iri *url.URL, expectedContentType string) ([]byte, error) { - l := t.log.WithField("func", "DereferenceMedia") + l := logrus.WithField("func", "DereferenceMedia") l.Debugf("performing GET to %s", iri.String()) req, err := http.NewRequestWithContext(ctx, "GET", iri.String(), nil) if err != nil { diff --git a/internal/transport/finger.go b/internal/transport/finger.go index ce092e83..648db019 100644 --- a/internal/transport/finger.go +++ b/internal/transport/finger.go @@ -21,13 +21,14 @@ package transport import ( "context" "fmt" + "github.com/sirupsen/logrus" "io/ioutil" "net/http" "net/url" ) func (t *transport) Finger(ctx context.Context, targetUsername string, targetDomain string) ([]byte, error) { - l := t.log.WithField("func", "Finger") + l := logrus.WithField("func", "Finger") urlString := fmt.Sprintf("https://%s/.well-known/webfinger?resource=acct:%s@%s", targetDomain, targetUsername, targetDomain) l.Debugf("performing GET to %s", urlString) diff --git a/internal/transport/transport.go b/internal/transport/transport.go index 8d826283..14787f5a 100644 --- a/internal/transport/transport.go +++ b/internal/transport/transport.go @@ -26,7 +26,6 @@ import ( "github.com/go-fed/activity/pub" "github.com/go-fed/httpsig" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) @@ -53,5 +52,4 @@ type transport struct { sigTransport *pub.HttpSigTransport getSigner httpsig.Signer getSignerMu *sync.Mutex - log *logrus.Logger } diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go index 88dae938..89b950c5 100644 --- a/internal/typeutils/astointernal.go +++ b/internal/typeutils/astointernal.go @@ -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 { diff --git a/internal/typeutils/converter.go b/internal/typeutils/converter.go index d702c1ae..812c3793 100644 --- a/internal/typeutils/converter.go +++ b/internal/typeutils/converter.go @@ -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(), } } diff --git a/internal/typeutils/converter_test.go b/internal/typeutils/converter_test.go index 424b0de2..04118236 100644 --- a/internal/typeutils/converter_test.go +++ b/internal/typeutils/converter_test.go @@ -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() { diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 70899d2d..272ffc17 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -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) diff --git a/internal/visibility/filter.go b/internal/visibility/filter.go index 644e85b3..b5f49c83 100644 --- a/internal/visibility/filter.go +++ b/internal/visibility/filter.go @@ -21,7 +21,6 @@ package visibility import ( "context" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) @@ -46,13 +45,11 @@ type Filter interface { type filter struct { db db.DB - log *logrus.Logger } -// NewFilter returns a new Filter interface that will use the provided database and logger. -func NewFilter(db db.DB, log *logrus.Logger) Filter { +// NewFilter returns a new Filter interface that will use the provided database. +func NewFilter(db db.DB) Filter { return &filter{ db: db, - log: log, } } diff --git a/internal/visibility/statushometimelineable.go b/internal/visibility/statushometimelineable.go index dd0ca079..3bc23dfc 100644 --- a/internal/visibility/statushometimelineable.go +++ b/internal/visibility/statushometimelineable.go @@ -27,7 +27,7 @@ import ( ) func (f *filter) StatusHometimelineable(ctx context.Context, targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusHometimelineable", "statusID": targetStatus.ID, }) diff --git a/internal/visibility/statuspublictimelineable.go b/internal/visibility/statuspublictimelineable.go index b815ac30..8dc1e9f5 100644 --- a/internal/visibility/statuspublictimelineable.go +++ b/internal/visibility/statuspublictimelineable.go @@ -27,7 +27,7 @@ import ( ) func (f *filter) StatusPublictimelineable(ctx context.Context, targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) { - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusPublictimelineable", "statusID": targetStatus.ID, }) diff --git a/internal/visibility/statusvisible.go b/internal/visibility/statusvisible.go index fc306411..1e48abcd 100644 --- a/internal/visibility/statusvisible.go +++ b/internal/visibility/statusvisible.go @@ -30,7 +30,7 @@ import ( func (f *filter) StatusVisible(ctx context.Context, targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) { const getBoosted = true - l := f.log.WithFields(logrus.Fields{ + l := logrus.WithFields(logrus.Fields{ "func": "StatusVisible", "statusID": targetStatus.ID, }) diff --git a/internal/web/base.go b/internal/web/base.go index 7be834a4..0eda1185 100644 --- a/internal/web/base.go +++ b/internal/web/base.go @@ -36,20 +36,18 @@ import ( type Module struct { config *config.Config processor processing.Processor - log *logrus.Logger } // New returns a new api.ClientModule for web pages. -func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { +func New(config *config.Config, processor processing.Processor) api.ClientModule { return &Module{ config: config, - log: log, processor: processor, } } func (m *Module) baseHandler(c *gin.Context) { - l := m.log.WithField("func", "BaseGETHandler") + l := logrus.WithField("func", "BaseGETHandler") l.Trace("serving index html") instance, err := m.processor.InstanceGet(c.Request.Context(), m.config.Host) @@ -66,7 +64,7 @@ func (m *Module) baseHandler(c *gin.Context) { // NotFoundHandler serves a 404 html page instead of a blank 404 error. func (m *Module) NotFoundHandler(c *gin.Context) { - l := m.log.WithField("func", "404") + l := logrus.WithField("func", "404") l.Trace("serving 404 html") instance, err := m.processor.InstanceGet(c.Request.Context(), m.config.Host) diff --git a/internal/web/thread.go b/internal/web/thread.go index 69c9674f..a359107c 100644 --- a/internal/web/thread.go +++ b/internal/web/thread.go @@ -19,6 +19,7 @@ package web import ( + "github.com/sirupsen/logrus" "net/http" "github.com/gin-gonic/gin" @@ -31,7 +32,7 @@ type statusLink struct { } func (m *Module) threadTemplateHandler(c *gin.Context) { - l := m.log.WithField("func", "threadTemplateGET") + l := logrus.WithField("func", "threadTemplateGET") l.Trace("rendering thread template") ctx := c.Request.Context() diff --git a/testrig/db.go b/testrig/db.go index 3de21c25..b97fa105 100644 --- a/testrig/db.go +++ b/testrig/db.go @@ -86,7 +86,7 @@ func NewTestDB() db.DB { config.DBConfig.Port = int(port) } - testDB, err := bundb.NewBunDBService(context.Background(), config, NewTestLog()) + testDB, err := bundb.NewBunDBService(context.Background(), config) if err != nil { logrus.Panic(err) } diff --git a/testrig/federatingdb.go b/testrig/federatingdb.go index 6e099fac..b0ef511b 100644 --- a/testrig/federatingdb.go +++ b/testrig/federatingdb.go @@ -7,5 +7,5 @@ import ( // NewTestFederatingDB returns a federating DB with the underlying db func NewTestFederatingDB(db db.DB) federatingdb.DB { - return federatingdb.New(db, NewTestConfig(), NewTestLog()) + return federatingdb.New(db, NewTestConfig()) } diff --git a/testrig/federator.go b/testrig/federator.go index df57032b..cd11f21b 100644 --- a/testrig/federator.go +++ b/testrig/federator.go @@ -27,5 +27,5 @@ import ( // NewTestFederator returns a federator with the given database and (mock!!) transport controller. func NewTestFederator(db db.DB, tc transport.Controller, storage *kv.KVStore) federation.Federator { - return federation.NewFederator(db, NewTestFederatingDB(db), tc, NewTestConfig(), NewTestLog(), NewTestTypeConverter(db), NewTestMediaHandler(db, storage)) + return federation.NewFederator(db, NewTestFederatingDB(db), tc, NewTestConfig(), NewTestTypeConverter(db), NewTestMediaHandler(db, storage)) } diff --git a/testrig/log.go b/testrig/log.go index 062368e9..5db12e6e 100644 --- a/testrig/log.go +++ b/testrig/log.go @@ -19,16 +19,14 @@ package testrig import ( - "github.com/superseriousbusiness/gotosocial/internal/log" - "github.com/sirupsen/logrus" + "github.com/superseriousbusiness/gotosocial/internal/log" ) -// NewTestLog returns a trace level logger for testing -func NewTestLog() *logrus.Logger { - logger, err := log.New("trace") +// InitTestLog sets the global logger to trace level for logging +func InitTestLog() { + err := log.Initialize(logrus.TraceLevel.String()) if err != nil { panic(err) } - return logger } diff --git a/testrig/mediahandler.go b/testrig/mediahandler.go index 3cf6f539..9ff8179c 100644 --- a/testrig/mediahandler.go +++ b/testrig/mediahandler.go @@ -24,8 +24,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/media" ) -// NewTestMediaHandler returns a media handler with the default test config, the default test logger, -// and the given db and storage. +// NewTestMediaHandler returns a media handler with the default test config, and the given db and storage. func NewTestMediaHandler(db db.DB, storage *kv.KVStore) media.Handler { - return media.New(NewTestConfig(), db, storage, NewTestLog()) + return media.New(NewTestConfig(), db, storage) } diff --git a/testrig/oauthserver.go b/testrig/oauthserver.go index 7ed230c4..3148e279 100644 --- a/testrig/oauthserver.go +++ b/testrig/oauthserver.go @@ -25,7 +25,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/oauth" ) -// NewTestOauthServer returns an oauth server with the given db, and the default test logger. +// NewTestOauthServer returns an oauth server with the given db func NewTestOauthServer(db db.DB) oauth.Server { - return oauth.New(context.Background(), db, NewTestLog()) + return oauth.New(context.Background(), db) } diff --git a/testrig/processor.go b/testrig/processor.go index 597edf33..88ded9ca 100644 --- a/testrig/processor.go +++ b/testrig/processor.go @@ -27,5 +27,5 @@ import ( // NewTestProcessor returns a Processor suitable for testing purposes func NewTestProcessor(db db.DB, storage *kv.KVStore, federator federation.Federator) processing.Processor { - return processing.NewProcessor(NewTestConfig(), NewTestTypeConverter(db), federator, NewTestOauthServer(db), NewTestMediaHandler(db, storage), storage, NewTestTimelineManager(db), db, NewTestLog()) + return processing.NewProcessor(NewTestConfig(), NewTestTypeConverter(db), federator, NewTestOauthServer(db), NewTestMediaHandler(db, storage), storage, NewTestTimelineManager(db), db) } diff --git a/testrig/router.go b/testrig/router.go index a3c11946..8efe1e4d 100644 --- a/testrig/router.go +++ b/testrig/router.go @@ -27,7 +27,7 @@ import ( // NewTestRouter returns a Router suitable for testing func NewTestRouter(db db.DB) router.Router { - r, err := router.New(context.Background(), NewTestConfig(), db, NewTestLog()) + r, err := router.New(context.Background(), NewTestConfig(), db) if err != nil { panic(err) } diff --git a/testrig/timelinemanager.go b/testrig/timelinemanager.go index 31c817e3..dd39f654 100644 --- a/testrig/timelinemanager.go +++ b/testrig/timelinemanager.go @@ -7,5 +7,5 @@ import ( // NewTestTimelineManager retuts a new timeline.Manager, suitable for testing, using the given db. func NewTestTimelineManager(db db.DB) timeline.Manager { - return timeline.NewManager(db, NewTestTypeConverter(db), NewTestConfig(), NewTestLog()) + return timeline.NewManager(db, NewTestTypeConverter(db), NewTestConfig()) } diff --git a/testrig/transportcontroller.go b/testrig/transportcontroller.go index ec591a9b..31e38f42 100644 --- a/testrig/transportcontroller.go +++ b/testrig/transportcontroller.go @@ -39,7 +39,7 @@ import ( // PER TEST rather than per suite, so that the do function can be set on a test by test (or even more granular) // basis. func NewTestTransportController(client pub.HttpClient, db db.DB) transport.Controller { - return transport.NewController(NewTestConfig(), db, &federation.Clock{}, client, NewTestLog()) + return transport.NewController(NewTestConfig(), db, &federation.Clock{}, client) } // NewMockHTTPClient returns a client that conforms to the pub.HttpClient interface, diff --git a/testrig/typeconverter.go b/testrig/typeconverter.go index c1561a35..9d49e6c9 100644 --- a/testrig/typeconverter.go +++ b/testrig/typeconverter.go @@ -25,5 +25,5 @@ import ( // NewTestTypeConverter returned a type converter with the given db and the default test config func NewTestTypeConverter(db db.DB) typeutils.TypeConverter { - return typeutils.NewConverter(NewTestConfig(), db, NewTestLog()) + return typeutils.NewConverter(NewTestConfig(), db) }