Common Golang helpers
This is useful for getting a custom log level in a Cobra program.
package cmd
import "github.com/mrsimonemms/golang-helpers/logger"
var logLevel string
var root = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return logger.SetLevel(logLevel)
},
}
func init() {
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", logrus.InfoLevel.String(), fmt.Sprintf("log level: %s", logger.GetAllLevels()))
}