mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 01:59:07 +00:00
moby: Create custom formatter for Info() log events
This formatter strips the prefix from Info() events to make the default output of "moby build" more readable. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
parent
e39b1ddffc
commit
8c012b75ff
@ -8,6 +8,22 @@ import (
|
|||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
defaultLogFormatter = &log.TextFormatter{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// infoFormatter overrides the default format for Info() log events to
|
||||||
|
// provide an easier to read output
|
||||||
|
type infoFormatter struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *infoFormatter) Format(entry *log.Entry) ([]byte, error) {
|
||||||
|
if entry.Level == log.InfoLevel {
|
||||||
|
return append([]byte(entry.Message), '\n'), nil
|
||||||
|
}
|
||||||
|
return defaultLogFormatter.Format(entry)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Printf("USAGE: %s [options] COMMAND\n\n", os.Args[0])
|
fmt.Printf("USAGE: %s [options] COMMAND\n\n", os.Args[0])
|
||||||
@ -52,7 +68,7 @@ func main() {
|
|||||||
runDisk := runCmd.String("disk", "", "Path to disk image to used")
|
runDisk := runCmd.String("disk", "", "Path to disk image to used")
|
||||||
|
|
||||||
// Set up logging
|
// Set up logging
|
||||||
log.SetFormatter(&log.TextFormatter{})
|
log.SetFormatter(new(infoFormatter))
|
||||||
log.SetLevel(log.InfoLevel)
|
log.SetLevel(log.InfoLevel)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *flagQuiet && *flagVerbose {
|
if *flagQuiet && *flagVerbose {
|
||||||
@ -63,6 +79,8 @@ func main() {
|
|||||||
log.SetLevel(log.ErrorLevel)
|
log.SetLevel(log.ErrorLevel)
|
||||||
}
|
}
|
||||||
if *flagVerbose {
|
if *flagVerbose {
|
||||||
|
// Switch back to the standard formatter
|
||||||
|
log.SetFormatter(defaultLogFormatter)
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user