Skip to content

Commit

Permalink
logflags: simplify Logger interface (#3274)
Browse files Browse the repository at this point in the history
Remove methods we never used or used only very sparingly (Print) and we
probably shouldn't be using at all (Fatal).
  • Loading branch information
aarzilli authored Aug 7, 2023
1 parent ae67a45 commit 2b785f2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pkg/logflags/logflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 0 additions & 36 deletions pkg/logflags/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)}
}
2 changes: 1 addition & 1 deletion pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
11 changes: 6 additions & 5 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2b785f2

Please sign in to comment.