From 4e83422530dea4eaa514bdc1e614158f855d3eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Fri, 8 Dec 2023 14:57:15 +0100 Subject: [PATCH 1/8] feat(BUX-200): change logger to zerolog --- .golangci.yml | 1 - README.md | 1 - actions/graphql/routes.go | 11 +++--- actions/paymail/routes.go | 3 +- cmd/server/main.go | 18 ++++----- config/config.go | 12 ++++-- config/envs/development.json | 74 +++++++++++++++++++++++++++--------- config/load.go | 9 ----- config/services.go | 26 ++++++++++--- go.mod | 31 +++++++-------- go.sum | 16 +++++++- logging.go | 72 +++++++++++++++++++++++++++++++++++ server/server.go | 7 +--- 13 files changed, 199 insertions(+), 82 deletions(-) create mode 100644 logging.go diff --git a/.golangci.yml b/.golangci.yml index e666f2e37..383b069fe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -332,7 +332,6 @@ linters: - testpackage - nestif - nlreturn - - testifylint - goconst disable-all: false presets: diff --git a/README.md b/README.md index 057621c12..33612c46e 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,6 @@ This repository was created using [MrZ's `go-template`](https://github.com/mrz18 - [BitcoinSchema/go-bitcoin](https://github.com/BitcoinSchema/go-bitcoin) - [BuxOrg/bux](https://github.com/BuxOrg/bux) - [mrz1836/go-api-router](https://github.com/mrz1836/go-api-router) -- [mrz1836/go-logger](https://github.com/mrz1836/go-logger) - [mrz1836/go-sanitize](https://github.com/mrz1836/go-sanitize) - [stretchr/testify](https://github.com/stretchr/testify) - [tonicpow/go-paymail](https://github.com/tonicpow/go-paymail) diff --git a/actions/graphql/routes.go b/actions/graphql/routes.go index 40d3dc607..1d0beec7a 100644 --- a/actions/graphql/routes.go +++ b/actions/graphql/routes.go @@ -19,7 +19,6 @@ import ( "github.com/gofrs/uuid" "github.com/julienschmidt/httprouter" apirouter "github.com/mrz1836/go-api-router" - "github.com/mrz1836/go-logger" "github.com/vektah/gqlparser/v2/gqlerror" ) @@ -62,13 +61,13 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi "variables": oc.Variables, } // LogParamsFormat "request_id=\"%s\" method=\"%s\" path=\"%s\" ip_address=\"%s\" user_agent=\"%s\" params=\"%v\"\n" - logger.NoFilePrintf(apirouter.LogParamsFormat, reqInfo.id, reqInfo.method, reqInfo.path, reqInfo.ip, reqInfo.userAgent, params) + services.Logger.Info().Msgf(apirouter.LogParamsFormat, reqInfo.id, reqInfo.method, reqInfo.path, reqInfo.ip, reqInfo.userAgent, params) return next(ctx) }) srv.SetErrorPresenter(func(ctx context.Context, err error) *gqlerror.Error { // LogErrorFormat "request_id=\"%s\" ip_address=\"%s\" type=\"%s\" internal_message=\"%s\" code=%d\n" reqInfo := ctx.Value(config.GraphRequestInfo).(requestInfo) - logger.NoFilePrintf(apirouter.LogErrorFormat, reqInfo.id, reqInfo.ip, "GraphQL", err.Error(), 500) + services.Logger.Info().Msgf(apirouter.LogErrorFormat, reqInfo.id, reqInfo.ip, "GraphQL", err.Error(), 500) return &gqlerror.Error{ Message: "presented: " + err.Error(), Path: graphql.GetPath(ctx), @@ -109,16 +108,16 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi ), ) if appConfig.Debug { - logger.Data(2, logger.DEBUG, "started graphql playground server on "+playgroundPath) + services.Logger.Debug().Msg("started graphql playground server on " + playgroundPath) } } else { - logger.Data(2, logger.ERROR, "Failed starting graphql playground server directory equals playground directory "+serverPath+" = "+playgroundPath) + services.Logger.Error().Msg("Failed starting graphql playground server directory equals playground directory " + serverPath + " = " + playgroundPath) } } // Success on the routes if appConfig.Debug { - logger.Data(2, logger.DEBUG, "registered graphql routes on "+serverPath) + services.Logger.Debug().Msg("registered graphql routes on " + serverPath) } } diff --git a/actions/paymail/routes.go b/actions/paymail/routes.go index 4d34935a7..d4cc2a2f6 100644 --- a/actions/paymail/routes.go +++ b/actions/paymail/routes.go @@ -4,7 +4,6 @@ import ( "github.com/BuxOrg/bux-server/actions" "github.com/BuxOrg/bux-server/config" apirouter "github.com/mrz1836/go-api-router" - "github.com/mrz1836/go-logger" ) // Action is an extension of actions.Action for this package @@ -29,6 +28,6 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi router.HTTPRouter.DELETE("/"+config.CurrentMajorVersion+"/paymail", action.Request(router, requireAdmin.Wrap(action.delete))) if appConfig.Debug { - logger.Data(2, logger.DEBUG, "registered paymail routes and model") + services.Logger.Debug().Msg("registered paymail routes and model") } } diff --git a/cmd/server/main.go b/cmd/server/main.go index cb76ec3b6..23645ffaf 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -14,7 +14,7 @@ import ( "github.com/BuxOrg/bux-server/dictionary" _ "github.com/BuxOrg/bux-server/docs" "github.com/BuxOrg/bux-server/server" - "github.com/mrz1836/go-logger" + "github.com/BuxOrg/bux/logging" ) // main method starts everything for the BUX Server @@ -25,17 +25,18 @@ import ( // @name bux-auth-xpub func main() { + defaultLogger := logging.GetDefaultLogger() // Load the Application Configuration appConfig, err := config.Load("") if err != nil { - logger.Fatalf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) + defaultLogger.Error().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) return } // Load the Application Services var services *config.AppServices if services, err = appConfig.LoadServices(context.Background()); err != nil { - logger.Fatalf(dictionary.GetInternalMessage(dictionary.ErrorLoadingService), config.ApplicationName, err.Error()) + defaultLogger.Error().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingService), config.ApplicationName, err.Error()) return } @@ -44,13 +45,13 @@ func main() { // Validate configuration (after services have been loaded) if err = appConfig.Validate(txn); err != nil { - logger.Fatalf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) + services.Logger.Error().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) return } // (debugging: show services that are enabled or not) if appConfig.Debug { - logger.Data(2, logger.DEBUG, + services.Logger.Debug().Msg( fmt.Sprintf("datastore: %s | cachestore: %s | taskmanager: %s [%s] | new_relic: %t | paymail: %t | graphql: %t", appConfig.Datastore.Engine.String(), appConfig.Cachestore.Engine.String(), @@ -76,7 +77,7 @@ func main() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err = appServer.Shutdown(ctx); err != nil { - logger.Fatalf("error shutting down: %s", err.Error()) + services.Logger.Error().Msgf("error shutting down: %s", err.Error()) } close(idleConnectionsClosed) @@ -86,10 +87,7 @@ func main() { txn.End() // Listen and serve - logger.Data(2, logger.DEBUG, - "starting ["+appConfig.Environment+"] "+config.ApplicationName+" server...", - logger.MakeParameter("port", appConfig.Server.Port), - ) + services.Logger.Debug().Msgf("starting [%s] %s server at port %s...", appConfig.Environment, config.ApplicationName, appConfig.Server.Port) appServer.Serve() <-idleConnectionsClosed diff --git a/config/config.go b/config/config.go index 1b2cb8f00..f7577475b 100644 --- a/config/config.go +++ b/config/config.go @@ -8,10 +8,7 @@ import ( "github.com/BuxOrg/bux/cluster" "github.com/BuxOrg/bux/taskmanager" validation "github.com/go-ozzo/ozzo-validation" - "github.com/mrz1836/go-cachestore" - "github.com/mrz1836/go-datastore" "github.com/newrelic/go-agent/v3/newrelic" - "github.com/tonicpow/go-minercraft/v2" ) // Config constants used for optimization and value testing @@ -76,6 +73,7 @@ type ( BroadcastClientAPIs []string `json:"broadcast_client_apis" mapstructure:"broadcast_client_apis"` UseBeef bool `json:"use_beef" mapstructure:"use_beef"` Pulse PulseConfig `json:"pulse" mapstructure:"pulse"` + Logging *LoggingConfig `json:"logging" mapstructure:"logging"` } // AuthenticationConfig is the configuration for Authentication @@ -182,6 +180,14 @@ type ( PulseURL string `json:"pulse_url" mapstructure:"pulse_url"` PulseAuthToken string `json:"pulse_auth_token" mapstructure:"pulse_auth_token"` } + + // LoggingConfig is a configuration for logging + LoggingConfig struct { + Level string `json:"level" mapstructure:"level"` + Format string `json:"format" mapstructure:"format"` + InstanceName string `json:"instance_name" mapstructure:"instance_name"` + LogOrigin bool `json:"log_origin" mapstructure:"log_origin"` + } ) // GetUserAgent will return the outgoing user agent diff --git a/config/envs/development.json b/config/envs/development.json index 56247b057..9b6d7b2cf 100644 --- a/config/envs/development.json +++ b/config/envs/development.json @@ -1,18 +1,24 @@ { "debug": true, "debug_profiling": false, - "disable_itc": true, + "disable_itc": false, "environment": "development", + "import_block_headers": "", "gdpr_compliance": false, "request_logging": true, "use_mapi_fee_quotes": true, - "minercraft_api": "mAPI", "authentication": { - "admin_key": "xpub661MyMwAqRbcFrBJbKwBGCB7d3fr2SaAuXGM95BA62X41m6eW2ehRQGW4xLi9wkEXUGnQZYxVVj4PxXnyrLk7jdqvBAs1Qq9gf6ykMvjR7J", + "admin_key": "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh", "require_signing": false, "scheme": "xpub", "signing_disabled": true }, + "logging": { + "level": "debug", + "format": "console", + "instance_name": "bux-pawel", + "log_origin": false + }, "cache": { "engine": "freecache" }, @@ -26,7 +32,7 @@ }, "datastore": { "auto_migrate": true, - "engine": "sqlite", + "engine": "postgresql", "debug": false, "table_prefix": "xapi" }, @@ -39,15 +45,15 @@ "mongodb": { "database_name": "xapi", "transactions": false, - "uri": "mongodb://localhost:27017/xapi" + "uri": "mongodb://mongo:mongo@localhost:27017/" }, "monitor": { - "auth_token": "", - "bux_agent_url": "ws://localhost:8000/websocket", - "debug": false, + "auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzaWdnaSIsImV4cCI6MTc1MDM4MTA2OH0.EXHm4MrwnJGjHIrdSUP39TyQZsieukWivCwqecQO0F8", + "bux_agent_url": "wss://siggi.siftbitcoin.com/websocket", + "debug": true, "enabled": false, "false_positive_rate": 0.01, - "load_monitored_destinations": false, + "load_monitored_destinations": true, "max_number_of_destinations": 100000, "monitor_days": 7, "processor_type": "bloom", @@ -60,11 +66,12 @@ }, "paymail": { "enabled": true, - "default_from_paymail": "from@domain.com", + "default_from_paymail": "bux@pawel.4chain.space", "default_note": "bux Address Resolution", "domain_validation_enabled": false, "domains": [ - "localhost" + "localhost", + "pawel.4chain.space" ], "sender_validation_enabled": false }, @@ -81,13 +88,13 @@ "server": { "idle_timeout": "60s", "port": "3003", - "read_timeout": "15s", - "write_timeout": "15s" + "read_timeout": "40s", + "write_timeout": "40s" }, "sql": { "host": "localhost", - "name": "xapi", - "password": "", + "name": "postgres", + "password": "postgres", "_port": "3306", "port": "5432", "replica": false, @@ -105,12 +112,41 @@ "factory": "memory", "queue_name": "development_queue" }, - "broadcast_client_apis": [ - "url|token" - ], "use_beef": true, "pulse": { "pulse_url": "http://localhost:8000/api/v1/chain/merkleroot/verify", "pulse_auth_token": "asd" - } + }, + "minercraft_custom_apis":[ + { + "minerid":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270", + "apis":[ + { + "token":"mainnet_3af382fadbc448b15cc4133242ac2621", + "url":"https://merchantapi.taal.com", + "type":"mAPI" + }, + { + "token":"mainnet_3af382fadbc448b15cc4133242ac2621", + "url":"https://tapi.taal.com/arc", + "type":"Arc" + } + ] + }, + { + "minerid":"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83", + "apis":[ + { + "token":"mainnet_3af382fadbc448b15cc4133242ac2621", + "url":"https://merchantapi.gorillapool.io", + "type":"mAPI" + }, + { + "token":"mainnet_3af382fadbc448b15cc4133242ac2621", + "url":"https://arc.gorillapool.io", + "type":"Arc" + } + ] + } + ] } diff --git a/config/load.go b/config/load.go index 68527c4e6..e66351153 100644 --- a/config/load.go +++ b/config/load.go @@ -7,8 +7,6 @@ import ( "sync" "github.com/BuxOrg/bux-server/dictionary" - "github.com/mrz1836/go-datastore" - "github.com/mrz1836/go-logger" "github.com/spf13/viper" ) @@ -37,12 +35,10 @@ var viperLock sync.Mutex // Load all environment variables func Load(customWorkingDirectory string) (_appConfig *AppConfig, err error) { - // Check the environment we are running environment := os.Getenv(EnvironmentKey) if !isValidEnvironment(environment) { err = fmt.Errorf(dictionary.GetInternalMessage(dictionary.ErrorInvalidEnv), environment) - logger.Data(2, logger.ERROR, err.Error()) return } @@ -72,13 +68,9 @@ func Load(customWorkingDirectory string) (_appConfig *AppConfig, err error) { // Read the configuration if err = viper.ReadInConfig(); err != nil { err = fmt.Errorf(dictionary.GetInternalMessage(dictionary.ErrorReadingConfig), err.Error()) - logger.Data(2, logger.ERROR, err.Error()) return } - // Log the configuration that was detected and where it was loaded from - logger.Data(2, logger.INFO, environment+" configuration env file processed in dir "+workingDirectory) - // Initialize _appConfigVal := AppConfig{ Authentication: AuthenticationConfig{}, @@ -100,7 +92,6 @@ func Load(customWorkingDirectory string) (_appConfig *AppConfig, err error) { // Unmarshal into values struct if err = viper.Unmarshal(&_appConfigVal); err != nil { err = fmt.Errorf(dictionary.GetInternalMessage(dictionary.ErrorViper), err.Error()) - logger.Data(2, logger.ERROR, err.Error()) return } diff --git a/config/services.go b/config/services.go index 00babfa8e..0d96af595 100644 --- a/config/services.go +++ b/config/services.go @@ -10,6 +10,7 @@ import ( "time" "github.com/BuxOrg/bux" + "github.com/BuxOrg/bux-server" "github.com/BuxOrg/bux/chainstate" "github.com/BuxOrg/bux/cluster" "github.com/BuxOrg/bux/taskmanager" @@ -18,8 +19,8 @@ import ( "github.com/go-redis/redis/v8" "github.com/mrz1836/go-cachestore" "github.com/mrz1836/go-datastore" - "github.com/mrz1836/go-logger" "github.com/newrelic/go-agent/v3/newrelic" + "github.com/rs/zerolog" "github.com/tonicpow/go-minercraft/v2" ) @@ -28,6 +29,7 @@ type ( AppServices struct { Bux bux.ClientInterface NewRelic *newrelic.Application + Logger *zerolog.Logger } ) @@ -48,8 +50,15 @@ func (a *AppConfig) LoadServices(ctx context.Context) (*AppServices, error) { ctx = newrelic.NewContext(ctx, txn) defer txn.End() + logger, err := buxserver.CreateLogger(a.Logging.InstanceName, a.Logging.Format, a.Logging.Level, a.Logging.LogOrigin) + if err != nil { + return nil, err + } + + _services.Logger = logger + // Load BUX - if err = _services.loadBux(ctx, a, false); err != nil { + if err = _services.loadBux(ctx, a, false, logger); err != nil { return nil, err } @@ -74,7 +83,7 @@ func (a *AppConfig) LoadTestServices(ctx context.Context) (*AppServices, error) defer txn.End() // Load bux for testing - if err = _services.loadBux(ctx, a, true); err != nil { + if err = _services.loadBux(ctx, a, true, _services.Logger); err != nil { return nil, err } @@ -124,11 +133,13 @@ func (s *AppServices) CloseAll(ctx context.Context) { } // All services closed! - logger.Data(2, logger.DEBUG, "all services have been closed") + if s.Logger != nil { + s.Logger.Debug().Msg("all services have been closed") + } } // loadBux will load the bux client (including CacheStore and DataStore) -func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig, testMode bool) (err error) { +func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig, testMode bool, logger *zerolog.Logger) (err error) { var options []bux.ClientOps // Set new relic if enabled @@ -149,7 +160,10 @@ func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig, testMod options = append(options, bux.WithImportBlockHeaders(appConfig.ImportBlockHeaders)) } - // todo: customize the logger + if logger != nil { + buxLogger := logger.With().Str("service", "bux").Logger() + options = append(options, bux.WithLogger(&buxLogger)) + } // todo: feature: override the config from JSON env (side-load your own /envs/custom-config.json diff --git a/go.mod b/go.mod index 4c8496afb..03558898c 100644 --- a/go.mod +++ b/go.mod @@ -4,37 +4,28 @@ go 1.19 require ( github.com/99designs/gqlgen v0.17.41 - github.com/BuxOrg/bux v0.8.0 + github.com/BuxOrg/bux v0.8.1 github.com/BuxOrg/bux-models v0.2.1 github.com/bitcoin-sv/go-broadcast-client v0.9.0 github.com/go-ozzo/ozzo-validation v3.6.0+incompatible github.com/go-redis/redis/v8 v8.11.5 github.com/gofrs/uuid v4.4.0+incompatible github.com/julienschmidt/httprouter v1.3.0 - github.com/mrz1836/go-api-router v0.7.0 + github.com/mrz1836/go-api-router v0.6.2 github.com/mrz1836/go-cachestore v0.3.3 github.com/mrz1836/go-datastore v0.5.8 - github.com/mrz1836/go-logger v0.3.2 github.com/mrz1836/go-parameters v0.4.1 github.com/mrz1836/go-sanitize v1.3.1 github.com/mrz1836/go-validate v0.2.0 github.com/newrelic/go-agent/v3 v3.28.1 github.com/newrelic/go-agent/v3/integrations/nrhttprouter v1.0.2 + github.com/rs/zerolog v1.31.0 github.com/spf13/viper v1.18.1 github.com/stretchr/testify v1.8.4 github.com/swaggo/swag v1.16.2 github.com/vektah/gqlparser/v2 v2.5.10 ) -require ( - github.com/jackc/puddle/v2 v2.2.1 // indirect - github.com/libsv/go-p2p v0.1.4 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/rs/zerolog v1.31.0 // indirect - go.elastic.co/ecszerolog v0.2.0 // indirect -) - require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/agnivade/levenshtein v1.1.1 // indirect @@ -68,7 +59,7 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect - github.com/google/uuid v1.4.0 // indirect + github.com/google/uuid v1.5.0 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.1 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect @@ -77,7 +68,8 @@ require ( github.com/iancoleman/strcase v0.3.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect - github.com/jackc/pgx/v5 v5.5.0 // indirect + github.com/jackc/pgx/v5 v5.5.1 // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -88,14 +80,18 @@ require ( github.com/libsv/go-bk v0.1.6 // indirect github.com/libsv/go-bt v1.0.8 // indirect github.com/libsv/go-bt/v2 v2.2.5 // indirect + github.com/libsv/go-p2p v0.1.4 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/matryer/respond v1.0.1 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.18 // indirect github.com/miekg/dns v1.1.57 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/montanaflynn/stats v0.7.1 // indirect github.com/mrz1836/go-cache v0.9.2 // indirect + github.com/mrz1836/go-logger v0.3.2 // indirect github.com/newrelic/go-agent/v3/integrations/nrmongo v1.1.2 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -126,6 +122,7 @@ require ( github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect + go.elastic.co/ecszerolog v0.2.0 go.mongodb.org/mongo-driver v1.13.1 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.16.0 // indirect @@ -135,9 +132,9 @@ require ( golang.org/x/sync v0.5.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.16.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect - google.golang.org/grpc v1.59.0 // indirect + golang.org/x/tools v0.16.1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect + google.golang.org/grpc v1.60.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 8276b804a..3d9e3d53d 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/99designs/gqlgen v0.17.41 h1:C1/zYMhGVP5TWNCNpmZ9Mb6CqT1Vr5SHEWoTOEJ3 github.com/99designs/gqlgen v0.17.41/go.mod h1:GQ6SyMhwFbgHR0a8r2Wn8fYgEwPxxmndLFPhU63+cJE= github.com/BuxOrg/bux v0.8.0 h1:i/oZMSZYJV5BWDiNEEQ21SVUSwJPcy2PaiKUf4zI3Pc= github.com/BuxOrg/bux v0.8.0/go.mod h1:9h8+Sdw907Cf2IzVrlH16O/K6kyxUGfpp3wqO+ous4k= +github.com/BuxOrg/bux v0.8.1 h1:YEMK1LXOEJyFqyqafH7ZI0jm19a+y5HiNFQh5ZRCdbk= +github.com/BuxOrg/bux v0.8.1/go.mod h1:9h8+Sdw907Cf2IzVrlH16O/K6kyxUGfpp3wqO+ous4k= github.com/BuxOrg/bux-models v0.2.1 h1:wgNTYCqisH3M+Z87hb0Jpbxc8MMdOEJ35mdw/WoZ73k= github.com/BuxOrg/bux-models v0.2.1/go.mod h1:nH3MOdsIPPerBPOiEvwA01yTeArYtBk+PtDo7E+vPCk= github.com/DATA-DOG/go-sqlmock v1.5.1 h1:FK6RCIUSfmbnI/imIICmboyQBkOckutaa6R5YYlLZyo= @@ -143,6 +145,8 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= @@ -165,6 +169,8 @@ github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw= github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= +github.com/jackc/pgx/v5 v5.5.1 h1:5I9etrGkLrN+2XPCsi6XLlV5DITbSL/xBZdmAxFcXPI= +github.com/jackc/pgx/v5 v5.5.1/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= @@ -231,8 +237,8 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= -github.com/mrz1836/go-api-router v0.7.0 h1:RTnU4g92IiTLDEHBUuftnTMfGRIc9/Q7y1wDUYJEV5E= -github.com/mrz1836/go-api-router v0.7.0/go.mod h1:zIj4Fe4mLx+VZjtWvxvPcfJMo9l8J/xEB5mDWh2oGQU= +github.com/mrz1836/go-api-router v0.6.2 h1:6IhpqUf42scot4rcPO7q+vkWFMJMDbqZqbGrlUjKwxc= +github.com/mrz1836/go-api-router v0.6.2/go.mod h1:g/swptRngTcD7ro4DSOpbHA+sYPtmvWyoSZ4i4aTsFA= github.com/mrz1836/go-cache v0.9.2 h1:pQK3SJg6kfbn43oKW68R3qCWRILKSvSHs3qvwn8OzHc= github.com/mrz1836/go-cache v0.9.2/go.mod h1:IphLH8lmLdSI5N+8MswFEaqP1bJQ8800CxXre5nJD4M= github.com/mrz1836/go-cachestore v0.3.3 h1:E9f1frV38iAfpJ7vYR8bJ/F3GEdmPUTTFwxDf8DZP/A= @@ -481,14 +487,20 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= +golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 h1:DC7wcm+i+P1rN3Ff07vL+OndGg5OhNddHyTA+ocPqYE= google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4/go.mod h1:eJVxU6o+4G1PSczBr85xmyvSNYAKvAYgkub40YGomFM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 h1:/jFB8jK5R3Sq3i/lmeZO0cATSzFfZaJq1J2Euan3XKU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0/go.mod h1:FUoWkonphQm3RhTS+kOEhF8h0iDpm4tdXolVCeZ9KKA= google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= +google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k= +google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/logging.go b/logging.go new file mode 100644 index 000000000..2b8112e09 --- /dev/null +++ b/logging.go @@ -0,0 +1,72 @@ +package buxserver + +import ( + "io" + "os" + "time" + + "github.com/rs/zerolog" + "go.elastic.co/ecszerolog" +) + +const ( + consoleLogFormat = "console" + jsonLogFormat = "json" +) + +// CreateLogger create and configure zerolog logger based on app config. +func CreateLogger(instanceName, format, level string, logOrigin bool) (*zerolog.Logger, error) { + var writer io.Writer + if format == consoleLogFormat { + writer = zerolog.ConsoleWriter{ + Out: os.Stdout, + TimeFormat: "2006-01-02 15:04:05.000", + } + } else { + writer = os.Stdout + } + + parsedLevel, err := zerolog.ParseLevel(level) + if err != nil { + return nil, err + } + + logLevel := ecszerolog.Level(parsedLevel) + //var origin ecszerolog.Option + origin := ecszerolog.Origin() + var logger zerolog.Logger + + if logOrigin { + logger = ecszerolog.New(writer, logLevel, origin). + With(). + Timestamp(). + Str("application", instanceName). + Str("service", "bux-server"). + Logger() + } else { + logger = ecszerolog.New(writer, logLevel). + With(). + Timestamp(). + Str("application", instanceName). + Str("service", "bux-server"). + Logger() + } + + zerolog.TimestampFunc = func() time.Time { + return time.Now().In(time.Local) //nolint:gosmopolitan // We want local time inside logger. + } + + return &logger, nil +} + +// GetDefaultLogger create and configure default zerolog logger. It should be used before config is loaded +func GetDefaultLogger() *zerolog.Logger { + logger := ecszerolog.New(os.Stdout, ecszerolog.Level(zerolog.DebugLevel)). + With(). + Timestamp(). + Caller(). + Str("application", "bux-default"). + Logger() + + return &logger +} diff --git a/server/server.go b/server/server.go index 8a5b95dbf..d7d30bd9e 100644 --- a/server/server.go +++ b/server/server.go @@ -17,7 +17,6 @@ import ( "github.com/BuxOrg/bux-server/actions/xpubs" "github.com/BuxOrg/bux-server/config" apirouter "github.com/mrz1836/go-api-router" - "github.com/mrz1836/go-logger" "github.com/newrelic/go-agent/v3/integrations/nrhttprouter" httpSwagger "github.com/swaggo/http-swagger" ) @@ -70,11 +69,7 @@ func (s *Server) Serve() { // Listen and serve if err := s.WebServer.ListenAndServe(); err != nil { - logger.Data( - 2, - logger.DEBUG, - "shutting down "+config.ApplicationName+" server ["+err.Error()+"]...", - logger.MakeParameter("port", s.AppConfig.Server.Port)) + s.Services.Logger.Debug().Msgf("shutting down %s server [%s] on port %s...", config.ApplicationName, err.Error(), s.AppConfig.Server.Port) } } From 3a2a29da17462b431d591af2f1e8bc4a5c1f44a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Fri, 8 Dec 2023 15:44:42 +0100 Subject: [PATCH 2/8] chore(BUX-200): update configs --- config/config.go | 3 ++ config/envs/development.json | 78 ++++++++++----------------------- config/envs/docker-compose.json | 6 +++ config/envs/production.json | 6 +++ config/envs/staging.json | 6 +++ config/envs/test.json | 6 +++ config/load.go | 1 + 7 files changed, 52 insertions(+), 54 deletions(-) diff --git a/config/config.go b/config/config.go index f7577475b..11fe953b2 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,9 @@ package config import ( "errors" + "github.com/mrz1836/go-cachestore" + "github.com/mrz1836/go-datastore" + "github.com/tonicpow/go-minercraft/v2" "time" "github.com/BuxOrg/bux/cluster" diff --git a/config/envs/development.json b/config/envs/development.json index 9b6d7b2cf..8be69c970 100644 --- a/config/envs/development.json +++ b/config/envs/development.json @@ -1,24 +1,18 @@ { "debug": true, "debug_profiling": false, - "disable_itc": false, + "disable_itc": true, "environment": "development", - "import_block_headers": "", "gdpr_compliance": false, "request_logging": true, "use_mapi_fee_quotes": true, + "minercraft_api": "mAPI", "authentication": { - "admin_key": "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh", + "admin_key": "xpub661MyMwAqRbcFrBJbKwBGCB7d3fr2SaAuXGM95BA62X41m6eW2ehRQGW4xLi9wkEXUGnQZYxVVj4PxXnyrLk7jdqvBAs1Qq9gf6ykMvjR7J", "require_signing": false, "scheme": "xpub", "signing_disabled": true }, - "logging": { - "level": "debug", - "format": "console", - "instance_name": "bux-pawel", - "log_origin": false - }, "cache": { "engine": "freecache" }, @@ -32,7 +26,7 @@ }, "datastore": { "auto_migrate": true, - "engine": "postgresql", + "engine": "sqlite", "debug": false, "table_prefix": "xapi" }, @@ -45,15 +39,15 @@ "mongodb": { "database_name": "xapi", "transactions": false, - "uri": "mongodb://mongo:mongo@localhost:27017/" + "uri": "mongodb://localhost:27017/xapi" }, "monitor": { - "auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzaWdnaSIsImV4cCI6MTc1MDM4MTA2OH0.EXHm4MrwnJGjHIrdSUP39TyQZsieukWivCwqecQO0F8", - "bux_agent_url": "wss://siggi.siftbitcoin.com/websocket", - "debug": true, + "auth_token": "", + "bux_agent_url": "ws://localhost:8000/websocket", + "debug": false, "enabled": false, "false_positive_rate": 0.01, - "load_monitored_destinations": true, + "load_monitored_destinations": false, "max_number_of_destinations": 100000, "monitor_days": 7, "processor_type": "bloom", @@ -66,12 +60,11 @@ }, "paymail": { "enabled": true, - "default_from_paymail": "bux@pawel.4chain.space", + "default_from_paymail": "from@domain.com", "default_note": "bux Address Resolution", "domain_validation_enabled": false, "domains": [ - "localhost", - "pawel.4chain.space" + "localhost" ], "sender_validation_enabled": false }, @@ -88,13 +81,13 @@ "server": { "idle_timeout": "60s", "port": "3003", - "read_timeout": "40s", - "write_timeout": "40s" + "read_timeout": "15s", + "write_timeout": "15s" }, "sql": { "host": "localhost", - "name": "postgres", - "password": "postgres", + "name": "xapi", + "password": "", "_port": "3306", "port": "5432", "replica": false, @@ -112,41 +105,18 @@ "factory": "memory", "queue_name": "development_queue" }, + "broadcast_client_apis": [ + "url|token" + ], "use_beef": true, "pulse": { "pulse_url": "http://localhost:8000/api/v1/chain/merkleroot/verify", "pulse_auth_token": "asd" }, - "minercraft_custom_apis":[ - { - "minerid":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270", - "apis":[ - { - "token":"mainnet_3af382fadbc448b15cc4133242ac2621", - "url":"https://merchantapi.taal.com", - "type":"mAPI" - }, - { - "token":"mainnet_3af382fadbc448b15cc4133242ac2621", - "url":"https://tapi.taal.com/arc", - "type":"Arc" - } - ] - }, - { - "minerid":"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83", - "apis":[ - { - "token":"mainnet_3af382fadbc448b15cc4133242ac2621", - "url":"https://merchantapi.gorillapool.io", - "type":"mAPI" - }, - { - "token":"mainnet_3af382fadbc448b15cc4133242ac2621", - "url":"https://arc.gorillapool.io", - "type":"Arc" - } - ] - } - ] + "logging": { + "level": "debug", + "format": "console", + "instance_name": "bux-instance-development", + "log_origin": false + } } diff --git a/config/envs/docker-compose.json b/config/envs/docker-compose.json index 56a95c7cc..712df5b30 100644 --- a/config/envs/docker-compose.json +++ b/config/envs/docker-compose.json @@ -103,5 +103,11 @@ "pulse": { "pulse_url": "http://localhost:8000/api/v1/chain/merkleroot/verify", "pulse_auth_token": "asd" + }, + "logging": { + "level": "debug", + "format": "console", + "instance_name": "bux-instance-docker", + "log_origin": false } } diff --git a/config/envs/production.json b/config/envs/production.json index 75d172692..cd228867c 100644 --- a/config/envs/production.json +++ b/config/envs/production.json @@ -104,5 +104,11 @@ "pulse": { "pulse_url": "http://localhost:8000/api/v1/chain/merkleroot/verify", "pulse_auth_token": "asd" + }, + "logging": { + "level": "info", + "format": "json", + "instance_name": "bux-instance-prod", + "log_origin": true } } diff --git a/config/envs/staging.json b/config/envs/staging.json index d50bff405..96dc0f720 100644 --- a/config/envs/staging.json +++ b/config/envs/staging.json @@ -104,5 +104,11 @@ "pulse": { "pulse_url": "http://localhost:8000/api/v1/chain/merkleroot/verify", "pulse_auth_token": "asd" + }, + "logging": { + "level": "info", + "format": "json", + "instance_name": "bux-instance-staging", + "log_origin": true } } diff --git a/config/envs/test.json b/config/envs/test.json index d54b1d0f5..51947c9ac 100644 --- a/config/envs/test.json +++ b/config/envs/test.json @@ -103,5 +103,11 @@ "pulse": { "pulse_url": "http://localhost:8000/api/v1/chain/merkleroot/verify", "pulse_auth_token": "asd" + }, + "logging": { + "level": "info", + "format": "json", + "instance_name": "bux-instance-test", + "log_origin": true } } diff --git a/config/load.go b/config/load.go index e66351153..d5284248c 100644 --- a/config/load.go +++ b/config/load.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "github.com/mrz1836/go-datastore" "os" "strings" "sync" From b18d088dd5c5900f8756fca0c947988be143b5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Fri, 8 Dec 2023 15:52:09 +0100 Subject: [PATCH 3/8] chore(BUX-200): move logging methods to separate package --- config/services.go | 4 ++-- logging.go => logging/logging.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) rename logging.go => logging/logging.go (96%) diff --git a/config/services.go b/config/services.go index 0d96af595..b33ec586f 100644 --- a/config/services.go +++ b/config/services.go @@ -5,12 +5,12 @@ import ( "crypto/tls" "errors" "fmt" + "github.com/BuxOrg/bux-server/logging" "net/url" "strings" "time" "github.com/BuxOrg/bux" - "github.com/BuxOrg/bux-server" "github.com/BuxOrg/bux/chainstate" "github.com/BuxOrg/bux/cluster" "github.com/BuxOrg/bux/taskmanager" @@ -50,7 +50,7 @@ func (a *AppConfig) LoadServices(ctx context.Context) (*AppServices, error) { ctx = newrelic.NewContext(ctx, txn) defer txn.End() - logger, err := buxserver.CreateLogger(a.Logging.InstanceName, a.Logging.Format, a.Logging.Level, a.Logging.LogOrigin) + logger, err := logging.CreateLogger(a.Logging.InstanceName, a.Logging.Format, a.Logging.Level, a.Logging.LogOrigin) if err != nil { return nil, err } diff --git a/logging.go b/logging/logging.go similarity index 96% rename from logging.go rename to logging/logging.go index 2b8112e09..3f2e1f67b 100644 --- a/logging.go +++ b/logging/logging.go @@ -1,4 +1,4 @@ -package buxserver +package logging import ( "io" @@ -32,7 +32,6 @@ func CreateLogger(instanceName, format, level string, logOrigin bool) (*zerolog. } logLevel := ecszerolog.Level(parsedLevel) - //var origin ecszerolog.Option origin := ecszerolog.Origin() var logger zerolog.Logger From 001c5e262b7844f746a0d1c63d9ff5b74b3ef815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Mon, 11 Dec 2023 11:56:06 +0100 Subject: [PATCH 4/8] chore(BUX-200): refactor logs --- actions/graphql/routes.go | 4 ++-- cmd/server/main.go | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/actions/graphql/routes.go b/actions/graphql/routes.go index 1d0beec7a..f4c7c63c7 100644 --- a/actions/graphql/routes.go +++ b/actions/graphql/routes.go @@ -108,10 +108,10 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi ), ) if appConfig.Debug { - services.Logger.Debug().Msg("started graphql playground server on " + playgroundPath) + services.Logger.Debug().Msgf("started graphql playground server on %s", playgroundPath) } } else { - services.Logger.Error().Msg("Failed starting graphql playground server directory equals playground directory " + serverPath + " = " + playgroundPath) + services.Logger.Error().Msgf("Failed starting graphql playground server directory equals playground directory %s = %s", serverPath, playgroundPath) } } diff --git a/cmd/server/main.go b/cmd/server/main.go index 23645ffaf..8e86c086c 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -5,7 +5,6 @@ package main import ( "context" - "fmt" "os" "os/signal" "time" @@ -51,16 +50,15 @@ func main() { // (debugging: show services that are enabled or not) if appConfig.Debug { - services.Logger.Debug().Msg( - fmt.Sprintf("datastore: %s | cachestore: %s | taskmanager: %s [%s] | new_relic: %t | paymail: %t | graphql: %t", - appConfig.Datastore.Engine.String(), - appConfig.Cachestore.Engine.String(), - appConfig.TaskManager.Engine.String(), - appConfig.TaskManager.Factory.String(), - appConfig.NewRelic.Enabled, - appConfig.Paymail.Enabled, - appConfig.GraphQL.Enabled, - ), + services.Logger.Debug().Msgf( + "datastore: %s | cachestore: %s | taskmanager: %s [%s] | new_relic: %t | paymail: %t | graphql: %t", + appConfig.Datastore.Engine.String(), + appConfig.Cachestore.Engine.String(), + appConfig.TaskManager.Engine.String(), + appConfig.TaskManager.Factory.String(), + appConfig.NewRelic.Enabled, + appConfig.Paymail.Enabled, + appConfig.GraphQL.Enabled, ) } From bb5d666bdbb7ecbefe75d2dae7457e9349529e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Mon, 11 Dec 2023 19:16:38 +0100 Subject: [PATCH 5/8] chore(BUX-200): change log type --- cmd/server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 8e86c086c..a61e95413 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -35,7 +35,7 @@ func main() { // Load the Application Services var services *config.AppServices if services, err = appConfig.LoadServices(context.Background()); err != nil { - defaultLogger.Error().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingService), config.ApplicationName, err.Error()) + defaultLogger.Fatal().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingService), config.ApplicationName, err.Error()) return } From 425317444fa8be983a448732e708e5f24a7ddbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Wed, 13 Dec 2023 15:30:44 +0100 Subject: [PATCH 6/8] chore(BUX-200): update bux version --- go.sum | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/go.sum b/go.sum index 3d9e3d53d..23602ddc4 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/99designs/gqlgen v0.17.41 h1:C1/zYMhGVP5TWNCNpmZ9Mb6CqT1Vr5SHEWoTOEJ3v3I= github.com/99designs/gqlgen v0.17.41/go.mod h1:GQ6SyMhwFbgHR0a8r2Wn8fYgEwPxxmndLFPhU63+cJE= -github.com/BuxOrg/bux v0.8.0 h1:i/oZMSZYJV5BWDiNEEQ21SVUSwJPcy2PaiKUf4zI3Pc= -github.com/BuxOrg/bux v0.8.0/go.mod h1:9h8+Sdw907Cf2IzVrlH16O/K6kyxUGfpp3wqO+ous4k= github.com/BuxOrg/bux v0.8.1 h1:YEMK1LXOEJyFqyqafH7ZI0jm19a+y5HiNFQh5ZRCdbk= github.com/BuxOrg/bux v0.8.1/go.mod h1:9h8+Sdw907Cf2IzVrlH16O/K6kyxUGfpp3wqO+ous4k= github.com/BuxOrg/bux-models v0.2.1 h1:wgNTYCqisH3M+Z87hb0Jpbxc8MMdOEJ35mdw/WoZ73k= @@ -143,8 +141,6 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -167,8 +163,6 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw= -github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jackc/pgx/v5 v5.5.1 h1:5I9etrGkLrN+2XPCsi6XLlV5DITbSL/xBZdmAxFcXPI= github.com/jackc/pgx/v5 v5.5.1/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= @@ -485,20 +479,14 @@ golang.org/x/tools v0.0.0-20200530233709-52effbd89c51/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= -golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 h1:DC7wcm+i+P1rN3Ff07vL+OndGg5OhNddHyTA+ocPqYE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4/go.mod h1:eJVxU6o+4G1PSczBr85xmyvSNYAKvAYgkub40YGomFM= google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 h1:/jFB8jK5R3Sq3i/lmeZO0cATSzFfZaJq1J2Euan3XKU= google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0/go.mod h1:FUoWkonphQm3RhTS+kOEhF8h0iDpm4tdXolVCeZ9KKA= -google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= -google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k= google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= From 2aa4cbbe57cc4339b8072ad41d91b0b46484c352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Wed, 13 Dec 2023 15:45:04 +0100 Subject: [PATCH 7/8] chore(BUX-200): revert golanci config changes --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 383b069fe..e666f2e37 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -332,6 +332,7 @@ linters: - testpackage - nestif - nlreturn + - testifylint - goconst disable-all: false presets: From b562480890cc55926a9eee2f6b41053d88fd6d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= Date: Wed, 13 Dec 2023 15:53:17 +0100 Subject: [PATCH 8/8] chore(BUX-199): change log methods --- .golangci.yml | 1 + cmd/server/main.go | 6 +++--- config/config.go | 6 +++--- config/load.go | 2 +- config/services.go | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e666f2e37..ad71ed60d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -348,6 +348,7 @@ issues: # excluded by default patterns execute `golangci-lint run --help` exclude: - Using the variable on range scope .* in function literal + - should have a package comment # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: diff --git a/cmd/server/main.go b/cmd/server/main.go index a61e95413..564c926f8 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -28,7 +28,7 @@ func main() { // Load the Application Configuration appConfig, err := config.Load("") if err != nil { - defaultLogger.Error().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) + defaultLogger.Fatal().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) return } @@ -44,7 +44,7 @@ func main() { // Validate configuration (after services have been loaded) if err = appConfig.Validate(txn); err != nil { - services.Logger.Error().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) + services.Logger.Fatal().Msgf(dictionary.GetInternalMessage(dictionary.ErrorLoadingConfig), err.Error()) return } @@ -75,7 +75,7 @@ func main() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err = appServer.Shutdown(ctx); err != nil { - services.Logger.Error().Msgf("error shutting down: %s", err.Error()) + services.Logger.Fatal().Msgf("error shutting down: %s", err.Error()) } close(idleConnectionsClosed) diff --git a/config/config.go b/config/config.go index 11fe953b2..ffb840cbc 100644 --- a/config/config.go +++ b/config/config.go @@ -3,15 +3,15 @@ package config import ( "errors" - "github.com/mrz1836/go-cachestore" - "github.com/mrz1836/go-datastore" - "github.com/tonicpow/go-minercraft/v2" "time" "github.com/BuxOrg/bux/cluster" "github.com/BuxOrg/bux/taskmanager" validation "github.com/go-ozzo/ozzo-validation" + "github.com/mrz1836/go-cachestore" + "github.com/mrz1836/go-datastore" "github.com/newrelic/go-agent/v3/newrelic" + "github.com/tonicpow/go-minercraft/v2" ) // Config constants used for optimization and value testing diff --git a/config/load.go b/config/load.go index d5284248c..3a9c0d066 100644 --- a/config/load.go +++ b/config/load.go @@ -2,12 +2,12 @@ package config import ( "fmt" - "github.com/mrz1836/go-datastore" "os" "strings" "sync" "github.com/BuxOrg/bux-server/dictionary" + "github.com/mrz1836/go-datastore" "github.com/spf13/viper" ) diff --git a/config/services.go b/config/services.go index b33ec586f..8f62dcbbf 100644 --- a/config/services.go +++ b/config/services.go @@ -5,12 +5,12 @@ import ( "crypto/tls" "errors" "fmt" - "github.com/BuxOrg/bux-server/logging" "net/url" "strings" "time" "github.com/BuxOrg/bux" + "github.com/BuxOrg/bux-server/logging" "github.com/BuxOrg/bux/chainstate" "github.com/BuxOrg/bux/cluster" "github.com/BuxOrg/bux/taskmanager"