diff --git a/config.json b/config.json index b86b49442341bfc16b4f5350669236573e90e6d5..8550f6286b26a43241749146ee261612b75fe8cb 100644 --- a/config.json +++ b/config.json @@ -1,28 +1,34 @@ { - "node": { - "logLevel": 3, - "disablePlugins": [], - "enablePlugins": [] + "analysis":{ + "serveraddress":"ressims.iota.cafe:188", + "serverport":0 }, - "database": { - "directory": "mainnetdb" + "autopeering":{ + "address":"0.0.0.0", + "entrynodes":[ + "V8LYtWWcPYYDTTXLeIEFjJEuWlsjDiI0+Pq/Cx9ai6g=@116.202.49.178:14626" + ], + "port":14626, + "selection":true }, - "analysis": { - "serverPort": 0, - "serverAddress": "ressims.iota.cafe:188" + "database":{ + "directory":"mainnetdb" }, - "gossip": { - "port": 14666 + "gossip":{ + "port":14666 }, - "zeromq": { - "port": 5556 + "logger":{ + "Level":"info", + "DisableCaller":false, + "DisableStacktrace":false, + "Encoding":"console", + "OutputPaths":[ + "shimmer.log" + ] }, - "autopeering": { - "address": "0.0.0.0", - "port": 14626, - "entryNodes": [ - "V8LYtWWcPYYDTTXLeIEFjJEuWlsjDiI0+Pq/Cx9ai6g=@116.202.49.178:14626" - ], - "selection": true + "node":{ + "disableplugins":"", + "enableplugins":"", + "loglevel":0 } } \ No newline at end of file diff --git a/go.mod b/go.mod index ea59aaa23425e94de612a9ad00f427b418d87100..e07f8c2e3e59ed7efa7cdfd91ea1d4ce07a81c17 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/go-zeromq/zmq4 v0.7.0 github.com/golang/protobuf v1.3.2 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/hive.go v0.0.0-20200107124343-d0fddfc88dea + github.com/iotaledger/hive.go v0.0.0-20200107205115-986a54f82a30 github.com/iotaledger/iota.go v1.0.0-beta.13 github.com/labstack/echo v3.3.10+incompatible github.com/labstack/gommon v0.3.0 // indirect @@ -31,15 +31,11 @@ require ( github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/testify v1.4.0 github.com/valyala/fasttemplate v1.1.0 // indirect - go.uber.org/atomic v1.5.1 // indirect - go.uber.org/multierr v1.4.0 // indirect go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 - golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8 // indirect - golang.org/x/tools v0.0.0-20191230181014-9fb4d21460e1 // indirect golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect gopkg.in/ini.v1 v1.51.1 // indirect gopkg.in/yaml.v2 v2.2.7 // indirect diff --git a/go.sum b/go.sum index c70612451b8fe7b29bbb14d8afd5ae937e309aee..4f7c64308f02fa91e9857db754580790fac71bae 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M= github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= @@ -82,8 +83,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/iotaledger/hive.go v0.0.0-20200107124343-d0fddfc88dea h1:kLGh9F6KOOygmJPynFSgy7DSlFOg4/x5jmOMOF8vFaA= -github.com/iotaledger/hive.go v0.0.0-20200107124343-d0fddfc88dea/go.mod h1:vrZrvGaWT1o5kz3Jj2B/PcUtqsFzZnLWrO3zEsGSuwk= +github.com/iotaledger/hive.go v0.0.0-20200107205115-986a54f82a30 h1:eE0sEnnQ/HV7QtkUBEPFXPqMXPjUET2UIWDCDcUuGhk= +github.com/iotaledger/hive.go v0.0.0-20200107205115-986a54f82a30/go.mod h1:obs07gqna53/Yw1ltzLsQzJBMyA6lGu7Fb/ltjqWMnQ= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.13 h1:6m6JRcKtjTflU2PbjvDA9Tv6NTEJX1PijBDOkH9weQc= github.com/iotaledger/iota.go v1.0.0-beta.13/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= @@ -141,6 +142,7 @@ github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCr github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= @@ -192,6 +194,7 @@ github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= @@ -285,8 +288,8 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191230181014-9fb4d21460e1 h1:vNFL7Do+hbqZGmVjqkjTBUugGFXohWPyiHMLqLUbtP4= -golang.org/x/tools v0.0.0-20191230181014-9fb4d21460e1/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 h1:DnSr2mCsxyCE6ZgIkmcWUQY2R5cH/6wL7eIxEmQOMSE= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 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 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/main.go b/main.go index 54e57babf90e9eea570540de703e384a7bda287e..64789962bb42b933152631a6d82f9047c715a6b8 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,8 @@ import ( ) func main() { + cli.LoadConfig() + go http.ListenAndServe("localhost:6060", nil) // pprof Server for Debbuging Mutexes node.Run( diff --git a/packages/autopeering/logger/logger.go b/packages/autopeering/logger/logger.go deleted file mode 100644 index 9a14bb0586fe79f4911be65729ffe355a894cf20..0000000000000000000000000000000000000000 --- a/packages/autopeering/logger/logger.go +++ /dev/null @@ -1,60 +0,0 @@ -package logger - -import ( - "encoding/json" - "fmt" - - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -// NewLogger creates a logger with the supplied configuration. -func NewLogger(configJSON string, levelOverride string, opts ...zap.Option) *zap.SugaredLogger { - var loggingCfg zap.Config - if err := json.Unmarshal([]byte(configJSON), &loggingCfg); err != nil { - return newFallbackLogger(err, levelOverride, opts...) - } - if len(levelOverride) > 0 { - if level, err := levelFromString(levelOverride); err == nil { - loggingCfg.Level = zap.NewAtomicLevelAt(*level) - } - } - - logger, err := loggingCfg.Build(opts...) - if err != nil { - return newFallbackLogger(err, levelOverride, opts...) - } - - logger.Info("Successfully created the logger.") - logger.Sugar().Infof("Logging level set to %v", loggingCfg.Level) - - return logger.Sugar() -} - -func levelFromString(level string) (*zapcore.Level, error) { - var zapLevel zapcore.Level - if err := zapLevel.UnmarshalText([]byte(level)); err != nil { - return nil, fmt.Errorf("invalid logging level: %v", level) - } - return &zapLevel, nil -} - -func newFallbackLogger(cause error, levelOverride string, opts ...zap.Option) *zap.SugaredLogger { - loggingCfg := zap.NewProductionConfig() - if len(levelOverride) > 0 { - if level, err := levelFromString(levelOverride); err == nil { - loggingCfg.Level = zap.NewAtomicLevelAt(*level) - } - } - - logger, err := loggingCfg.Build(opts...) - if err != nil { - panic(err) - } - logger = logger.Named("fallback-logger") - - logger.Warn("Failed to create logger, using fallback:", zap.Error(cause)) - logger.Sugar().Infof("Logging level set to %v", loggingCfg.Level) - - return logger.Sugar() -} diff --git a/packages/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go index 8767c14a89090dd3c50e9a22645f4b9ba562d5ee..a2cae4aefa4b3ae824008dc44cc8332bc13c9b86 100644 --- a/packages/transactionspammer/transactionspammer.go +++ b/packages/transactionspammer/transactionspammer.go @@ -14,7 +14,7 @@ import ( "github.com/iotaledger/hive.go/logger" ) -var log = logger.NewLogger("Transaction Spammer") +var log *logger.Logger var spamming = false var spammingMutex sync.Mutex @@ -30,6 +30,7 @@ func init() { } func Start(tps uint) { + log = logger.NewLogger("Transaction Spammer") spammingMutex.Lock() spamming = true spammingMutex.Unlock() @@ -59,7 +60,7 @@ func Start(tps uint) { tx.SetTrunkTransactionHash(tipselection.GetRandomTip()) tx.SetTimestamp(uint(time.Now().Unix())) if err := tx.DoProofOfWork(meta_transaction.MIN_WEIGHT_MAGNITUDE); err != nil { - log.Warning("PoW failed", err) + log.Warn("PoW failed", err) continue } diff --git a/plugins/analysis/client/plugin.go b/plugins/analysis/client/plugin.go index 1dd3054876999f2d540c5aed9c11cc68662da274..da700fadeab250016a45421f3344e888141d9d77 100644 --- a/plugins/analysis/client/plugin.go +++ b/plugins/analysis/client/plugin.go @@ -23,9 +23,10 @@ import ( "github.com/iotaledger/hive.go/timeutil" ) -var log = logger.NewLogger("Analysis-Client") +var log *logger.Logger func Run(plugin *node.Plugin) { + log = logger.NewLogger("Analysis-Client") daemon.BackgroundWorker("Analysis Client", func(shutdownSignal <-chan struct{}) { shuttingDown := false diff --git a/plugins/analysis/plugin.go b/plugins/analysis/plugin.go index 0208ca1d915ff881849159c7402d4103dd3350e3..8be4a8422f10dff034cc7d90d793361115cf1243 100644 --- a/plugins/analysis/plugin.go +++ b/plugins/analysis/plugin.go @@ -10,9 +10,10 @@ import ( ) var PLUGIN = node.NewPlugin("Analysis", node.Enabled, configure, run) -var log = logger.NewLogger("Analysis") +var log *logger.Logger func configure(plugin *node.Plugin) { + log = logger.NewLogger("Analysis") if parameter.NodeConfig.GetInt(server.CFG_SERVER_PORT) != 0 { webinterface.Configure(plugin) server.Configure(plugin) diff --git a/plugins/analysis/server/plugin.go b/plugins/analysis/server/plugin.go index 40fabc28ac500b4d1203f3d0aa5e0232b10b5c08..35973f84a6fb701a4c1001c234750c6b004f41eb 100644 --- a/plugins/analysis/server/plugin.go +++ b/plugins/analysis/server/plugin.go @@ -21,9 +21,10 @@ import ( var server *tcp.Server -var log = logger.NewLogger("Analysis-Server") +var log *logger.Logger func Configure(plugin *node.Plugin) { + log = logger.NewLogger("Analysis-Server") server = tcp.NewServer() server.Events.Connect.Attach(events.NewClosure(HandleConnection)) diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index 3bbbd33957760e63177e1cdc4de8e873d0cd14b4..4d70e09eae26cda600a67d09abaa2b8374b561f8 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/iotaledger/goshimmer/packages/autopeering/discover" - "github.com/iotaledger/goshimmer/packages/autopeering/logger" "github.com/iotaledger/goshimmer/packages/autopeering/peer" "github.com/iotaledger/goshimmer/packages/autopeering/peer/service" "github.com/iotaledger/goshimmer/packages/autopeering/selection" @@ -15,6 +14,7 @@ import ( "github.com/iotaledger/goshimmer/packages/autopeering/transport" "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/hive.go/logger" "github.com/pkg/errors" ) @@ -23,30 +23,9 @@ var ( Discovery *discover.Protocol // Selection is the peer selection protocol. Selection *selection.Protocol -) - -const defaultZLC = `{ - "level": "info", - "development": false, - "outputPaths": ["./autopeering.log"], - "errorOutputPaths": ["stderr"], - "encoding": "console", - "encoderConfig": { - "timeKey": "ts", - "levelKey": "level", - "nameKey": "logger", - "callerKey": "caller", - "messageKey": "msg", - "stacktraceKey": "stacktrace", - "lineEnding": "", - "levelEncoder": "", - "timeEncoder": "iso8601", - "durationEncoder": "", - "callerEncoder": "" - } - }` -var zLogger = logger.NewLogger(defaultZLC, logLevel) + log *logger.Logger +) func configureAP() { masterPeers, err := parseEntryNodes() @@ -56,13 +35,13 @@ func configureAP() { log.Debugf("Master peers: %v", masterPeers) Discovery = discover.New(local.GetInstance(), discover.Config{ - Log: zLogger.Named("disc"), + Log: log.Named("disc"), MasterPeers: masterPeers, }) if parameter.NodeConfig.GetBool(CFG_SELECTION) { Selection = selection.New(local.GetInstance(), Discovery, selection.Config{ - Log: zLogger.Named("sel"), + Log: log.Named("sel"), Param: &selection.Parameters{ SaltLifetime: selection.DefaultSaltLifetime, RequiredService: []service.Key{service.GossipKey}, @@ -104,7 +83,7 @@ func start(shutdownSignal <-chan struct{}) { } // start a server doing discovery and peering - srv := server.Listen(local.GetInstance(), trans, zLogger.Named("srv"), handlers...) + srv := server.Listen(local.GetInstance(), trans, log.Named("srv"), handlers...) defer srv.Close() // start the discovery on that connection diff --git a/plugins/autopeering/local/local.go b/plugins/autopeering/local/local.go index 58381256aeb2b8ad2c1b0a1aedb03a1b4473be30..cfafcb89f974cbafad8b308399a8f630d3145d5e 100644 --- a/plugins/autopeering/local/local.go +++ b/plugins/autopeering/local/local.go @@ -11,7 +11,7 @@ import ( "github.com/iotaledger/goshimmer/packages/autopeering/peer" "github.com/iotaledger/goshimmer/packages/parameter" - "go.uber.org/zap" + "github.com/iotaledger/hive.go/logger" ) var ( @@ -35,11 +35,7 @@ func configureLocal() *peer.Local { port := strconv.Itoa(parameter.NodeConfig.GetInt(CFG_PORT)) // create a new local node - logger, err := zap.NewProduction() - if err != nil { - log.Fatalf("Could not create logger: %v", err) - } - db := peer.NewPersistentDB(logger.Named("db").Sugar()) + db := peer.NewPersistentDB(logger.NewLogger("local")) local, err := peer.NewLocal("udp", net.JoinHostPort(ip.String(), port), db) if err != nil { diff --git a/plugins/autopeering/plugin.go b/plugins/autopeering/plugin.go index 4ba57d0c0ee1a21ebb288c403977add4f2a081b1..da2fd92088708150e6d487e0be412ec8c8e0190b 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -9,22 +9,21 @@ import ( "github.com/iotaledger/hive.go/node" ) -const ( - name = "Autopeering" // name of the plugin - logLevel = "info" -) +const name = "Autopeering" // name of the plugin var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) -var log = logger.NewLogger(name) - func configure(*node.Plugin) { + log = logger.NewLogger(name) + configureEvents() configureAP() } func run(*node.Plugin) { - daemon.BackgroundWorker(name, start) + if err := daemon.BackgroundWorker(name, start); err != nil { + log.Errorf("Failed to start as daemon: %s", err) + } } func configureEvents() { diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index 5b78beae1e388d92b86858f1890caeacaf1234c9..6505583f451516b7db36c7d5a0c20d90d56fa490 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -11,9 +11,11 @@ import ( "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tipselection" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/iota.go/consts" "github.com/magiconair/properties/assert" + "github.com/spf13/viper" ) var seed = client.NewSeed("YFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCMSJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9Z", consts.SecurityLevelMedium) @@ -23,6 +25,7 @@ func init() { if err != nil { log.Fatalf("Failed to initialize config: %s", err) } + logger.InitGlobalLogger(&viper.Viper{}) } func BenchmarkValidateSignatures(b *testing.B) { diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index b36977156716b46725ca2153efd5d6b4498fc5a9..ad4ecb52eb13fcb1ea3b03a6947a2e0e9f3fc52d 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -11,9 +11,11 @@ import ( ) var PLUGIN = node.NewPlugin("Bundle Processor", node.Enabled, configure, run) -var log = logger.NewLogger("Bundle Processor") +var log *logger.Logger func configure(*node.Plugin) { + log = logger.NewLogger("Bundle Processor") + tangle.Events.TransactionSolid.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { if tx.IsHead() { workerPool.Submit(tx) diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index d4da0e2a5cc617f3bf6a55d608549774816337d3..39791c7c52a7e8f0f9506d4729f83e9414125c61 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -6,6 +6,7 @@ import ( "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" flag "github.com/spf13/pflag" ) @@ -43,6 +44,17 @@ func parseParameters() { } } +func LoadConfig() { + if err := parameter.FetchConfig(true); err != nil { + panic(err) + } + parseParameters() + + if err := logger.InitGlobalLogger(parameter.NodeConfig); err != nil { + panic(err) + } +} + func configure(ctx *node.Plugin) { fmt.Println(" _____ _ _ ________ ______ ___ ___________ ") @@ -53,11 +65,6 @@ func configure(ctx *node.Plugin) { fmt.Printf(" \\____/\\_| |_/\\___/\\_| |_/\\_| |_/\\____/\\_| \\_| fullnode %s", AppVersion) fmt.Println() - if err := parameter.FetchConfig(true); err != nil { - panic(err) - } - parseParameters() - ctx.Node.Logger.Info("Loading plugins ...") } diff --git a/plugins/dashboard/plugin.go b/plugins/dashboard/plugin.go index f263b4b88a1daae71811f16fa8c92c85e52e665e..4321e0b5c5f452fbb6498d400eb925f14107646e 100644 --- a/plugins/dashboard/plugin.go +++ b/plugins/dashboard/plugin.go @@ -17,9 +17,10 @@ var server *http.Server var router *http.ServeMux var PLUGIN = node.NewPlugin("Dashboard", node.Disabled, configure, run) -var log = logger.NewLogger("Dashboard") +var log *logger.Logger func configure(plugin *node.Plugin) { + log = logger.NewLogger("Dashboard") router = http.NewServeMux() server = &http.Server{Addr: ":8081", Handler: router} diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go index 8b552c69f800972eea094f5da6a1b6678a3ce056..aff925c7b9622f0d76b5417e54e9344b43a91f71 100644 --- a/plugins/gossip/gossip.go +++ b/plugins/gossip/gossip.go @@ -5,7 +5,6 @@ import ( "net" "strconv" - "github.com/iotaledger/goshimmer/packages/autopeering/logger" "github.com/iotaledger/goshimmer/packages/autopeering/peer/service" "github.com/iotaledger/goshimmer/packages/errors" gp "github.com/iotaledger/goshimmer/packages/gossip" @@ -13,36 +12,15 @@ import ( "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/goshimmer/plugins/autopeering/local" "github.com/iotaledger/goshimmer/plugins/tangle" + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/typeutils" ) var ( + log *logger.Logger mgr *gp.Manager ) -const defaultZLC = `{ - "level": "info", - "development": false, - "outputPaths": ["./gossip.log"], - "errorOutputPaths": ["stderr"], - "encoding": "console", - "encoderConfig": { - "timeKey": "ts", - "levelKey": "level", - "nameKey": "logger", - "callerKey": "caller", - "messageKey": "msg", - "stacktraceKey": "stacktrace", - "lineEnding": "", - "levelEncoder": "", - "timeEncoder": "iso8601", - "durationEncoder": "", - "callerEncoder": "" - } - }` - -var zLogger = logger.NewLogger(defaultZLC, logLevel) - func configureGossip() { lPeer := local.GetInstance() @@ -57,13 +35,13 @@ func configureGossip() { log.Fatalf("could not update services: %v", err) } - mgr = gp.NewManager(lPeer, getTransaction, zLogger) + mgr = gp.NewManager(lPeer, getTransaction, log) } func start(shutdownSignal <-chan struct{}) { defer log.Info("Stopping Gossip ... done") - srv, err := server.ListenTCP(local.GetInstance(), zLogger) + srv, err := server.ListenTCP(local.GetInstance(), log) if err != nil { log.Fatalf("ListenTCP: %v", err) } diff --git a/plugins/gossip/plugin.go b/plugins/gossip/plugin.go index 56babd44a2fcfc67027ec4f465d3f685d8037cc7..774364674fd7069c241f7d460b9c629ec5d8c059 100644 --- a/plugins/gossip/plugin.go +++ b/plugins/gossip/plugin.go @@ -13,22 +13,21 @@ import ( "github.com/iotaledger/hive.go/typeutils" ) -const ( - name = "Gossip" // name of the plugin - logLevel = "info" -) +const name = "Gossip" // name of the plugin var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) -var log = logger.NewLogger(name) - func configure(*node.Plugin) { + log = logger.NewLogger(name) + configureGossip() configureEvents() } func run(*node.Plugin) { - daemon.BackgroundWorker(name, start) + if err := daemon.BackgroundWorker(name, start); err != nil { + log.Errorf("Failed to start as daemon: %s", err) + } } func configureEvents() { diff --git a/plugins/gracefulshutdown/plugin.go b/plugins/gracefulshutdown/plugin.go index 15d5cbe64641dd81d08a59b4e10d2fe692f8ae55..2cc523798146b0c67d1686595e7a51e5484c3a66 100644 --- a/plugins/gracefulshutdown/plugin.go +++ b/plugins/gracefulshutdown/plugin.go @@ -15,8 +15,10 @@ import ( // maximum amount of time to wait for background processes to terminate. After that the process is killed. const WAIT_TO_KILL_TIME_IN_SECONDS = 10 -var log = logger.NewLogger("Graceful Shutdown") +var log *logger.Logger + var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node.Plugin) { + log = logger.NewLogger("Graceful Shutdown") gracefulStop := make(chan os.Signal) signal.Notify(gracefulStop, syscall.SIGTERM) @@ -25,7 +27,7 @@ var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node go func() { <-gracefulStop - log.Warningf("Received shutdown request - waiting (max %d) to finish processing ...", WAIT_TO_KILL_TIME_IN_SECONDS) + log.Warnf("Received shutdown request - waiting (max %d) to finish processing ...", WAIT_TO_KILL_TIME_IN_SECONDS) go func() { start := time.Now() @@ -38,7 +40,7 @@ var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node if len(runningBackgroundWorkers) >= 1 { processList = "(" + strings.Join(runningBackgroundWorkers, ", ") + ") " } - log.Warningf("Received shutdown request - waiting (max %d seconds) to finish processing %s...", WAIT_TO_KILL_TIME_IN_SECONDS-int(secondsSinceStart), processList) + log.Warnf("Received shutdown request - waiting (max %d seconds) to finish processing %s...", WAIT_TO_KILL_TIME_IN_SECONDS-int(secondsSinceStart), processList) } else { log.Error("Background processes did not terminate in time! Forcing shutdown ...") os.Exit(1) diff --git a/plugins/statusscreen/constants.go b/plugins/statusscreen/constants.go deleted file mode 100644 index 1fa6c46dac0ec691e0323e9e753952a2a7139b96..0000000000000000000000000000000000000000 --- a/plugins/statusscreen/constants.go +++ /dev/null @@ -1,7 +0,0 @@ -package statusscreen - -import "time" - -const ( - REPAINT_INTERVAL = 500 * time.Millisecond -) diff --git a/plugins/statusscreen/logger.go b/plugins/statusscreen/logger.go index 871472bf483435fd7eaa0107780acd9e1564eeff..10606990e2659ceb4a58f0267119bb457ed32856 100644 --- a/plugins/statusscreen/logger.go +++ b/plugins/statusscreen/logger.go @@ -1,31 +1,55 @@ package statusscreen import ( + stdlog "log" + "sync" "time" "github.com/iotaledger/hive.go/logger" ) -func storeStatusMessage(logLevel logger.LogLevel, prefix string, message string) { - mutex.Lock() - defer mutex.Unlock() - messageLog = append(messageLog, &StatusMessage{ - Source: prefix, - LogLevel: logLevel, - Message: message, - Time: time.Now(), +var ( + mu sync.Mutex + logMessages = make([]*logMessage, 0) + logMessagesByName = make(map[string]*logMessage) +) + +type logMessage struct { + time time.Time + name string + level logger.Level + msg string +} + +func stdLogMsg(level logger.Level, name string, msg string) { + stdlog.Printf("[ %s ] %s: %s", + level.CapitalString(), + name, + msg, + ) +} + +func storeLogMsg(level logger.Level, name string, message string) { + mu.Lock() + defer mu.Unlock() + + logMessages = append(logMessages, &logMessage{ + time: time.Now(), + name: name, + level: level, + msg: message, }) - if statusMessage, exists := statusMessages[prefix]; !exists { - statusMessages[prefix] = &StatusMessage{ - Source: prefix, - LogLevel: logLevel, - Message: message, - Time: time.Now(), + if statusMessage, exists := logMessagesByName[name]; !exists { + logMessagesByName[name] = &logMessage{ + time: time.Now(), + name: name, + level: level, + msg: message, } } else { - statusMessage.LogLevel = logLevel - statusMessage.Message = message - statusMessage.Time = time.Now() + statusMessage.time = time.Now() + statusMessage.level = level + statusMessage.msg = message } } diff --git a/plugins/statusscreen/plugin.go b/plugins/statusscreen/plugin.go new file mode 100644 index 0000000000000000000000000000000000000000..544e19004106076228876cc8703a3ca01a7a4391 --- /dev/null +++ b/plugins/statusscreen/plugin.go @@ -0,0 +1,81 @@ +package statusscreen + +import ( + "time" + + "github.com/iotaledger/hive.go/daemon" + "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/hive.go/node" +) + +const ( + name = "Statusscreen" + repaintInterval = 1 * time.Second +) + +var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) + +var ( + stdLogMsgClosure = events.NewClosure(stdLogMsg) + storeLogMsgClosure = events.NewClosure(storeLogMsg) +) + +func init() { + // use standard go logger by default + logger.Events.AnyMsg.Attach(stdLogMsgClosure) +} + +func configure(*node.Plugin) { + if !isTerminal() { + return + } + + // store any log message for display + logger.Events.AnyMsg.Attach(storeLogMsgClosure) + + log = logger.NewLogger(name) + configureTview() +} + +func run(*node.Plugin) { + if !isTerminal() { + return + } + + stopped := make(chan struct{}) + err := daemon.BackgroundWorker(name+" Refresher", func(shutdown <-chan struct{}) { + for { + select { + case <-time.After(repaintInterval): + app.QueueUpdateDraw(func() {}) + case <-shutdown: + logger.Events.AnyMsg.Detach(storeLogMsgClosure) + app.Stop() + return + case <-stopped: + return + } + } + }) + if err != nil { + log.Errorf("Failed to start as daemon: %s", err) + return + } + + err = daemon.BackgroundWorker(name+" App", func(<-chan struct{}) { + defer close(stopped) + + // switch logging to status screen + logger.Events.AnyMsg.Detach(stdLogMsgClosure) + defer logger.Events.AnyMsg.Attach(stdLogMsgClosure) + + if err := app.SetRoot(frame, true).SetFocus(frame).Run(); err != nil { + log.Errorf("Error running application: %s", err) + } + }) + if err != nil { + log.Errorf("Failed to start as daemon: %s", err) + close(stopped) + } +} diff --git a/plugins/statusscreen/status_message.go b/plugins/statusscreen/status_message.go deleted file mode 100644 index 96ae34ee95e6ad8cbbd38e5253ef366e6f21626f..0000000000000000000000000000000000000000 --- a/plugins/statusscreen/status_message.go +++ /dev/null @@ -1,14 +0,0 @@ -package statusscreen - -import ( - "time" - - "github.com/iotaledger/hive.go/logger" -) - -type StatusMessage struct { - Source string - LogLevel logger.LogLevel - Message string - Time time.Time -} diff --git a/plugins/statusscreen/statusscreen.go b/plugins/statusscreen/statusscreen.go index e488b59ac4510acd94cc3fce2e54597aaec62a0d..40acb01ba3fa40ea593118d47f0e6165210fcf9a 100644 --- a/plugins/statusscreen/statusscreen.go +++ b/plugins/statusscreen/statusscreen.go @@ -1,68 +1,22 @@ package statusscreen import ( - "io/ioutil" "os" - "sync" - "time" "github.com/gdamore/tcell" "github.com/iotaledger/hive.go/daemon" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" - "github.com/iotaledger/hive.go/node" "github.com/rivo/tview" "golang.org/x/crypto/ssh/terminal" ) -var statusMessages = make(map[string]*StatusMessage) -var messageLog = make([]*StatusMessage, 0) -var mutex sync.RWMutex - -var app *tview.Application - -func configure(plugin *node.Plugin) { - if !terminal.IsTerminal(int(os.Stdin.Fd())) { - return - } - - // don't write anything to stdout anymore - // as log messages are now stored and displayed via this plugin - logger.InjectWriters(ioutil.Discard) - - // store any log message for display - anyLogMsgClosure := events.NewClosure(func(logLevel logger.LogLevel, prefix string, msg string) { - storeStatusMessage(logLevel, prefix, msg) - }) - logger.Events.AnyMsg.Attach(anyLogMsgClosure) - - daemon.BackgroundWorker("UI-Detach", func(shutdownSignal <-chan struct{}) { - <-shutdownSignal - logger.InjectWriters(os.Stdout) - logger.Events.AnyMsg.Detach(anyLogMsgClosure) - if app != nil { - app.Stop() - } - }, 1) -} - -func run(plugin *node.Plugin) { - if !terminal.IsTerminal(int(os.Stdin.Fd())) { - return - } - - newPrimitive := func(text string) *tview.TextView { - textView := tview.NewTextView() - - textView. - SetTextAlign(tview.AlignLeft). - SetText(" " + text) - - return textView - } - - app = tview.NewApplication() +var ( + log *logger.Logger + app *tview.Application + frame *tview.Frame +) +func configureTview() { headerBar := NewUIHeaderBar() content := tview.NewGrid() @@ -84,30 +38,28 @@ func run(plugin *node.Plugin) { AddItem(content, 1, 0, 1, 1, 0, 0, false). AddItem(footer, 2, 0, 1, 1, 0, 0, false) - frame := tview.NewFrame(grid). + frame = tview.NewFrame(grid). SetBorders(1, 1, 0, 0, 2, 2) frame.SetBackgroundColor(tcell.ColorDarkGray) + app = tview.NewApplication() app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { + // end the daemon on ctrl+c if event.Key() == tcell.KeyCtrlC || event.Key() == tcell.KeyESC { daemon.Shutdown() - return nil } - return event }) app.SetBeforeDrawFunc(func(screen tcell.Screen) bool { - mutex.RLock() - defer mutex.RUnlock() headerBar.Update() rows := make([]int, 2) rows[0] = 1 rows[1] = 1 _, _, _, height := content.GetRect() - for i := 0; i < len(messageLog) && i < height-2; i++ { + for i := 0; i < len(logMessages) && i < height-2; i++ { rows = append(rows, 1) } @@ -118,12 +70,12 @@ func run(plugin *node.Plugin) { blankLine.SetBackgroundColor(tcell.ColorWhite) content.AddItem(blankLine, 0, 0, 1, 1, 0, 0, false) - logStart := len(messageLog) - (len(rows) - 2) + logStart := len(logMessages) - (len(rows) - 2) if logStart < 0 { logStart = 0 } - for i, message := range messageLog[logStart:] { + for i, message := range logMessages[logStart:] { if i < height-2 { content.AddItem(NewUILogEntry(*message).Primitive, i+1, 0, 1, 1, 0, 0, false) } @@ -135,23 +87,15 @@ func run(plugin *node.Plugin) { return false }) +} - daemon.BackgroundWorker("Statusscreen Refresher", func(shutdownSignal <-chan struct{}) { - for { - select { - case <-shutdownSignal: - return - case <-time.After(1 * time.Second): - app.QueueUpdateDraw(func() {}) - } - } - }) +func newPrimitive(text string) *tview.TextView { + textView := tview.NewTextView() + textView.SetTextAlign(tview.AlignLeft).SetText(" " + text) - daemon.BackgroundWorker("Statusscreen App", func(shutdownSignal <-chan struct{}) { - if err := app.SetRoot(frame, true).SetFocus(frame).Run(); err != nil { - panic(err) - } - }) + return textView } -var PLUGIN = node.NewPlugin("Status Screen", node.Enabled, configure, run) +func isTerminal() bool { + return terminal.IsTerminal(int(os.Stdin.Fd())) +} diff --git a/plugins/statusscreen/ui_log.go b/plugins/statusscreen/ui_log.go deleted file mode 100644 index 6dae65662bd2b2b100d954409c7435e558443587..0000000000000000000000000000000000000000 --- a/plugins/statusscreen/ui_log.go +++ /dev/null @@ -1,15 +0,0 @@ -package statusscreen - -import "github.com/rivo/tview" - -type UILog struct { - Primitive *tview.Grid -} - -func NewUILog() *UILog { - uiLog := &UILog{ - Primitive: tview.NewGrid(), - } - - return uiLog -} diff --git a/plugins/statusscreen/ui_log_entry.go b/plugins/statusscreen/ui_log_entry.go index fc8db3a76d581ea0466cf32f7c569f6b2522f483..57cbc6e7ebefa986056c8df36a3f1cb5003793f6 100644 --- a/plugins/statusscreen/ui_log_entry.go +++ b/plugins/statusscreen/ui_log_entry.go @@ -15,7 +15,7 @@ type UILogEntry struct { LogLevelContainer *tview.TextView } -func NewUILogEntry(message StatusMessage) *UILogEntry { +func NewUILogEntry(message logMessage) *UILogEntry { logEntry := &UILogEntry{ Primitive: tview.NewGrid(), TimeContainer: tview.NewTextView(), @@ -36,19 +36,15 @@ func NewUILogEntry(message StatusMessage) *UILogEntry { logEntry.LogLevelContainer.SetDynamicColors(true) textColor := "black::d" - switch message.LogLevel { + switch message.level { case logger.LevelInfo: fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [blue::d]INFO [black::d]]") - case logger.LevelNotice: - fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [blue::d]NOTICE [black::d]]") - case logger.LevelWarning: + case logger.LevelWarn: fmt.Fprintf(logEntry.LogLevelContainer, " [black::d][ [yellow::d]WARN [black::d]]") textColor = "yellow::d" case logger.LevelError: fallthrough - case logger.LevelCritical: - fallthrough case logger.LevelPanic: fallthrough case logger.LevelFatal: @@ -61,11 +57,11 @@ func NewUILogEntry(message StatusMessage) *UILogEntry { textColor = "black::b" } - fmt.Fprintf(logEntry.TimeContainer, " [black::b]"+message.Time.Format("15:04:05")) - if message.Source == "Node" { - fmt.Fprintf(logEntry.MessageContainer, "["+textColor+"]"+message.Message) + fmt.Fprintf(logEntry.TimeContainer, " [black::b]"+message.time.Format("15:04:05")) + if message.name == "Node" { + fmt.Fprintf(logEntry.MessageContainer, "["+textColor+"]"+message.msg) } else { - fmt.Fprintf(logEntry.MessageContainer, "["+textColor+"]"+message.Source+": "+message.Message) + fmt.Fprintf(logEntry.MessageContainer, "["+textColor+"]"+message.name+": "+message.msg) } logEntry.Primitive. diff --git a/plugins/tangle/plugin.go b/plugins/tangle/plugin.go index d7aa7c8f3f1925564cec7f35f8e2b774fcb5fe3f..6684986c5514af244f8907153b3f64dc45e3e772 100644 --- a/plugins/tangle/plugin.go +++ b/plugins/tangle/plugin.go @@ -8,9 +8,11 @@ import ( // region plugin module setup ////////////////////////////////////////////////////////////////////////////////////////// var PLUGIN = node.NewPlugin("Tangle", node.Enabled, configure, run) -var log = logger.NewLogger("Tangle") +var log *logger.Logger func configure(*node.Plugin) { + log = logger.NewLogger("Tangle") + configureTransactionDatabase() configureTransactionMetaDataDatabase() configureApproversDatabase() diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index d3d9127167e4397804df5c3af0f112197722c07a..e30ae82e9a95e89b9fbcb164212fd7e27e5bdefa 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -37,7 +37,7 @@ func configureSolidifier() { gossip.Events.TransactionReceived.Attach(events.NewClosure(func(ev *gossip.TransactionReceivedEvent) { metaTx := meta_transaction.FromBytes(ev.Data) if err := metaTx.Validate(); err != nil { - log.Warningf("invalid transaction: %s", err) + log.Warnf("invalid transaction: %s", err) return } diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go index 139febe3a4f2e240d9fc82f6629ce2868a6ec113..e93cfdce6fb9a5af113d590309784deb68aad5c9 100644 --- a/plugins/tangle/solidifier_test.go +++ b/plugins/tangle/solidifier_test.go @@ -9,7 +9,9 @@ import ( "github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/hive.go/events" + "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" + "github.com/spf13/viper" "github.com/stretchr/testify/require" ) @@ -18,6 +20,8 @@ func init() { if err != nil { log.Fatalf("Failed to initialize config: %s", err) } + + logger.InitGlobalLogger(&viper.Viper{}) } func TestSolidifier(t *testing.T) { diff --git a/plugins/ui/logger.go b/plugins/ui/logger.go index 08658c431719479887e08ce781c14bd9bf094330..cf488427123718f9de240d1cf2568874a12891eb 100644 --- a/plugins/ui/logger.go +++ b/plugins/ui/logger.go @@ -11,15 +11,15 @@ var logMutex = sync.RWMutex{} var logHistory = make([]*statusMessage, 0) type statusMessage struct { - Source string `json:"source"` - Level logger.LogLevel `json:"level"` - Message string `json:"message"` - Time time.Time `json:"time"` + Source string `json:"source"` + Level logger.Level `json:"level"` + Message string `json:"message"` + Time time.Time `json:"time"` } type resp map[string]interface{} -func storeAndSendStatusMessage(logLevel logger.LogLevel, pluginName string, message string) { +func storeAndSendStatusMessage(logLevel logger.Level, pluginName string, message string) { msg := &statusMessage{ Source: pluginName, diff --git a/plugins/ui/ui.go b/plugins/ui/ui.go index 02e248a3f64db98bf952866213b183de52262f60..f4458e58434f2c4339da661c6c043f043c4623fd 100644 --- a/plugins/ui/ui.go +++ b/plugins/ui/ui.go @@ -50,7 +50,7 @@ func configure(plugin *node.Plugin) { })) // store log messages to send them down via the websocket - anyMsgClosure := events.NewClosure(func(logLvl logger.LogLevel, prefix string, msg string) { + anyMsgClosure := events.NewClosure(func(logLvl logger.Level, prefix string, msg string) { storeAndSendStatusMessage(logLvl, prefix, msg) }) logger.Events.AnyMsg.Attach(anyMsgClosure) diff --git a/plugins/validator/plugin.go b/plugins/validator/plugin.go index 11217efc4604fd3394e940ed5256b9bbe3c0d32f..b20ba75d573100fd0e10af65600a0f3a0871366d 100644 --- a/plugins/validator/plugin.go +++ b/plugins/validator/plugin.go @@ -13,7 +13,7 @@ import ( ) var PLUGIN = node.NewPlugin("Validator", node.Enabled, configure, run) -var log = logger.NewLogger("Validator") +var log *logger.Logger func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransaction) (bool, error) { for i, tx := range txs { @@ -51,7 +51,7 @@ func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransacti } func configure(plugin *node.Plugin) { - + log = logger.NewLogger("Validator") bundleprocessor.Events.BundleSolid.Attach(events.NewClosure(func(b *bundle.Bundle, txs []*value_transaction.ValueTransaction) { // signature are verified against the bundle hash valid, err := validateSignatures(b.GetBundleEssenceHash(), txs) diff --git a/plugins/webapi-send-data/plugin.go b/plugins/webapi-send-data/plugin.go index 778a41b27b1deae8f5d88c0e8b9a21dd3f64f9d9..c7029181b5a0e7aa8b987e53b28bca9dbc6b9461 100644 --- a/plugins/webapi-send-data/plugin.go +++ b/plugins/webapi-send-data/plugin.go @@ -18,9 +18,10 @@ import ( ) var PLUGIN = node.NewPlugin("WebAPI SendData Endpoint", node.Enabled, configure) -var log = logger.NewLogger("API-sendData") +var log *logger.Logger func configure(plugin *node.Plugin) { + log = logger.NewLogger("API-sendData") webapi.AddEndpoint("sendData", SendDataHandler) } @@ -55,7 +56,7 @@ func SendDataHandler(c echo.Context) error { tx.SetTrunkTransactionHash(tipselection.GetRandomTip()) tx.SetTimestamp(uint(time.Now().Unix())) if err := tx.DoProofOfWork(meta_transaction.MIN_WEIGHT_MAGNITUDE); err != nil { - log.Warning("PoW failed", err) + log.Warn("PoW failed", err) } gossip.Events.TransactionReceived.Trigger(&gossip.TransactionReceivedEvent{Data: tx.GetBytes(), Peer: &local.GetInstance().Peer}) diff --git a/plugins/webapi-tx-request/plugin.go b/plugins/webapi-tx-request/plugin.go index a10ac0eada32f1e84602d5a61632052be6084d2a..5f4e4282548acacebab17b8c3b6f4ebd12b4c938 100644 --- a/plugins/webapi-tx-request/plugin.go +++ b/plugins/webapi-tx-request/plugin.go @@ -12,9 +12,10 @@ import ( ) var PLUGIN = node.NewPlugin("WebAPI Transaction Request Endpoint", node.Enabled, configure) -var log = logger.NewLogger("API-TxRequest") +var log *logger.Logger func configure(plugin *node.Plugin) { + log = logger.NewLogger("API-TxRequest") webapi.AddEndpoint("txRequest", Handler) } diff --git a/plugins/webapi/plugin.go b/plugins/webapi/plugin.go index e7d7c5a32fc1478c5fa59d25cd1251dc9c16bfb3..6cd2e037b3f6ad471df85dbe1b40dce0c50d17dd 100644 --- a/plugins/webapi/plugin.go +++ b/plugins/webapi/plugin.go @@ -11,11 +11,12 @@ import ( ) var PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run) -var log = logger.NewLogger("WebAPI") +var log *logger.Logger var Server = echo.New() func configure(plugin *node.Plugin) { + log = logger.NewLogger("WebAPI") Server.HideBanner = true Server.HidePort = true Server.GET("/", IndexRequest) diff --git a/plugins/zeromq/plugin.go b/plugins/zeromq/plugin.go index c9d469a85a6df97ec4b38379062a90447e1f58f6..11ddb33c23927cc873e6a8ff2d83e0288cd194d5 100644 --- a/plugins/zeromq/plugin.go +++ b/plugins/zeromq/plugin.go @@ -16,12 +16,13 @@ import ( // zeromq logging is disabled by default var PLUGIN = node.NewPlugin("ZeroMQ", node.Disabled, configure, run) -var log = logger.NewLogger("ZeroMQ") +var log *logger.Logger var publisher *Publisher var emptyTag = strings.Repeat("9", 27) // Configure the zeromq plugin func configure(plugin *node.Plugin) { + log = logger.NewLogger("ZeroMQ") tangle.Events.TransactionStored.Attach(events.NewClosure(func(tx *value_transaction.ValueTransaction) { // create goroutine for every event go func() {