gocommon/log/utils.go
Matthieu 'JP' DERASSE d880059980
All checks were successful
continuous-integration/drone/push Build is passing
feat(middlewares): Continue adding std middlewares
2023-01-29 16:00:49 +00:00

28 lines
558 B
Go

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
}