Browse Source

Configure logging in the SpeechToText example (#973)

Motivation:

It's easier to provide to people when we have logs.

Modifications:

- Add debug stdout logging to SpeechToText
- Bump the pod version
- Add an ignore file for SpeechToText

Result:

Logs in the SpeechToText example
George Barnett 5 years ago
parent
commit
312dde0647

+ 4 - 0
Examples/Google/SpeechToText/.gitignore

@@ -0,0 +1,4 @@
+Pods
+Sources/Generated
+google
+googleapis

+ 1 - 1
Examples/Google/SpeechToText/Podfile

@@ -6,5 +6,5 @@ target 'SpeechToText-gRPC-iOS' do
   use_frameworks!
   use_frameworks!
 
 
   pod 'SnapKit'
   pod 'SnapKit'
-  pod 'gRPC-Swift', '1.0.0-alpha.14'
+  pod 'gRPC-Swift', '1.0.0-alpha.19'
 end
 end

+ 7 - 1
Examples/Google/SpeechToText/Sources/SpeechService.swift

@@ -15,6 +15,7 @@
  */
  */
 
 
 import GRPC
 import GRPC
+import Logging
 
 
 typealias Request = Google_Cloud_Speech_V1_StreamingRecognizeRequest
 typealias Request = Google_Cloud_Speech_V1_StreamingRecognizeRequest
 typealias Response = Google_Cloud_Speech_V1_StreamingRecognizeResponse
 typealias Response = Google_Cloud_Speech_V1_StreamingRecognizeResponse
@@ -43,15 +44,20 @@ final class SpeechService {
     // see https://github.com/grpc/grpc-swift/blob/main/docs/apple-platforms.md for more details
     // see https://github.com/grpc/grpc-swift/blob/main/docs/apple-platforms.md for more details
     let group = PlatformSupport.makeEventLoopGroup(loopCount: 1)
     let group = PlatformSupport.makeEventLoopGroup(loopCount: 1)
 
 
+    // Setup a logger for debugging.
+    var logger = Logger(label: "gRPC", factory: StreamLogHandler.standardOutput(label:))
+    logger.logLevel = .debug
+
     // Create a connection secured with TLS to Google's speech service running on our `EventLoopGroup`
     // Create a connection secured with TLS to Google's speech service running on our `EventLoopGroup`
     let channel = ClientConnection
     let channel = ClientConnection
       .secure(group: group)
       .secure(group: group)
+      .withBackgroundActivityLogger(logger)
       .connect(host: "speech.googleapis.com", port: 443)
       .connect(host: "speech.googleapis.com", port: 443)
 
 
     // Specify call options to be used for gRPC calls
     // Specify call options to be used for gRPC calls
     let callOptions = CallOptions(customMetadata: [
     let callOptions = CallOptions(customMetadata: [
       "x-goog-api-key": Constants.apiKey,
       "x-goog-api-key": Constants.apiKey,
-    ])
+    ], logger: logger)
 
 
     // Now we have a client!
     // Now we have a client!
     self.client = Google_Cloud_Speech_V1_SpeechClient(
     self.client = Google_Cloud_Speech_V1_SpeechClient(

+ 2 - 2
README.md

@@ -51,7 +51,7 @@ necessary targets:
 
 
 ```swift
 ```swift
 dependencies: [
 dependencies: [
-  .package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0-alpha.12")
+  .package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0-alpha.19")
 ]
 ]
 ```
 ```
 
 
@@ -96,7 +96,7 @@ gRPC Swift is currently available [from CocoaPods][pod-new]. To integrate, add
 the following line to your `Podfile`:
 the following line to your `Podfile`:
 
 
 ```ruby
 ```ruby
-    pod 'gRPC-Swift', '~> 1.0.0-alpha.18'
+    pod 'gRPC-Swift', '~> 1.0.0-alpha.19'
 ```
 ```
 
 
 Then, run `pod install` from command line and use your project's generated
 Then, run `pod install` from command line and use your project's generated