|
8 | 8 | "fmt"
|
9 | 9 | "time"
|
10 | 10 |
|
| 11 | + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors" |
11 | 12 | "google.golang.org/grpc/codes"
|
12 | 13 | "google.golang.org/grpc/status"
|
13 | 14 | )
|
@@ -53,12 +54,12 @@ var (
|
53 | 54 | )
|
54 | 55 |
|
55 | 56 | type options struct {
|
56 |
| - levelFunc CodeToLevel |
57 |
| - loggableEvents []LoggableEvent |
58 |
| - codeFunc ErrorToCode |
59 |
| - durationFieldFunc DurationToFields |
60 |
| - timestampFormat string |
61 |
| - fieldsFromCtxFn fieldsFromCtxFn |
| 57 | + levelFunc CodeToLevel |
| 58 | + loggableEvents []LoggableEvent |
| 59 | + codeFunc ErrorToCode |
| 60 | + durationFieldFunc DurationToFields |
| 61 | + timestampFormat string |
| 62 | + fieldsFromCtxCallMetaFn fieldsFromCtxCallMetaFn |
62 | 63 | }
|
63 | 64 |
|
64 | 65 | type Option func(*options)
|
@@ -130,12 +131,24 @@ func DefaultClientCodeToLevel(code codes.Code) Level {
|
130 | 131 | }
|
131 | 132 | }
|
132 | 133 |
|
133 |
| -type fieldsFromCtxFn func(ctx context.Context) Fields |
| 134 | +type ( |
| 135 | + fieldsFromCtxFn func(ctx context.Context) Fields |
| 136 | + fieldsFromCtxCallMetaFn func(ctx context.Context, c interceptors.CallMeta) Fields |
| 137 | +) |
134 | 138 |
|
135 |
| -// WithFieldsFromContext allows overriding existing or adding extra fields to all log messages per given request. |
| 139 | +// WithFieldsFromContext allows overriding existing or adding extra fields to all log messages per given context |
136 | 140 | func WithFieldsFromContext(f fieldsFromCtxFn) Option {
|
137 | 141 | return func(o *options) {
|
138 |
| - o.fieldsFromCtxFn = f |
| 142 | + o.fieldsFromCtxCallMetaFn = func(ctx context.Context, _ interceptors.CallMeta) Fields { |
| 143 | + return f(ctx) |
| 144 | + } |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +// WithFieldsFromContextAndCallMeta allows overriding existing or adding extra fields to all log messages per given context and interceptor.CallMeta |
| 149 | +func WithFieldsFromContextAndCallMeta(f fieldsFromCtxCallMetaFn) Option { |
| 150 | + return func(o *options) { |
| 151 | + o.fieldsFromCtxCallMetaFn = f |
139 | 152 | }
|
140 | 153 | }
|
141 | 154 |
|
|
0 commit comments