Skip to content

Commit 36dde9e

Browse files
committed
fix(Logger): Added jwt_field option
1 parent 853cc00 commit 36dde9e

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ logs:
4848
#jwt_user:
4949
# enabled: true
5050
# header: "Test"
51+
# JWT field which you want to log
52+
# jwt_field: "email"
5153
access_logs_fields:
5254
- REQUEST:method
5355
- REQUEST:host

api/v1alpha1/config_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ type ConfigSpec struct {
1717
Logs struct {
1818
ShowAccessLogs bool `yaml:"show_access_logs"`
1919
JwtUser struct {
20-
Enabled bool `yaml:"enabled"`
21-
Header string `yaml:"header"`
20+
Enabled bool `yaml:"enabled"`
21+
Header string `yaml:"header"`
22+
JwtField string `yaml:"jwt_field"`
2223
} `yaml:"jwt_user"`
2324
AccessLogsFields []string `yaml:"access_logs_fields"`
2425
} `yaml:"logs"`

config/samples/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ logs:
1313
jwt_user:
1414
enabled: true
1515
header: "Cookie"
16+
jwt_field: "email"
1617
access_logs_fields:
1718
- REQUEST:method
1819
- REQUEST:host

internal/commons/commons.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ func addJwtUser(ctx v1alpha1.Context, logFields []interface{}, req *fasthttp.Req
199199
return logFields
200200
}
201201

202-
email, ok := payload["email"].(string)
202+
user, ok := payload[ctx.Config.Logs.JwtUser.JwtField].(string)
203203
if ok {
204-
logFields = append(logFields, "jwt_user", email)
204+
logFields = append(logFields, "jwt_user", user)
205205
return logFields
206206
}
207207
}

0 commit comments

Comments
 (0)