Skip to content

Commit

Permalink
Set subscription log level
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed Feb 16, 2022
1 parent f36f961 commit 798ba34
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions AWSAppSyncClient/AWSAppSyncClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import Foundation
import AWSCore
import AppSyncRealTimeClient

public typealias SubscriptionResultHandler<Operation: GraphQLSubscription> = (_ result: GraphQLResult<Operation.Data>?, _ transaction: ApolloStore.ReadWriteTransaction?, _ error: Error?) -> Void

Expand Down Expand Up @@ -119,6 +120,8 @@ public class AWSAppSyncClient {
name: .appSyncReachabilityChanged,
object: nil)

AppSyncRealTimeClient.logLevel = AppSyncLogHelper.subscriptionLogLevel

try AWSAppSyncClient.prefixTrackerQueue.sync {
if appSyncConfig.cacheConfiguration?.usePrefix ?? false {
let prefixTrackerKey = appSyncConfig.cacheConfiguration?.prefix ?? ""
Expand Down
19 changes: 18 additions & 1 deletion AWSAppSyncClient/Internal/AppSyncLogHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import Foundation
import AWSCore
import AppSyncRealTimeClient

struct AppSyncLogHelper {

Expand All @@ -19,7 +20,6 @@ struct AppSyncLogHelper {
file: String,
function: String,
line: UInt) {

AWSDDLog.log(asynchronous: true,
level: AWSDDLog.sharedInstance.logLevel,
flag: flag,
Expand All @@ -31,4 +31,21 @@ struct AppSyncLogHelper {
format: message,
arguments: getVaList([]))
}

static var subscriptionLogLevel: AppSyncRealTimeClient.LogLevel {
switch AWSDDLog.sharedInstance.logLevel {
case .off, .error:
return .error
case .warning:
return .warn
case .info:
return .info
case .debug:
return .debug
case .verbose, .all:
return .verbose
@unknown default:
return .error
}
}
}
5 changes: 2 additions & 3 deletions AWSAppSyncTestCommon/AppSyncClientTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ public class AppSyncClientTestHelper: NSObject {
throw TestHelperError.setupError(AppSyncClientTestHelper.testSetupErrorMessage)
}

AWSDDLog.sharedInstance.logLevel = .error
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)

AWSDDLog.sharedInstance.add(AWSDDTTYLogger.sharedInstance)

let appSyncConfig = try AppSyncClientTestHelper.makeAppSyncConfiguration(
for: authenticationType,
testConfiguration: resolvedTestConfiguration,
Expand Down

0 comments on commit 798ba34

Please sign in to comment.