-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
968546f
commit 4c1a36f
Showing
1 changed file
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,13 +50,13 @@ logger := slog.New( | |
ReplaceAttr: masq.New( | ||
// By user defined custom type | ||
masq.WithType[AccessToken](), | ||
|
||
// By regex of phone number as e164 format | ||
masq.WithRegex(regexp.MustCompile(`^\+[1-9]\d{1,14}$`)), | ||
|
||
// By field tag such as masq:"secret" | ||
masq.WithTag("secret"), | ||
|
||
// By by field name prefix. Concealing SecureXxx field | ||
masq.WithFieldPrefix("Secure"), | ||
), | ||
|
@@ -168,6 +168,30 @@ out.Flush() | |
// {"level":"INFO","msg":"Got record","record":{"EMail":"[FILTERED]","ID":"m-mizutani"},"time":"2022-12-25T09:00:00.123456789"} | ||
``` | ||
|
||
You can change the tag key by `masq.WithCustomTagKey` option. | ||
|
||
```go | ||
type myRecord struct { | ||
ID string | ||
EMail string `custom:"secret"` | ||
} | ||
|
||
record := myRecord{ | ||
ID: "m-mizutani", | ||
EMail: "[email protected]", | ||
} | ||
|
||
logger := newLogger(out, masq.New( | ||
masq.WithCustomTagKey("custom"), | ||
masq.WithTag("secret"), | ||
)) | ||
|
||
logger.With("record", record).Info("Got record") | ||
out.Flush() | ||
// Output: | ||
// {"level":"INFO","msg":"Got record","record":{"EMail":"[REDACTED]","ID":"m-mizutani"},"time":"2022-12-25T09:00:00.123456789"} | ||
``` | ||
|
||
### With struct field name | ||
|
||
```go | ||
|