New ๐ŸŒŠ wave for @helm

Commit 03c9fa04

03c9fa0407cfMerged

Svyatoslav Dumchenko <[email protected]> ยท 4 years ago ยท 1 file ยท ~1 modified

Description

Add flag to enable log timestamps

Details

Commit
03c9fa0407cf
Parent
5ad3107a5654

pkg/log/log.gomodifiedView file

@@ -15,10 +15,11 @@
1515
1616 // Settings stores configuration for logger.
1717 type Settings struct {
18- level string
19- format string
20- color bool
21- width int
18+ level string
19+ format string
20+ color bool
21+ timestamps bool
22+ width int
2223 }
2324
2425 // Flags returns CLI flags for logger settings.
@@ -52,6 +53,13 @@
5253 EnvVars: []string{"HELMWAVE_KUBEDOG_LOG_WIDTH"},
5354 Destination: &l.width,
5455 },
56+ &cli.BoolFlag{
57+ Name: "log-timestamps",
58+ Usage: "Add timestamps to log messages",
59+ Value: false,
60+ EnvVars: []string{"HELMWAVE_LOG_TIMESTAMPS"},
61+ Destination: &l.timestamps,
62+ },
5563 }
5664 }
5765
@@ -100,16 +108,23 @@
100108 })
101109 case "pad":
102110 log.SetFormatter(&log.TextFormatter{
103- PadLevelText: true,
104- ForceColors: l.color,
111+ PadLevelText: true,
112+ ForceColors: l.color,
113+ FullTimestamp: l.timestamps,
105114 })
106115 case "emoji":
107- log.SetFormatter(&formatter.Config{
116+ cfg := &formatter.Config{
108117 Color: l.color,
109- })
118+ }
119+ if l.timestamps {
120+ cfg.LogFormat = "[%time%] [%emoji% aka %lvl%]: %msg%"
121+ }
122+
123+ log.SetFormatter(cfg)
110124 case "text":
111125 log.SetFormatter(&log.TextFormatter{
112- ForceColors: l.color,
126+ ForceColors: l.color,
127+ FullTimestamp: l.timestamps,
113128 })
114129 }
115130 }