[chore] use our own logging implementation (#716)

* first commit

Signed-off-by: kim <grufwub@gmail.com>

* replace logging with our own log library

Signed-off-by: kim <grufwub@gmail.com>

* fix imports

Signed-off-by: kim <grufwub@gmail.com>

* fix log imports

Signed-off-by: kim <grufwub@gmail.com>

* add license text

Signed-off-by: kim <grufwub@gmail.com>

* fix package import cycle between config and log package

Signed-off-by: kim <grufwub@gmail.com>

* fix empty kv.Fields{} being passed to WithFields()

Signed-off-by: kim <grufwub@gmail.com>

* fix uses of log.WithFields() with whitespace issues and empty slices

Signed-off-by: kim <grufwub@gmail.com>

* *linter related grumbling*

Signed-off-by: kim <grufwub@gmail.com>

* gofmt the codebase! also fix more log.WithFields() formatting issues

Signed-off-by: kim <grufwub@gmail.com>

* update testrig code to match new changes

Signed-off-by: kim <grufwub@gmail.com>

* fix error wrapping in non fmt.Errorf function

Signed-off-by: kim <grufwub@gmail.com>

* add benchmarking of log.Caller() vs non-cached

Signed-off-by: kim <grufwub@gmail.com>

* fix syslog tests, add standard build tags to test runner to ensure consistency

Signed-off-by: kim <grufwub@gmail.com>

* make syslog tests more robust

Signed-off-by: kim <grufwub@gmail.com>

* fix caller depth arithmatic (is that how you spell it?)

Signed-off-by: kim <grufwub@gmail.com>

* update to use unkeyed fields in kv.Field{} instances

Signed-off-by: kim <grufwub@gmail.com>

* update go-kv library

Signed-off-by: kim <grufwub@gmail.com>

* update libraries list

Signed-off-by: kim <grufwub@gmail.com>

* fuck you linter get nerfed

Signed-off-by: kim <grufwub@gmail.com>

Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
This commit is contained in:
kim 2022-07-19 09:47:55 +01:00 committed by GitHub
commit 098dbe6ff4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
141 changed files with 3046 additions and 997 deletions

View file

@ -23,11 +23,11 @@ import (
"os"
"strconv"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
)
var testModels = []interface{}{
@ -91,7 +91,7 @@ func NewTestDB() db.DB {
testDB, err := bundb.NewBunDBService(context.Background())
if err != nil {
logrus.Panic(err)
log.Panic(err)
}
return testDB
}
@ -101,7 +101,7 @@ func CreateTestTables(db db.DB) {
ctx := context.Background()
for _, m := range testModels {
if err := db.CreateTable(ctx, m); err != nil {
logrus.Panicf("error creating table for %+v: %s", m, err)
log.Panicf("error creating table for %+v: %s", m, err)
}
}
}
@ -116,7 +116,7 @@ func CreateTestTables(db db.DB) {
// verification will fail.
func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) {
if db == nil {
logrus.Panic("db setup: db was nil")
log.Panic("db setup: db was nil")
}
CreateTestTables(db)
@ -125,128 +125,128 @@ func StandardDBSetup(db db.DB, accounts map[string]*gtsmodel.Account) {
for _, v := range NewTestTokens() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestClients() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestApplications() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestBlocks() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestDomainBlocks() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestInstances() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestUsers() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
if accounts == nil {
for _, v := range NewTestAccounts() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
} else {
for _, v := range accounts {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
}
for _, v := range NewTestAttachments() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestStatuses() {
if err := db.PutStatus(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestEmojis() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestTags() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestMentions() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestFaves() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestFollows() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
for _, v := range NewTestNotifications() {
if err := db.Put(ctx, v); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
if err := db.CreateInstanceAccount(ctx); err != nil {
logrus.Panic(err)
log.Panic(err)
}
if err := db.CreateInstanceInstance(ctx); err != nil {
logrus.Panic(err)
log.Panic(err)
}
logrus.Debug("testing db setup complete")
log.Debug("testing db setup complete")
}
// StandardDBTeardown drops all the standard testing tables/models from the database to ensure it's clean for the next test.
func StandardDBTeardown(db db.DB) {
ctx := context.Background()
if db == nil {
logrus.Panic("db teardown: db was nil")
log.Panic("db teardown: db was nil")
}
for _, m := range testModels {
if err := db.DropTable(ctx, m); err != nil {
logrus.Panic(err)
log.Panic(err)
}
}
}

View file

@ -19,6 +19,7 @@
package testrig
import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/log"
"gopkg.in/mcuadros/go-syslog.v2"
"gopkg.in/mcuadros/go-syslog.v2/format"
@ -26,8 +27,19 @@ import (
// InitTestLog sets the global logger to trace level for logging
func InitTestLog() {
if err := log.Initialize(); err != nil {
panic(err)
// Set the global log level from configuration
if err := log.ParseLevel(config.GetLogLevel()); err != nil {
log.Panicf("error parsing log level: %v", err)
}
if config.GetSyslogEnabled() {
// Enable logging to syslog
if err := log.EnableSyslog(
config.GetSyslogProtocol(),
config.GetSyslogAddress(),
); err != nil {
log.Panicf("error enabling syslogging: %v", err)
}
}
}

View file

@ -25,7 +25,6 @@ import (
"net/http"
"strings"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/activity/streams/vocab"
@ -33,12 +32,15 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/transport"
)
const applicationJSON = "application/json"
const applicationActivityJSON = "application/activity+json"
const (
applicationJSON = "application/json"
applicationActivityJSON = "application/activity+json"
)
// NewTestTransportController returns a test transport controller with the given http client.
//
@ -171,7 +173,7 @@ func NewMockHTTPClient(do func(req *http.Request) (*http.Response, error), relat
responseContentLength = len(attachment.Data)
}
logrus.Debugf("returning response %s", string(responseBytes))
log.Debugf("returning response %s", string(responseBytes))
reader := bytes.NewReader(responseBytes)
readCloser := io.NopCloser(reader)
return &http.Response{
@ -264,7 +266,7 @@ func WebfingerResponse(req *http.Request) (responseCode int, responseBytes []byt
}
if wfr == nil {
logrus.Debugf("webfinger response not available for %s", req.URL)
log.Debugf("webfinger response not available for %s", req.URL)
responseCode = http.StatusNotFound
responseBytes = []byte(`{"error":"not found"}`)
responseContentType = applicationJSON