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).
This commit is contained in:
parent
ae67a45a1c
commit
2b785f293b
@ -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) {
|
||||
|
||||
@ -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)}
|
||||
}
|
||||
|
||||
@ -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())
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user