Skip to content

Commit

Permalink
Add example for CustomTagKey
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mizutani committed Nov 12, 2024
1 parent 968546f commit 4c1a36f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4c1a36f

Please sign in to comment.