Skip to content
Snippets Groups Projects
Unverified Commit b787780e authored by Wolfgang Welz's avatar Wolfgang Welz Committed by GitHub
Browse files

Merge pull request #93 from iotaledger/feat/logger-update

Updates to the new logger in hive.go
parents c7496bf6 bcf3977f
No related branches found
No related tags found
No related merge requests found
Showing
with 94 additions and 184 deletions
{
"node": {
"logLevel": 3,
"disablePlugins": [],
"enablePlugins": []
"analysis":{
"serveraddress":"ressims.iota.cafe:188",
"serverport":0
},
"autopeering":{
"address":"0.0.0.0",
"entrynodes":[
"V8LYtWWcPYYDTTXLeIEFjJEuWlsjDiI0+Pq/Cx9ai6g=@116.202.49.178:14626"
],
"port":14626,
"selection":true
},
"database":{
"directory":"mainnetdb"
},
"analysis": {
"serverPort": 0,
"serverAddress": "ressims.iota.cafe:188"
},
"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
......@@ -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
......
......
......@@ -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=
......
......
......@@ -28,6 +28,8 @@ import (
)
func main() {
cli.LoadConfig()
go http.ListenAndServe("localhost:6060", nil) // pprof Server for Debbuging Mutexes
node.Run(
......
......
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()
}
......@@ -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
}
......
......
......@@ -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
......
......
......@@ -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)
......
......
......@@ -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))
......
......
......@@ -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
......
......
......@@ -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 {
......
......
......@@ -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() {
......
......
......@@ -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) {
......
......
......@@ -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)
......
......
......@@ -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 ...")
}
......
......
......@@ -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}
......
......
......@@ -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)
}
......
......
......@@ -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() {
......
......
......@@ -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)
......
......
package statusscreen
import "time"
const (
REPAINT_INTERVAL = 500 * time.Millisecond
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment