ToLogKey takes a slice of case-sensitive log key names and will return a LogKeyMask bitfield and a slice of deferred log functions for any warnings that may occur.
(ctx context.Context, keysStr []string)
| 196 | // ToLogKey takes a slice of case-sensitive log key names and will return a LogKeyMask bitfield |
| 197 | // and a slice of deferred log functions for any warnings that may occur. |
| 198 | func ToLogKey(ctx context.Context, keysStr []string) (logKeys LogKeyMask) { |
| 199 | |
| 200 | for _, key := range keysStr { |
| 201 | // Take a copy of key, so we can use it in a closure outside the scope |
| 202 | // of this loop (the warnings returned are logged asyncronously) |
| 203 | originalKey := key |
| 204 | |
| 205 | // Some old log keys (like HTTP+), we want to handle slightly (map to a different key) |
| 206 | if newLogKeys, ok := convertSpecialLogKey(key); ok { |
| 207 | for _, newLogKey := range newLogKeys { |
| 208 | logKeys.Enable(newLogKey) |
| 209 | } |
| 210 | continue |
| 211 | } |
| 212 | |
| 213 | // Strip a single "+" suffix in log keys and warn (for backwards compatibility) |
| 214 | if strings.HasSuffix(key, "+") { |
| 215 | newLogKey := strings.TrimSuffix(key, "+") |
| 216 | WarnfCtx(ctx, "Deprecated log key: %q found. Changing to: %q.", originalKey, newLogKey) |
| 217 | key = newLogKey |
| 218 | } |
| 219 | |
| 220 | if logKey, ok := logKeyNamesInverse[key]; ok { |
| 221 | logKeys.Enable(logKey) |
| 222 | } else { |
| 223 | WarnfCtx(ctx, "Invalid log key: %v", originalKey) |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return logKeys |
| 228 | } |
| 229 | |
| 230 | func inverselogKeyNames(in [LogKeyCount]string) map[string]LogKey { |
| 231 | var out = make(map[string]LogKey, len(in)) |