github.com/jenkins-x/jx/v2@v2.1.155/cmd/codegen/util/logger.go (about) 1 package util 2 3 import ( 4 "os" 5 6 log "github.com/sirupsen/logrus" 7 ) 8 9 const ( 10 // AppName is tge application name for logging. 11 AppName = "codegen" 12 ) 13 14 var ( 15 logger = log.WithFields(log.Fields{"app": AppName}) 16 ) 17 18 func init() { 19 // Output to stdout instead of the default stderr 20 log.SetOutput(os.Stdout) 21 } 22 23 // AppLogger returns the application logger. 24 func AppLogger() *log.Entry { 25 return logger 26 } 27 28 // SetLevel sets the logging level 29 func SetLevel(s string) error { 30 level, err := log.ParseLevel(s) 31 if err != nil { 32 return err 33 } 34 logger.Debugf("logging set to level: %s", level) 35 log.SetLevel(level) 36 return nil 37 }