mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-09 05:59:54 +00:00
Merge pull request #23 from mritd/feat/add-log-timestamp-format
feat(log): add log timestamp format
This commit is contained in:
commit
1301039807
17
cmd/main.go
17
cmd/main.go
@ -2,9 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Injected when compiling
|
// Injected when compiling
|
||||||
@ -31,12 +32,22 @@ func init() {
|
|||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tsFormat is used to format the log timestamp, by default(empty)
|
||||||
|
// the RFC3339("2006-01-02T15:04:05Z07:00") format is used.
|
||||||
|
// The user can use environment variable to override the default
|
||||||
|
// timestamp format(e.g. "2006-01-02 15:04:05").
|
||||||
|
tsFormat := os.Getenv("LOGGING_TIMESTAMP_FORMAT")
|
||||||
|
|
||||||
fmtter := os.Getenv("LOGGING_FORMATTER")
|
fmtter := os.Getenv("LOGGING_FORMATTER")
|
||||||
if strings.ToLower(fmtter) == "json" {
|
if strings.ToLower(fmtter) == "json" {
|
||||||
logrus.SetFormatter(&logrus.JSONFormatter{})
|
logrus.SetFormatter(&logrus.JSONFormatter{
|
||||||
|
TimestampFormat: tsFormat,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
logrus.SetFormatter(&logrus.TextFormatter{
|
logrus.SetFormatter(&logrus.TextFormatter{
|
||||||
ForceColors: true,
|
ForceColors: true,
|
||||||
|
FullTimestamp: true,
|
||||||
|
TimestampFormat: tsFormat,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user