mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
49 lines
1001 B
Go
49 lines
1001 B
Go
package bbgo
|
|
|
|
import (
|
|
"os"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
|
)
|
|
|
|
func GetCurrentEnv() string {
|
|
env := os.Getenv("BBGO_ENV")
|
|
if env == "" {
|
|
env = "development"
|
|
}
|
|
|
|
return env
|
|
}
|
|
|
|
func NewLogFormatterWithEnv(env string) log.Formatter {
|
|
switch env {
|
|
case "production", "prod", "stag", "staging":
|
|
// always use json formatter for production and staging
|
|
return &log.JSONFormatter{}
|
|
}
|
|
|
|
return &prefixed.TextFormatter{}
|
|
}
|
|
|
|
type LogFormatterType string
|
|
|
|
const (
|
|
LogFormatterTypePrefixed LogFormatterType = "prefixed"
|
|
LogFormatterTypeText LogFormatterType = "text"
|
|
LogFormatterTypeJson LogFormatterType = "json"
|
|
)
|
|
|
|
func NewLogFormatter(logFormatter LogFormatterType) log.Formatter {
|
|
switch logFormatter {
|
|
case LogFormatterTypePrefixed:
|
|
return &prefixed.TextFormatter{}
|
|
case LogFormatterTypeText:
|
|
return &log.TextFormatter{}
|
|
case LogFormatterTypeJson:
|
|
return &log.JSONFormatter{}
|
|
}
|
|
|
|
return &prefixed.TextFormatter{}
|
|
}
|