Fix configurable logging type fields
@@ -4,16 +4,34 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/sirupsen/logrus"
+ "github.com/avenga/couper/config/env"
"github.com/avenga/couper/config/request"
"github.com/avenga/couper/eval"
+ "github.com/avenga/couper/logging"
)
-var _ logrus.Hook = &CustomLogs{}
+var (
+ _ logrus.Hook = &CustomLogs{}
+ acTypeField string
+ beTypeField string
+)
const customLogField = "custom"
type CustomLogs struct{}
+func init() {
+ logConf := *logging.DefaultConfig
+ logConf.TypeFieldKey = "couper_access"
+ env.DecodeWithPrefix(&logConf, "ACCESS_")
+ acTypeField = logConf.TypeFieldKey
+
+ logConf = *logging.DefaultConfig
+ logConf.TypeFieldKey = "couper_backend"
+ env.DecodeWithPrefix(&logConf, "BACKEND_")
+ beTypeField = logConf.TypeFieldKey
+}
+
func (c *CustomLogs) Levels() []logrus.Level {
return logrus.AllLevels
}
@@ -22,9 +40,9 @@ func (c *CustomLogs) Fire(entry *logrus.Entry) error {
if entry.Context != nil {
if t, exists := entry.Data["type"]; exists {
switch t {
- case "couper_access":
+ case acTypeField:
fire(entry, request.LogCustomAccess)
- case "couper_backend":
+ case beTypeField:
fire(entry, request.LogCustomUpstream)
}
}
