Merge pull request #1211 from jonhenrik13/log-timestamp-v0.19.0
Add timestamp to logs
This commit is contained in:
		
						commit
						ae9c9b2813
					
				|  | @ -39,16 +39,18 @@ import ( | |||
| ) | ||||
| 
 | ||||
| var ( | ||||
| 	opts       = &config.KanikoOptions{} | ||||
| 	ctxSubPath string | ||||
| 	force      bool | ||||
| 	logLevel   string | ||||
| 	logFormat  string | ||||
| 	opts         = &config.KanikoOptions{} | ||||
| 	ctxSubPath   string | ||||
| 	force        bool | ||||
| 	logLevel     string | ||||
| 	logFormat    string | ||||
| 	logTimestamp bool | ||||
| ) | ||||
| 
 | ||||
| func init() { | ||||
| 	RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", logging.DefaultLevel, "Log level (trace, debug, info, warn, error, fatal, panic)") | ||||
| 	RootCmd.PersistentFlags().StringVar(&logFormat, "log-format", logging.FormatColor, "Log format (text, color, json)") | ||||
| 	RootCmd.PersistentFlags().BoolVar(&logTimestamp, "log-timestamp", logging.DefaultLogTimestamp, "Timestamp in log output") | ||||
| 	RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container") | ||||
| 
 | ||||
| 	addKanikoOptionsFlags() | ||||
|  | @ -62,7 +64,7 @@ var RootCmd = &cobra.Command{ | |||
| 		if cmd.Use == "executor" { | ||||
| 			resolveEnvironmentBuildArgs(opts.BuildArgs, os.Getenv) | ||||
| 
 | ||||
| 			if err := logging.Configure(logLevel, logFormat); err != nil { | ||||
| 			if err := logging.Configure(logLevel, logFormat, logTimestamp); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,14 +29,16 @@ import ( | |||
| ) | ||||
| 
 | ||||
| var ( | ||||
| 	opts      = &config.WarmerOptions{} | ||||
| 	logLevel  string | ||||
| 	logFormat string | ||||
| 	opts         = &config.WarmerOptions{} | ||||
| 	logLevel     string | ||||
| 	logFormat    string | ||||
| 	logTimestamp bool | ||||
| ) | ||||
| 
 | ||||
| func init() { | ||||
| 	RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", logging.DefaultLevel, "Log level (trace, debug, info, warn, error, fatal, panic)") | ||||
| 	RootCmd.PersistentFlags().StringVar(&logFormat, "log-format", logging.FormatColor, "Log format (text, color, json)") | ||||
| 	RootCmd.PersistentFlags().BoolVar(&logTimestamp, "log-timestamp", logging.DefaultLogTimestamp, "Timestamp in log output") | ||||
| 
 | ||||
| 	addKanikoOptionsFlags() | ||||
| 	addHiddenFlags() | ||||
|  | @ -45,7 +47,7 @@ func init() { | |||
| var RootCmd = &cobra.Command{ | ||||
| 	Use: "cache warmer", | ||||
| 	PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||||
| 		if err := logging.Configure(logLevel, logFormat); err != nil { | ||||
| 		if err := logging.Configure(logLevel, logFormat, logTimestamp); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 
 | ||||
|  |  | |||
|  | @ -26,6 +26,8 @@ import ( | |||
| const ( | ||||
| 	// Default log level
 | ||||
| 	DefaultLevel = "info" | ||||
| 	// Default timestamp in logs
 | ||||
| 	DefaultLogTimestamp = false | ||||
| 
 | ||||
| 	// Text format
 | ||||
| 	FormatText = "text" | ||||
|  | @ -36,7 +38,7 @@ const ( | |||
| ) | ||||
| 
 | ||||
| // Configure sets the logrus logging level and formatter
 | ||||
| func Configure(level, format string) error { | ||||
| func Configure(level, format string, logTimestamp bool) error { | ||||
| 	lvl, err := logrus.ParseLevel(level) | ||||
| 	if err != nil { | ||||
| 		return errors.Wrap(err, "parsing log level") | ||||
|  | @ -48,10 +50,12 @@ func Configure(level, format string) error { | |||
| 	case FormatText: | ||||
| 		formatter = &logrus.TextFormatter{ | ||||
| 			DisableColors: true, | ||||
| 			FullTimestamp: logTimestamp, | ||||
| 		} | ||||
| 	case FormatColor: | ||||
| 		formatter = &logrus.TextFormatter{ | ||||
| 			ForceColors: true, | ||||
| 			ForceColors:   true, | ||||
| 			FullTimestamp: logTimestamp, | ||||
| 		} | ||||
| 	case FormatJSON: | ||||
| 		formatter = &logrus.JSONFormatter{} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue