Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions GeneratedFirebaseAI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ let package = Package(
.product(name: "Logging", package: "swift-log"),
.product(name: "FirebaseCore", package: "firebase-ios-sdk"),
// TODO(daymxn): Before release, investigate releasing the Interop layers for AppCheck/Auth.
// Maybe with https://github.com/google/interop-ios-for-google-sdks
.product(name: "FirebaseAppCheck", package: "firebase-ios-sdk"),
.product(name: "FirebaseAuth", package: "firebase-ios-sdk")
.product(name: "FirebaseAuth", package: "firebase-ios-sdk"),
]
),
.testTarget(
name: "GeneratedFirebaseAITests",
dependencies: [
"GeneratedFirebaseAI",
.product(name: "TestServer", package: "TestServer")
.product(name: "TestServer", package: "test-server"),
],
path: "Tests",
exclude: [
"test-server.yml",
"Recordings"
"Recordings",
]
),
]
Expand Down
39 changes: 4 additions & 35 deletions GeneratedFirebaseAI/Sources/AILog.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Google LLC
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -13,10 +13,11 @@
// limitations under the License.

import Foundation
import Logging

#if os(Linux)
import FoundationNetworking
import FoundationNetworking
#endif
import Logging

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
enum AILog {
Expand Down Expand Up @@ -116,36 +117,4 @@ enum AILog {
static func additionalLoggingEnabled() -> Bool {
return ProcessInfo.processInfo.arguments.contains(enableArgumentKey)
}

/// Returns the unwrapped optional value if non-nil or returns the fallback value and logs.
///
/// This convenience method is intended for use in place of `optionalValue ?? fallbackValue` with
/// the addition of logging on use of the fallback value.
///
/// - Parameters:
/// - optionalValue: The value to unwrap.
/// - fallbackValue: The fallback (default) value to return when `optionalValue` is `nil`.
/// - level: The logging level to use for fallback messages; defaults to
/// `.default`.
/// - code: The message code to use for fallback messages; defaults to
/// `MessageCode.fallbackValueUsed`.
/// - caller: The name of the unwrapped value; defaults to the name of the computed property or
/// function name from which the unwrapping occurred.
static func safeUnwrap<T>(
_ optionalValue: T?,
fallback fallbackValue: T,
level: Logger.Level = .debug,
code: MessageCode = .fallbackValueUsed,
caller: String = #function
) -> T {
guard let unwrappedValue = optionalValue else {
AILog.log(
level: level, code: code,
"""
No value specified for '\(caller)' (\(T.self)); using fallback value '\(fallbackValue)'.
""")
return fallbackValue
}
return unwrappedValue
}
}
Loading
Loading