package log import ( "fmt" "os" "github.com/sirupsen/logrus" ) // list of common environment variables. var commonEnvs = []string{"APP_NAME", "APP_VERSION"} // AddCommonFieldsFromEnv will analyze "common" environment variable and will add those // as fields on a logrus.Entry. func AddCommonFieldsFromEnv(l *logrus.Entry) (*logrus.Entry, error) { if l == nil { return nil, fmt.Errorf("missing logrus entry") } for _, envKey := range commonEnvs { if v := os.Getenv(envKey); v != "" { l = logrus.WithField(envKey, v) } } return l, nil }