From 988ee988bcdb2b07870f296f739bb3de8aad8b98 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Fri, 25 Sep 2020 09:40:25 +0100 Subject: [PATCH] Configure logging in the SpeechToText example 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 --- Examples/Google/SpeechToText/.gitignore | 4 ++++ Examples/Google/SpeechToText/Podfile | 2 +- Examples/Google/SpeechToText/Sources/SpeechService.swift | 8 +++++++- README.md | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 Examples/Google/SpeechToText/.gitignore diff --git a/Examples/Google/SpeechToText/.gitignore b/Examples/Google/SpeechToText/.gitignore new file mode 100644 index 000000000..c99bab229 --- /dev/null +++ b/Examples/Google/SpeechToText/.gitignore @@ -0,0 +1,4 @@ +Pods +Sources/Generated +google +googleapis diff --git a/Examples/Google/SpeechToText/Podfile b/Examples/Google/SpeechToText/Podfile index 5f833a448..e6d0d5c77 100644 --- a/Examples/Google/SpeechToText/Podfile +++ b/Examples/Google/SpeechToText/Podfile @@ -6,5 +6,5 @@ target 'SpeechToText-gRPC-iOS' do use_frameworks! pod 'SnapKit' - pod 'gRPC-Swift', '1.0.0-alpha.14' + pod 'gRPC-Swift', '1.0.0-alpha.19' end diff --git a/Examples/Google/SpeechToText/Sources/SpeechService.swift b/Examples/Google/SpeechToText/Sources/SpeechService.swift index fdea3ae14..cf50886d9 100644 --- a/Examples/Google/SpeechToText/Sources/SpeechService.swift +++ b/Examples/Google/SpeechToText/Sources/SpeechService.swift @@ -15,6 +15,7 @@ */ import GRPC +import Logging typealias Request = Google_Cloud_Speech_V1_StreamingRecognizeRequest 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 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` let channel = ClientConnection .secure(group: group) + .withBackgroundActivityLogger(logger) .connect(host: "speech.googleapis.com", port: 443) // Specify call options to be used for gRPC calls let callOptions = CallOptions(customMetadata: [ "x-goog-api-key": Constants.apiKey, - ]) + ], logger: logger) // Now we have a client! self.client = Google_Cloud_Speech_V1_SpeechClient( diff --git a/README.md b/README.md index 717f7ac4c..f991beab8 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ necessary targets: ```swift 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`: ```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