As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 99f2163b authored by Patrick Bajao's avatar Patrick Bajao
Browse files

Merge branch '140-standardize-logging-timestamp-format' into 'main'

Standardize logging timestamp format

Closes #140

See merge request gitlab-org/gitlab-shell!485
parents a9c25c17 7ae7047d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -10,9 +10,21 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
)
type UTCFormatter struct {
log.Formatter
}
func (u UTCFormatter) Format(e *log.Entry) ([]byte, error) {
e.Time = e.Time.UTC()
return u.Formatter.Format(e)
}
func configureLogFormat(cfg *config.Config) {
if cfg.LogFormat == "json" {
log.SetFormatter(&log.JSONFormatter{})
log.SetFormatter(UTCFormatter{&log.JSONFormatter{}})
} else {
log.SetFormatter(UTCFormatter{&log.TextFormatter{}})
}
}
Loading
Loading
Loading
Loading
@@ -3,6 +3,7 @@ package logger
import (
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
Loading
Loading
@@ -44,3 +45,27 @@ func TestConfigureWithPermissionError(t *testing.T) {
Configure(&config)
log.Info("this is a test")
}
func TestLogInUTC(t *testing.T) {
tmpFile, err := ioutil.TempFile(os.TempDir(), "logtest-")
require.NoError(t, err)
defer tmpFile.Close()
defer os.Remove(tmpFile.Name())
config := config.Config{
LogFile: tmpFile.Name(),
LogFormat: "json",
}
Configure(&config)
log.Info("this is a test")
data, err := ioutil.ReadFile(tmpFile.Name())
require.NoError(t, err)
utc := `[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z`
r, e := regexp.MatchString(utc, string(data))
require.NoError(t, e)
require.True(t, r)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment