Merge pull request #2106 from Random-Liu/add-trace-level-support
Support trace level.
This commit is contained in:
commit
e92c913ea5
@ -54,7 +54,7 @@ func main() {
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log-level,l",
|
||||
Usage: "set the logging level [debug, info, warn, error, fatal, panic]",
|
||||
Usage: "set the logging level [trace, debug, info, warn, error, fatal, panic]",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "address,a",
|
||||
@ -192,7 +192,7 @@ func setLevel(context *cli.Context, config *server.Config) error {
|
||||
l = config.Debug.Level
|
||||
}
|
||||
if l != "" {
|
||||
lvl, err := logrus.ParseLevel(l)
|
||||
lvl, err := log.ParseLevel(l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -21,6 +21,19 @@ type (
|
||||
loggerKey struct{}
|
||||
)
|
||||
|
||||
// TraceLevel is the log level for tracing. Trace level is lower than debug level,
|
||||
// and is usually used to trace detailed behavior of the program.
|
||||
const TraceLevel = logrus.Level(uint32(logrus.DebugLevel + 1))
|
||||
|
||||
// ParseLevel takes a string level and returns the Logrus log level constant.
|
||||
// It supports trace level.
|
||||
func ParseLevel(lvl string) (logrus.Level, error) {
|
||||
if lvl == "trace" {
|
||||
return TraceLevel, nil
|
||||
}
|
||||
return logrus.ParseLevel(lvl)
|
||||
}
|
||||
|
||||
// WithLogger returns a new context with the provided logger. Use in
|
||||
// combination with logger.WithField(s) for great effect.
|
||||
func WithLogger(ctx context.Context, logger *logrus.Entry) context.Context {
|
||||
@ -38,3 +51,17 @@ func GetLogger(ctx context.Context) *logrus.Entry {
|
||||
|
||||
return logger.(*logrus.Entry)
|
||||
}
|
||||
|
||||
// Trace logs a message at level Trace with the log entry passed-in.
|
||||
func Trace(e *logrus.Entry, args ...interface{}) {
|
||||
if e.Level >= TraceLevel {
|
||||
e.Debug(args...)
|
||||
}
|
||||
}
|
||||
|
||||
// Tracef logs a message at level Trace with the log entry passed-in.
|
||||
func Tracef(e *logrus.Entry, format string, args ...interface{}) {
|
||||
if e.Level >= TraceLevel {
|
||||
e.Debugf(format, args...)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user