summaryrefslogtreecommitdiff
path: root/internal/logger/logger.go
diff options
context:
space:
mode:
authorAakriti Gupta <agupta@gitlab.com>2020-02-05 15:43:57 +0100
committerAsh McKenzie <amckenzie@gitlab.com>2020-02-11 19:31:17 +1100
commit354ae8d88d7ef447baf3d4fd6f5cba211df7efd1 (patch)
tree29dcd0065a41edfeea5c668d8bbdee39a74aa79e /internal/logger/logger.go
parenta7b6307397c0bf5414a102052042d405c3b40162 (diff)
downloadgitlab-shell-ag-update-timestamps.tar.gz
Format timestamp in UTC with a precision of a milisecondag-update-timestamps
Diffstat (limited to 'internal/logger/logger.go')
-rw-r--r--internal/logger/logger.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/internal/logger/logger.go b/internal/logger/logger.go
index f1db4b0..4115641 100644
--- a/internal/logger/logger.go
+++ b/internal/logger/logger.go
@@ -21,6 +21,15 @@ var (
ProgName string
)
+type UTCFormatter struct {
+ defaultFormatter log.Formatter
+}
+
+func (f *UTCFormatter) Format(entry *log.Entry) ([]byte, error) {
+ entry.Time = entry.Time.UTC()
+ return f.defaultFormatter.Format(entry)
+}
+
func Configure(cfg *config.Config) error {
mutex.Lock()
defer mutex.Unlock()
@@ -34,8 +43,20 @@ func Configure(cfg *config.Config) error {
}
log.SetOutput(logWriter)
+
if cfg.LogFormat == "json" {
- log.SetFormatter(&log.JSONFormatter{})
+ log.SetFormatter(&UTCFormatter{
+ defaultFormatter: &log.JSONFormatter{
+ TimestampFormat: "2020-02-05 15:04:05.999Z",
+ },
+ })
+ } else {
+ log.SetFormatter(&UTCFormatter{
+ defaultFormatter: &log.TextFormatter{
+ TimestampFormat: "2020-02-05 15:04:05.999Z",
+ FullTimestamp: true,
+ },
+ })
}
return nil