From dfdeee43fc1a84585d47e939dd4aed9c3da844a7 Mon Sep 17 00:00:00 2001 From: Luca Moser <moser.luca@gmail.com> Date: Wed, 8 Jan 2020 11:44:17 +0100 Subject: [PATCH] updates to new logger --- go.mod | 6 +----- go.sum | 11 +++++++---- main.go | 2 ++ .../transactionspammer/transactionspammer.go | 5 +++-- plugins/analysis/client/plugin.go | 3 ++- plugins/analysis/plugin.go | 3 ++- plugins/analysis/server/plugin.go | 3 ++- plugins/autopeering/plugin.go | 4 +++- plugins/bundleprocessor/plugin.go | 3 ++- plugins/cli/plugin.go | 17 ++++++++++++----- plugins/dashboard/plugin.go | 3 ++- plugins/gossip/plugin.go | 3 ++- plugins/gracefulshutdown/plugin.go | 8 +++++--- plugins/statusscreen/logger.go | 2 +- plugins/statusscreen/status_message.go | 2 +- plugins/statusscreen/statusscreen.go | 8 +------- plugins/statusscreen/ui_log_entry.go | 6 +----- plugins/tangle/plugin.go | 3 ++- plugins/tangle/solidifier.go | 2 +- plugins/ui/logger.go | 10 +++++----- plugins/ui/ui.go | 2 +- plugins/validator/plugin.go | 4 ++-- plugins/webapi-send-data/plugin.go | 5 +++-- plugins/webapi-tx-request/plugin.go | 3 ++- plugins/webapi/plugin.go | 3 ++- plugins/zeromq/plugin.go | 3 ++- 26 files changed, 69 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index ea59aaa2..e07f8c2e 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 c7061245..4f7c6430 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 54e57bab..64789962 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/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go index 8767c14a..a2cae4ae 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 1dd30548..da700fad 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 0208ca1d..8be4a842 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 40fabc28..35973f84 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/plugin.go b/plugins/autopeering/plugin.go index 4ba57d0c..1952d5c7 100644 --- a/plugins/autopeering/plugin.go +++ b/plugins/autopeering/plugin.go @@ -16,9 +16,11 @@ const ( var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) -var log = logger.NewLogger(name) +var log *logger.Logger func configure(*node.Plugin) { + log = logger.NewLogger(name) + configureEvents() configureAP() } diff --git a/plugins/bundleprocessor/plugin.go b/plugins/bundleprocessor/plugin.go index c95eeeed..0f013307 100644 --- a/plugins/bundleprocessor/plugin.go +++ b/plugins/bundleprocessor/plugin.go @@ -11,9 +11,10 @@ import ( ) var PLUGIN = node.NewPlugin("Bundle Processor", node.Enabled, configure, run) -var log = logger.NewLogger("Bundle Processor") +var log *logger.Logger func configure(plugin *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 d4da0e2a..fe3bbc0a 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 f263b4b8..4321e0b5 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/plugin.go b/plugins/gossip/plugin.go index 56babd44..2c6d6a8d 100644 --- a/plugins/gossip/plugin.go +++ b/plugins/gossip/plugin.go @@ -20,9 +20,10 @@ const ( var PLUGIN = node.NewPlugin(name, node.Enabled, configure, run) -var log = logger.NewLogger(name) +var log *logger.Logger func configure(*node.Plugin) { + log = logger.NewLogger(name) configureGossip() configureEvents() } diff --git a/plugins/gracefulshutdown/plugin.go b/plugins/gracefulshutdown/plugin.go index 15d5cbe6..2cc52379 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/logger.go b/plugins/statusscreen/logger.go index 871472bf..5d9d780b 100644 --- a/plugins/statusscreen/logger.go +++ b/plugins/statusscreen/logger.go @@ -6,7 +6,7 @@ import ( "github.com/iotaledger/hive.go/logger" ) -func storeStatusMessage(logLevel logger.LogLevel, prefix string, message string) { +func storeStatusMessage(logLevel logger.Level, prefix string, message string) { mutex.Lock() defer mutex.Unlock() messageLog = append(messageLog, &StatusMessage{ diff --git a/plugins/statusscreen/status_message.go b/plugins/statusscreen/status_message.go index 96ae34ee..2ec23aff 100644 --- a/plugins/statusscreen/status_message.go +++ b/plugins/statusscreen/status_message.go @@ -8,7 +8,7 @@ import ( type StatusMessage struct { Source string - LogLevel logger.LogLevel + LogLevel logger.Level Message string Time time.Time } diff --git a/plugins/statusscreen/statusscreen.go b/plugins/statusscreen/statusscreen.go index e488b59a..0d51af1e 100644 --- a/plugins/statusscreen/statusscreen.go +++ b/plugins/statusscreen/statusscreen.go @@ -1,7 +1,6 @@ package statusscreen import ( - "io/ioutil" "os" "sync" "time" @@ -26,19 +25,14 @@ func configure(plugin *node.Plugin) { 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) { + anyLogMsgClosure := events.NewClosure(func(logLevel logger.Level, 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() diff --git a/plugins/statusscreen/ui_log_entry.go b/plugins/statusscreen/ui_log_entry.go index fc8db3a7..4134636d 100644 --- a/plugins/statusscreen/ui_log_entry.go +++ b/plugins/statusscreen/ui_log_entry.go @@ -39,16 +39,12 @@ func NewUILogEntry(message StatusMessage) *UILogEntry { switch message.LogLevel { 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: diff --git a/plugins/tangle/plugin.go b/plugins/tangle/plugin.go index 62006c6b..02048012 100644 --- a/plugins/tangle/plugin.go +++ b/plugins/tangle/plugin.go @@ -8,9 +8,10 @@ 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(plugin *node.Plugin) { + log = logger.NewLogger("Tangle") configureTransactionDatabase(plugin) configureTransactionMetaDataDatabase(plugin) configureApproversDatabase(plugin) diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index af7b07c5..696bd3d0 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -38,7 +38,7 @@ func configureSolidifier(plugin *node.Plugin) { 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/ui/logger.go b/plugins/ui/logger.go index 08658c43..cf488427 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 02e248a3..f4458e58 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 11217efc..b20ba75d 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 778a41b2..c7029181 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 a10ac0ea..5f4e4282 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 e7d7c5a3..6cd2e037 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 c9d469a8..11ddb33c 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() { -- GitLab