From 2b785f293b6038586e84c5a09bc7932e8d839303 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Mon, 7 Aug 2023 22:55:45 +0200 Subject: [PATCH] logflags: simplify Logger interface (#3274) Remove methods we never used or used only very sparingly (Print) and we probably shouldn't be using at all (Fatal). --- pkg/logflags/logflags.go | 2 +- pkg/logflags/logger.go | 36 ------------------------------------ pkg/proc/bininfo.go | 2 +- service/dap/server.go | 11 ++++++----- 4 files changed, 8 insertions(+), 43 deletions(-) diff --git a/pkg/logflags/logflags.go b/pkg/logflags/logflags.go index acf4cb5a7a..571913239d 100644 --- a/pkg/logflags/logflags.go +++ b/pkg/logflags/logflags.go @@ -163,7 +163,7 @@ func writeListeningMessage(server string, addr net.Addr) { return } logger := rpcLogger(true) - logger.Warnln("Listening for remote connections (connections are not authenticated nor encrypted)") + logger.Warn("Listening for remote connections (connections are not authenticated nor encrypted)") } func WriteError(msg string) { diff --git a/pkg/logflags/logger.go b/pkg/logflags/logger.go index 14fd07ead3..8b79eaed33 100644 --- a/pkg/logflags/logger.go +++ b/pkg/logflags/logger.go @@ -8,39 +8,15 @@ import ( // Logger represents a generic interface for logging inside of // Delve codebase. type Logger interface { - // WithField returns a new Logger enriched with the given field. - WithField(key string, value interface{}) Logger - // WithFields returns a new Logger enriched with the given fields. - WithFields(fields Fields) Logger - // WithError returns a new Logger enriched with the given error. - WithError(err error) Logger - Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) - Printf(format string, args ...interface{}) Warnf(format string, args ...interface{}) - Warningf(format string, args ...interface{}) Errorf(format string, args ...interface{}) - Fatalf(format string, args ...interface{}) - Panicf(format string, args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) - Print(args ...interface{}) Warn(args ...interface{}) - Warning(args ...interface{}) Error(args ...interface{}) - Fatal(args ...interface{}) - Panic(args ...interface{}) - - Debugln(args ...interface{}) - Infoln(args ...interface{}) - Println(args ...interface{}) - Warnln(args ...interface{}) - Warningln(args ...interface{}) - Errorln(args ...interface{}) - Fatalln(args ...interface{}) - Panicln(args ...interface{}) } // LoggerFactory is used to create new Logger instances. @@ -63,15 +39,3 @@ type Fields map[string]interface{} type logrusLogger struct { *logrus.Entry } - -func (l *logrusLogger) WithField(key string, value interface{}) Logger { - return &logrusLogger{l.Entry.WithField(key, value)} -} - -func (l *logrusLogger) WithFields(fields Fields) Logger { - return &logrusLogger{l.Entry.WithFields(logrus.Fields(fields))} -} - -func (l *logrusLogger) WithError(err error) Logger { - return &logrusLogger{l.Entry.WithError(err)} -} diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 592774b0d3..c63fb16f4a 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -2143,7 +2143,7 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugInfoBytes, debugLineB if hasLineInfo && lineInfoOffset >= 0 && lineInfoOffset < int64(len(debugLineBytes)) { var logfn func(string, ...interface{}) if logflags.DebugLineErrors() { - logfn = logflags.DebugLineLogger().Printf + logfn = logflags.DebugLineLogger().Debugf } cu.lineInfo = line.Parse(compdir, bytes.NewBuffer(debugLineBytes[lineInfoOffset:]), image.debugLineStr, logfn, image.StaticBase, bi.GOOS == "windows", bi.Arch.PtrSize()) } diff --git a/service/dap/server.go b/service/dap/server.go index a0b6583408..990f9679ac 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -329,7 +329,8 @@ func NewSession(conn io.ReadWriteCloser, config *Config, debugger *debugger.Debu } config.log.Debugf("DAP connection %d started", sessionCount) if config.StopTriggered == nil { - config.log.Fatal("Session must be configured with StopTriggered") + config.log.Error("Session must be configured with StopTriggered") + os.Exit(1) } return &Session{ config: config, @@ -453,8 +454,8 @@ func (c *Config) triggerServerStop() { // we need to take that into consideration. func (s *Server) Run() { if s.listener == nil { - s.config.log.Fatal("Misconfigured server: no Listener is configured.") - return + s.config.log.Error("Misconfigured server: no Listener is configured.") + os.Exit(1) } go func() { @@ -492,8 +493,8 @@ func (s *Server) runSession(conn io.ReadWriteCloser) { // until a launch/attach request is received over the connection. func (s *Server) RunWithClient(conn net.Conn) { if s.listener != nil { - s.config.log.Fatal("RunWithClient must not be used when the Server is configured with a Listener") - return + s.config.log.Error("RunWithClient must not be used when the Server is configured with a Listener") + os.Exit(1) } s.config.log.Debugf("Connected to the client at %s", conn.RemoteAddr()) go s.runSession(conn)