Skip to content

Commit a3fd2ea

Browse files
Make Util.log autoclosure-based and add setUp lifecycle logs
Util.log: - Switch the message parameter to @autoclosure so the interpolated string is only built when DEBUG is set. Eliminates allocation/format cost in release builds where the print() is compiled out. - Bracket the prefix as "[UnityAdapter] ..." for consistency with other third-party adapter logs (AppLovin, AdMob, etc.). UnityAdapter.setUp: - Log when initialization starts (gameId, testMode), when it succeeds, when the SDK reports a failure, and when setUp aborts before reaching the SDK (e.g. missing gameId in server config). Gives integrators enough breadcrumbs from the adapter alone to diagnose init issues without having to attach to the SDK's internal logger. Note: For the logs to surface in pod consumers, the host app's Podfile must propagate SWIFT_ACTIVE_COMPILATION_CONDITIONS=DEBUG into pod targets — CocoaPods does not do this by default. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 159886c commit a3fd2ea

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

adapters/Unity/UnityAdapter/UnityAdapter.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ final class UnityAdapter: NSObject, RTBAdapter {
4545
.with(logLevel: isTestMode ? .debug : .info)
4646
.build()
4747

48+
Util.log("setUp: initializing UnityAds (gameId=\(gameId), testMode=\(isTestMode))")
4849
client.initialize(configuration: initConfig) { error in
49-
completionHandler(error)
50+
if let error {
51+
Util.log("setUp: UnityAds init failed — \(error.localizedDescription)")
52+
} else {
53+
Util.log("setUp: UnityAds init succeeded")
54+
}
55+
completionHandler(error)
5056
}
5157
} catch {
58+
Util.log("setUp: aborted before SDK init — \(error.localizedDescription)")
5259
completionHandler(error)
5360
}
5461
}

adapters/Unity/UnityAdapter/Util.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ final class Util {
2222
case placementId = "zoneId"
2323
}
2424

25-
static func log(_ message: String) {
25+
static func log(_ message: @autoclosure () -> String) {
2626
#if DEBUG
27-
print("UnityAdapter: \(message)")
27+
print("[UnityAdapter] \(message())")
2828
#endif
2929
}
3030

0 commit comments

Comments
 (0)