Skip to content

Commit 5659604

Browse files
authored
Renames for console logging (#14776)
1 parent 15e6b03 commit 5659604

12 files changed

+45
-45
lines changed

FirebaseAI/Sources/VertexLog.swift renamed to FirebaseAI/Sources/AILog.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import os.log
1717

1818
internal import FirebaseCoreExtension
1919

20-
enum VertexLog {
21-
/// Log message codes for the Vertex AI SDK
20+
enum AILog {
21+
/// Log message codes for the Firebase AI SDK
2222
///
2323
/// These codes should ideally not be re-used in order to facilitate matching error codes in
2424
/// support requests to lines in the SDK. These codes should range between 0 and 999999 to avoid
@@ -75,10 +75,10 @@ enum VertexLog {
7575
/// Subsystem that should be used for all Loggers.
7676
static let subsystem = "com.google.firebase"
7777

78-
/// Log identifier for the Vertex AI SDK.
78+
/// Log identifier for the AI SDK.
7979
///
8080
/// > Note: This corresponds to the `category` in `OSLog`.
81-
static let service = "[FirebaseVertexAI]"
81+
static let service = "[FirebaseAI]"
8282

8383
/// The raw `OSLog` log object.
8484
///
@@ -92,7 +92,7 @@ enum VertexLog {
9292
let messageCode = String(format: "I-VTX%06d", code.rawValue)
9393
FirebaseLogger.log(
9494
level: level,
95-
service: VertexLog.service,
95+
service: AILog.service,
9696
code: messageCode,
9797
message: message
9898
)

FirebaseAI/Sources/FirebaseAI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public final class FirebaseAI: Sendable {
7373
requestOptions: RequestOptions = RequestOptions())
7474
-> GenerativeModel {
7575
if !modelName.starts(with: GenerativeModel.geminiModelNamePrefix) {
76-
VertexLog.warning(code: .unsupportedGeminiModel, """
76+
AILog.warning(code: .unsupportedGeminiModel, """
7777
Unsupported Gemini model "\(modelName)"; see \
7878
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
7979
""")
@@ -113,7 +113,7 @@ public final class FirebaseAI: Sendable {
113113
safetySettings: ImagenSafetySettings? = nil,
114114
requestOptions: RequestOptions = RequestOptions()) -> ImagenModel {
115115
if !modelName.starts(with: ImagenModel.imagenModelNamePrefix) {
116-
VertexLog.warning(code: .unsupportedImagenModel, """
116+
AILog.warning(code: .unsupportedImagenModel, """
117117
Unsupported Imagen model "\(modelName)"; see \
118118
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
119119
""")

FirebaseAI/Sources/GenerateContentResponse.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public struct GenerateContentResponse: Sendable {
4949
/// The response's content as text, if it exists.
5050
public var text: String? {
5151
guard let candidate = candidates.first else {
52-
VertexLog.error(
52+
AILog.error(
5353
code: .generateContentResponseNoCandidates,
5454
"Could not get text from a response that had no candidates."
5555
)
@@ -64,7 +64,7 @@ public struct GenerateContentResponse: Sendable {
6464
}
6565
}
6666
guard textValues.count > 0 else {
67-
VertexLog.error(
67+
AILog.error(
6868
code: .generateContentResponseNoText,
6969
"Could not get a text part from the first candidate."
7070
)
@@ -91,7 +91,7 @@ public struct GenerateContentResponse: Sendable {
9191
/// Returns inline data parts found in any `Part`s of the first candidate of the response, if any.
9292
public var inlineDataParts: [InlineDataPart] {
9393
guard let candidate = candidates.first else {
94-
VertexLog.error(code: .generateContentResponseNoCandidates, """
94+
AILog.error(code: .generateContentResponseNoCandidates, """
9595
Could not get inline data parts because the response has no candidates. The accessor only \
9696
checks the first candidate.
9797
""")
@@ -219,7 +219,7 @@ public struct FinishReason: DecodableProtoEnum, Hashable, Sendable {
219219
public let rawValue: String
220220

221221
static let unrecognizedValueMessageCode =
222-
VertexLog.MessageCode.generateContentResponseUnrecognizedFinishReason
222+
AILog.MessageCode.generateContentResponseUnrecognizedFinishReason
223223
}
224224

225225
/// A metadata struct containing any feedback the model had on the prompt it was provided.
@@ -254,7 +254,7 @@ public struct PromptFeedback: Sendable {
254254
public let rawValue: String
255255

256256
static let unrecognizedValueMessageCode =
257-
VertexLog.MessageCode.generateContentResponseUnrecognizedBlockReason
257+
AILog.MessageCode.generateContentResponseUnrecognizedBlockReason
258258
}
259259

260260
/// The reason a prompt was blocked, if it was blocked.
@@ -428,7 +428,7 @@ extension Citation: Decodable {
428428
) {
429429
publicationDate = publicationProtoDate.dateComponents
430430
if let publicationDate, !publicationDate.isValidDate {
431-
VertexLog.warning(
431+
AILog.warning(
432432
code: .decodedInvalidCitationPublicationDate,
433433
"Decoded an invalid citation publication date: \(publicationDate)"
434434
)

FirebaseAI/Sources/GenerativeAIService.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ struct GenerativeAIService {
5050

5151
// Verify the status code is 200
5252
guard response.statusCode == 200 else {
53-
VertexLog.error(
53+
AILog.error(
5454
code: .loadRequestResponseError,
5555
"The server responded with an error: \(response)"
5656
)
5757
if let responseString = String(data: data, encoding: .utf8) {
58-
VertexLog.error(
58+
AILog.error(
5959
code: .loadRequestResponseErrorPayload,
6060
"Response payload: \(responseString)"
6161
)
@@ -104,7 +104,7 @@ struct GenerativeAIService {
104104

105105
// Verify the status code is 200
106106
guard response.statusCode == 200 else {
107-
VertexLog.error(
107+
AILog.error(
108108
code: .loadRequestStreamResponseError,
109109
"The server responded with an error: \(response)"
110110
)
@@ -113,7 +113,7 @@ struct GenerativeAIService {
113113
responseBody += line + "\n"
114114
}
115115

116-
VertexLog.error(
116+
AILog.error(
117117
code: .loadRequestStreamResponseErrorPayload,
118118
"Response payload: \(responseBody)"
119119
)
@@ -128,7 +128,7 @@ struct GenerativeAIService {
128128
let decoder = JSONDecoder()
129129
decoder.keyDecodingStrategy = .convertFromSnakeCase
130130
for try await line in stream.lines {
131-
VertexLog.debug(code: .loadRequestStreamResponseLine, "Stream response: \(line)")
131+
AILog.debug(code: .loadRequestStreamResponseLine, "Stream response: \(line)")
132132

133133
if line.hasPrefix("data:") {
134134
// We can assume 5 characters since it's utf-8 encoded, removing `data:`.
@@ -180,7 +180,7 @@ struct GenerativeAIService {
180180
let tokenResult = await appCheck.getToken(forcingRefresh: false)
181181
urlRequest.setValue(tokenResult.token, forHTTPHeaderField: "X-Firebase-AppCheck")
182182
if let error = tokenResult.error {
183-
VertexLog.error(
183+
AILog.error(
184184
code: .appCheckTokenFetchFailed,
185185
"Failed to fetch AppCheck token. Error: \(error)"
186186
)
@@ -212,7 +212,7 @@ struct GenerativeAIService {
212212
// response objects you get back from the URLSession, NSURLConnection, or NSURLDownload class
213213
// are instances of the HTTPURLResponse class."
214214
guard let response = urlResponse as? HTTPURLResponse else {
215-
VertexLog.error(
215+
AILog.error(
216216
code: .generativeAIServiceNonHTTPResponse,
217217
"Response wasn't an HTTP response, internal error \(urlResponse)"
218218
)
@@ -260,8 +260,8 @@ struct GenerativeAIService {
260260
private func logRPCError(_ error: BackendError) {
261261
let projectID = firebaseInfo.projectID
262262
if error.isVertexAIInFirebaseServiceDisabledError() {
263-
VertexLog.error(code: .vertexAIInFirebaseAPIDisabled, """
264-
The Vertex AI in Firebase SDK requires the Vertex AI in Firebase API \
263+
AILog.error(code: .vertexAIInFirebaseAPIDisabled, """
264+
The Firebase AI SDK requires the Firebase AI API \
265265
(`firebasevertexai.googleapis.com`) to be enabled in your Firebase project. Enable this API \
266266
by visiting the Firebase Console at
267267
https://console.firebase.google.com/project/\(projectID)/genai/ and clicking "Get started". \
@@ -276,9 +276,9 @@ struct GenerativeAIService {
276276
return try JSONDecoder().decode(type, from: data)
277277
} catch {
278278
if let json = String(data: data, encoding: .utf8) {
279-
VertexLog.error(code: .loadRequestParseResponseFailedJSON, "JSON response: \(json)")
279+
AILog.error(code: .loadRequestParseResponseFailedJSON, "JSON response: \(json)")
280280
}
281-
VertexLog.error(
281+
AILog.error(
282282
code: .loadRequestParseResponseFailedJSONError,
283283
"Error decoding server JSON: \(error)"
284284
)
@@ -307,12 +307,12 @@ struct GenerativeAIService {
307307
}
308308

309309
private func printCURLCommand(from request: URLRequest) {
310-
guard VertexLog.additionalLoggingEnabled() else {
310+
guard AILog.additionalLoggingEnabled() else {
311311
return
312312
}
313313
let command = cURLCommand(from: request)
314-
os_log(.debug, log: VertexLog.logObject, """
315-
\(VertexLog.service) Creating request with the equivalent cURL command:
314+
os_log(.debug, log: AILog.logObject, """
315+
\(AILog.service) Creating request with the equivalent cURL command:
316316
----- cURL command -----
317317
\(command, privacy: .private)
318318
------------------------

FirebaseAI/Sources/GenerativeModel.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ public final class GenerativeModel: Sendable {
104104
}
105105
self.requestOptions = requestOptions
106106

107-
if VertexLog.additionalLoggingEnabled() {
108-
VertexLog.debug(code: .verboseLoggingEnabled, "Verbose logging enabled.")
107+
if AILog.additionalLoggingEnabled() {
108+
AILog.debug(code: .verboseLoggingEnabled, "Verbose logging enabled.")
109109
} else {
110-
VertexLog.info(code: .verboseLoggingDisabled, """
110+
AILog.info(code: .verboseLoggingDisabled, """
111111
[FirebaseVertexAI] To enable additional logging, add \
112-
`\(VertexLog.enableArgumentKey)` as a launch argument in Xcode.
112+
`\(AILog.enableArgumentKey)` as a launch argument in Xcode.
113113
""")
114114
}
115-
VertexLog.debug(code: .generativeModelInitialized, "Model \(modelResourceName) initialized.")
115+
AILog.debug(code: .generativeModelInitialized, "Model \(modelResourceName) initialized.")
116116
}
117117

118118
/// Generates content from String and/or image inputs, given to the model as a prompt, that are

FirebaseAI/Sources/ModalityTokenCount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public struct ContentModality: DecodableProtoEnum, Hashable, Sendable {
5454
public let rawValue: String
5555

5656
static let unrecognizedValueMessageCode =
57-
VertexLog.MessageCode.generateContentResponseUnrecognizedContentModality
57+
AILog.MessageCode.generateContentResponseUnrecognizedContentModality
5858
}
5959

6060
// MARK: Codable Conformances

FirebaseAI/Sources/Protocols/Internal/CodableProtoEnum.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ protocol ProtoEnum: Sendable {
4646
/// Protobuf enums are represented as strings in JSON. A default `Decodable` implementation is
4747
/// provided when conforming to this type.
4848
protocol DecodableProtoEnum: ProtoEnum, Decodable {
49-
/// Returns the ``VertexLog/MessageCode`` associated with unrecognized (unknown) enum values.
50-
static var unrecognizedValueMessageCode: VertexLog.MessageCode { get }
49+
/// Returns the ``AILog/MessageCode`` associated with unrecognized (unknown) enum values.
50+
static var unrecognizedValueMessageCode: AILog.MessageCode { get }
5151

5252
/// Creates a new instance by decoding from the given decoder.
5353
///
@@ -90,7 +90,7 @@ extension DecodableProtoEnum {
9090
self = Self(rawValue: rawValue)
9191

9292
if Kind(rawValue: rawValue) == nil {
93-
VertexLog.error(
93+
AILog.error(
9494
code: Self.unrecognizedValueMessageCode,
9595
"""
9696
Unrecognized \(Self.self) with value "\(rawValue)":

FirebaseAI/Sources/Safety.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public struct SafetyRating: Equatable, Hashable, Sendable {
107107
public let rawValue: String
108108

109109
static let unrecognizedValueMessageCode =
110-
VertexLog.MessageCode.generateContentResponseUnrecognizedHarmProbability
110+
AILog.MessageCode.generateContentResponseUnrecognizedHarmProbability
111111
}
112112

113113
/// The magnitude of how harmful a model response might be for the respective ``HarmCategory``.
@@ -139,7 +139,7 @@ public struct SafetyRating: Equatable, Hashable, Sendable {
139139
public let rawValue: String
140140

141141
static let unrecognizedValueMessageCode =
142-
VertexLog.MessageCode.generateContentResponseUnrecognizedHarmSeverity
142+
AILog.MessageCode.generateContentResponseUnrecognizedHarmSeverity
143143
}
144144
}
145145

@@ -263,7 +263,7 @@ public struct HarmCategory: CodableProtoEnum, Hashable, Sendable {
263263
public let rawValue: String
264264

265265
static let unrecognizedValueMessageCode =
266-
VertexLog.MessageCode.generateContentResponseUnrecognizedHarmCategory
266+
AILog.MessageCode.generateContentResponseUnrecognizedHarmCategory
267267
}
268268

269269
// MARK: - Codable Conformances

FirebaseAI/Sources/Types/Internal/ProtoDate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension ProtoDate: Decodable {
6868
let container = try decoder.container(keyedBy: CodingKeys.self)
6969
if let year = try container.decodeIfPresent(Int.self, forKey: .year), year != 0 {
7070
if year < 0 || year > 9999 {
71-
VertexLog.warning(
71+
AILog.warning(
7272
code: .decodedInvalidProtoDateYear,
7373
"""
7474
Invalid year: \(year); must be from 1 to 9999, or 0 for a date without a specified year.
@@ -82,7 +82,7 @@ extension ProtoDate: Decodable {
8282

8383
if let month = try container.decodeIfPresent(Int.self, forKey: .month), month != 0 {
8484
if month < 0 || month > 12 {
85-
VertexLog.warning(
85+
AILog.warning(
8686
code: .decodedInvalidProtoDateMonth,
8787
"""
8888
Invalid month: \(month); must be from 1 to 12, or 0 for a year date without a specified \
@@ -97,7 +97,7 @@ extension ProtoDate: Decodable {
9797

9898
if let day = try container.decodeIfPresent(Int.self, forKey: .day), day != 0 {
9999
if day < 0 || day > 31 {
100-
VertexLog.warning(
100+
AILog.warning(
101101
code: .decodedInvalidProtoDateDay,
102102
"Invalid day: \(day); must be from 1 to 31, or 0 for a date without a specified day."
103103
)

FirebaseAI/Sources/Types/Public/Imagen/ImagenGenerationResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension ImagenGenerationResponse: Decodable where T: Decodable {
6161
} else if let filteredReason = try? predictionsContainer.decode(RAIFilteredReason.self) {
6262
filteredReasons.append(filteredReason.raiFilteredReason)
6363
} else if let unsupportedPrediction = try? predictionsContainer.decode(JSONObject.self) {
64-
VertexLog.warning(
64+
AILog.warning(
6565
code: .decodedUnsupportedImagenPredictionType,
6666
"Ignoring unsupported Imagen prediction: \(unsupportedPrediction)"
6767
)

0 commit comments

Comments
 (0)