MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / ToLogKey

Function ToLogKey

base/log_keys.go:198–228  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
198func 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
230func inverselogKeyNames(in [LogKeyCount]string) map[string]LogKey {
231 var out = make(map[string]LogKey, len(in))

Callers 4

toDbLogConfigMethod · 0.92
TestLogKeyNamesFunction · 0.85
BenchmarkToLogKeyFunction · 0.85
NewConsoleLoggerFunction · 0.85

Calls 3

convertSpecialLogKeyFunction · 0.85
WarnfCtxFunction · 0.85
EnableMethod · 0.80

Tested by 2

TestLogKeyNamesFunction · 0.68
BenchmarkToLogKeyFunction · 0.68