From 280b1c6c83b676ef4e592f4ecf60cb5b54b6a753 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Tue, 16 Jun 2020 10:40:34 +0200 Subject: Optimize socketclient adapter and add various code improvements This commit includes: Features - optimized [socketclient](adapter/socketclient) adapter and add method to set client name - added list of compatible messages to `CompatibilityError` Fixes - `MsgCodec` will recover panic occurring during a message decoding - calling `Unsubscibe` will close the notification channel Other - improved log messages to provide more relevant info Examples - added more code samples of working with unions in [union example](examples/union-example) - added profiling mode to [perf bench](examples/perf-bench) example - improved [simple client](examples/simple-client) example to work properly even with multiple runs Dependencies - updated `github.com/sirupsen/logrus` dep to `v1.6.0` - updated `github.com/lunixbochs/struc` dep to `v0.0.0-20200521075829-a4cb8d33dbbe` Change-Id: I136a3968ccf9e93760d7ee2b9902fc7e6390a09d Signed-off-by: Ondrej Fabry --- core/log.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'core/log.go') diff --git a/core/log.go b/core/log.go index 5960d6b..dea6cbb 100644 --- a/core/log.go +++ b/core/log.go @@ -2,32 +2,35 @@ package core import ( "os" + "strings" - logger "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" ) var ( debug = os.Getenv("DEBUG_GOVPP") != "" - debugMsgIDs = os.Getenv("DEBUG_GOVPP_MSGIDS") != "" + debugMsgIDs = strings.Contains(os.Getenv("DEBUG_GOVPP"), "msgid") - log = logger.New() // global logger + log = logrus.New() ) -// init initializes global logger, which logs debug level messages to stdout. +// init initializes global logger func init() { - log.Out = os.Stdout + log.Formatter = &logrus.TextFormatter{ + EnvironmentOverrideColors: true, + } if debug { - log.Level = logger.DebugLevel - log.Debugf("govpp/core: debug mode enabled") + log.Level = logrus.DebugLevel + log.Debugf("govpp: debug level enabled") } } // SetLogger sets global logger to l. -func SetLogger(l *logger.Logger) { +func SetLogger(l *logrus.Logger) { log = l } // SetLogLevel sets global logger level to lvl. -func SetLogLevel(lvl logger.Level) { +func SetLogLevel(lvl logrus.Level) { log.Level = lvl } -- cgit 1.2.3-korg