Add timestamp to logs
This commit is contained in:
parent
9f4fead7b5
commit
41a95fe4bd
4
Makefile
4
Makefile
|
|
@ -89,8 +89,8 @@ integration-test-misc:
|
||||||
.PHONY: images
|
.PHONY: images
|
||||||
images:
|
images:
|
||||||
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
|
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
|
||||||
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:debug -f deploy/Dockerfile_debug .
|
# docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:debug -f deploy/Dockerfile_debug .
|
||||||
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/warmer:latest -f deploy/Dockerfile_warmer .
|
# docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/warmer:latest -f deploy/Dockerfile_warmer .
|
||||||
|
|
||||||
.PHONY: push
|
.PHONY: push
|
||||||
push:
|
push:
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,13 @@ var (
|
||||||
force bool
|
force bool
|
||||||
logLevel string
|
logLevel string
|
||||||
logFormat string
|
logFormat string
|
||||||
|
logTimestamp bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", logging.DefaultLevel, "Log level (debug, info, warn, error, fatal, panic")
|
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", logging.DefaultLevel, "Log level (debug, info, warn, error, fatal, panic")
|
||||||
RootCmd.PersistentFlags().StringVar(&logFormat, "log-format", logging.FormatColor, "Log format (text, color, json)")
|
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")
|
RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container")
|
||||||
|
|
||||||
|
|
@ -62,7 +64,7 @@ var RootCmd = &cobra.Command{
|
||||||
if cmd.Use == "executor" {
|
if cmd.Use == "executor" {
|
||||||
resolveEnvironmentBuildArgs(opts.BuildArgs, os.Getenv)
|
resolveEnvironmentBuildArgs(opts.BuildArgs, os.Getenv)
|
||||||
|
|
||||||
if err := logging.Configure(logLevel, logFormat); err != nil {
|
if err := logging.Configure(logLevel, logFormat, logTimestamp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,13 @@ var (
|
||||||
opts = &config.WarmerOptions{}
|
opts = &config.WarmerOptions{}
|
||||||
logLevel string
|
logLevel string
|
||||||
logFormat string
|
logFormat string
|
||||||
|
logTimestamp bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", logging.DefaultLevel, "Log level (debug, info, warn, error, fatal, panic")
|
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", logging.DefaultLevel, "Log level (debug, info, warn, error, fatal, panic")
|
||||||
RootCmd.PersistentFlags().StringVar(&logFormat, "log-format", logging.FormatColor, "Log format (text, color, json)")
|
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()
|
addKanikoOptionsFlags()
|
||||||
addHiddenFlags()
|
addHiddenFlags()
|
||||||
|
|
@ -45,7 +47,7 @@ func init() {
|
||||||
var RootCmd = &cobra.Command{
|
var RootCmd = &cobra.Command{
|
||||||
Use: "cache warmer",
|
Use: "cache warmer",
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ import (
|
||||||
const (
|
const (
|
||||||
// Default log level
|
// Default log level
|
||||||
DefaultLevel = "info"
|
DefaultLevel = "info"
|
||||||
|
// Default timestamp in logs
|
||||||
|
DefaultLogTimestamp = false
|
||||||
|
|
||||||
// Text format
|
// Text format
|
||||||
FormatText = "text"
|
FormatText = "text"
|
||||||
|
|
@ -36,7 +38,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Configure sets the logrus logging level and formatter
|
// 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)
|
lvl, err := logrus.ParseLevel(level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "parsing log level")
|
return errors.Wrap(err, "parsing log level")
|
||||||
|
|
@ -48,10 +50,12 @@ func Configure(level, format string) error {
|
||||||
case FormatText:
|
case FormatText:
|
||||||
formatter = &logrus.TextFormatter{
|
formatter = &logrus.TextFormatter{
|
||||||
DisableColors: true,
|
DisableColors: true,
|
||||||
|
FullTimestamp: logTimestamp,
|
||||||
}
|
}
|
||||||
case FormatColor:
|
case FormatColor:
|
||||||
formatter = &logrus.TextFormatter{
|
formatter = &logrus.TextFormatter{
|
||||||
ForceColors: true,
|
ForceColors: true,
|
||||||
|
FullTimestamp: logTimestamp,
|
||||||
}
|
}
|
||||||
case FormatJSON:
|
case FormatJSON:
|
||||||
formatter = &logrus.JSONFormatter{}
|
formatter = &logrus.JSONFormatter{}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue