Skip to content

Commit

Permalink
feat: Client Key in Resolve Debug logs (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria authored Nov 19, 2024
1 parent 558c811 commit 712ff6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ extension Confidence {
public func build() -> Confidence {
if debugLogger == nil {
if loggerLevel != LoggerLevel.NONE {
debugLogger = DebugLoggerImpl(loggerLevel: loggerLevel)
debugLogger = DebugLoggerImpl(loggerLevel: loggerLevel, clientKey: clientSecret)
debugLogger?.logContext(action: "InitialContext", context: initialContext)
}
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/Confidence/DebugLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ private extension Logger {

internal class DebugLoggerImpl: DebugLogger {
private let encoder = JSONEncoder()
private let clientKey: String

func logResolveDebugURL(flagName: String, context: ConfidenceStruct) {
let ctxNetworkValue = TypeMapper.convert(structure: context)
if let ctxNetworkData = try? encoder.encode(ctxNetworkValue),
let ctxNetworkString = String(data: ctxNetworkData, encoding: .utf8) {
log(messageLevel: .DEBUG, message: "[Resolve Debug] https://app.confidence.spotify.com/flags/resolver-test?flag=flags/\(flagName)&context=\(ctxNetworkString)")
log(messageLevel: .DEBUG, message: "[Resolve Debug] https://app.confidence.spotify.com/flags/resolver-test?client-key=\(clientKey)&flag=flags/\(flagName)&context=\(ctxNetworkString)")
}
}

private let loggerLevel: LoggerLevel

init(loggerLevel: LoggerLevel) {
init(loggerLevel: LoggerLevel, clientKey: String) {
self.loggerLevel = loggerLevel
self.clientKey = clientKey
}

func logMessage(message: String, isWarning: Bool = false) {
Expand Down

0 comments on commit 712ff6e

Please sign in to comment.