/golang-helpers

Common Golang helpers

Primary LanguageGoApache License 2.0Apache-2.0

golang-helpers

Common Golang helpers

Logger

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()))
}

Contributing

Open in a container