From 1106ca5eb181f024d20b1c607d3e4859ac8643f9 Mon Sep 17 00:00:00 2001 From: gmbnt Date: Tue, 31 Mar 2020 16:34:31 +1100 Subject: [PATCH] Make logging more useful --- Signal/src/AppDelegate.m | 2 -- .../Utilities/LokiPushNotificationManager.swift | 2 +- SignalServiceKit/src/Contacts/TSThread.m | 2 +- .../src/Loki/API/LokiAPI+SwarmAPI.swift | 2 +- SignalServiceKit/src/Loki/API/LokiAPI.swift | 8 -------- .../src/Loki/API/LokiFileServerProxy.swift | 1 - SignalServiceKit/src/Loki/API/LokiPoller.swift | 1 - SignalServiceKit/src/Loki/API/LokiSnodeProxy.swift | 1 - .../Database/LokiSessionResetImplementation.swift | 4 ++-- .../src/Loki/Database/OWSPrimaryStorage+Loki.m | 7 ++++--- .../src/Messages/Interactions/TSMessage.m | 2 +- SignalServiceKit/src/Messages/OWSMessageManager.m | 14 +++++++------- 12 files changed, 17 insertions(+), 29 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 5dd5662ae..40eb01790 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -1181,11 +1181,9 @@ static BOOL isUsingFullAPNs = YES; PMKJoin(promises).then(^(id results) { completionHandler(UIBackgroundFetchResultNewData); CurrentAppContext().wasWokenUpBySilentPushNotification = false; - [LKLogger print:@"[Loki] UIBackgroundFetchResultNewData"]; }).catch(^(id error) { completionHandler(UIBackgroundFetchResultFailed); CurrentAppContext().wasWokenUpBySilentPushNotification = false; - [LKLogger print:@"[Loki] UIBackgroundFetchResultFailed"]; }); } diff --git a/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift b/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift index d37c71e7d..a9542f960 100644 --- a/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift +++ b/Signal/src/Loki/Utilities/LokiPushNotificationManager.swift @@ -28,7 +28,7 @@ final class LokiPushNotificationManager : NSObject { return print("[Loki] Device token hasn't changed; no need to re-upload.") } guard !isUsingFullAPNs else { - return print("[Loki] Using full APNs; no need to upload device token.") + return print("[Loki] Using full APNs; ignoring call to register(with:).") } let parameters = [ "token" : hexEncodedToken ] let request = TSRequest(url: url, method: "POST", parameters: parameters) diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index b8b61ef42..59860ed44 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -780,7 +780,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa - (void)saveFriendRequestStatus:(LKThreadFriendRequestStatus)friendRequestStatus withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction { self.friendRequestStatus = friendRequestStatus; - NSLog(@"[Loki] Setting thread friend request status to %@.", self.friendRequestStatusDescription); + [LKLogger print:[NSString stringWithFormat:@"[Loki] Setting thread friend request status to %@.", self.friendRequestStatusDescription]]; void (^postNotification)() = ^() { [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.threadFriendRequestStatusChanged object:self.uniqueId]; }; diff --git a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift index ef631140d..42fc8401d 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift @@ -48,7 +48,7 @@ public extension LokiAPI { ] ] ]) - print("[Loki] Invoking get_service_nodes on \(target).") + print("[Loki] Populating snode pool using: \(target).") return TSNetworkManager.shared().perform(request, withCompletionQueue: DispatchQueue.global()).map(on: DispatchQueue.global()) { intermediate in let rawResponse = intermediate.responseObject guard let json = rawResponse as? JSON, let intermediate = json["result"] as? JSON, let rawTargets = intermediate["service_node_states"] as? [JSON] else { throw LokiAPIError.randomSnodePoolUpdatingFailed } diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index d69c1abde..b112e5adb 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -98,9 +98,6 @@ public final class LokiAPI : NSObject { let request = TSRequest(url: url, method: "POST", parameters: [ "method" : method.rawValue, "params" : parameters ]) if let headers = headers { request.allHTTPHeaderFields = headers } request.timeoutInterval = timeout ?? defaultTimeout - let headers = request.allHTTPHeaderFields ?? [:] - let headersDescription = headers.isEmpty ? "no custom headers specified" : headers.prettifiedDescription - print("[Loki] Invoking \(method.rawValue) on \(target) with \(parameters.prettifiedDescription) (\(headersDescription)).") return LokiSnodeProxy(for: target).perform(request, withCompletionQueue: DispatchQueue.global()) .handlingSwarmSpecificErrorsIfNeeded(for: target, associatedWith: hexEncodedPublicKey) .recoveringNetworkErrorsIfNeeded() @@ -259,11 +256,6 @@ public final class LokiAPI : NSObject { let newRawMessages = removeDuplicates(from: rawMessages) let newMessages = parseProtoEnvelopes(from: newRawMessages) let newMessageCount = newMessages.count - if newMessageCount == 1 { - print("[Loki] Retrieved 1 new message.") - } else if (newMessageCount != 0) { - print("[Loki] Retrieved \(newMessageCount) new messages.") - } return newMessages } diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift index 76463b711..8cb0be5d8 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift @@ -56,7 +56,6 @@ internal class LokiFileServerProxy : LokiHTTPClient { serverURLEndIndex < urlAsString.endIndex else { throw Error.endpointParsingFailed } let endpointStartIndex = urlAsString.index(after: serverURLEndIndex) let endpoint = String(urlAsString[endpointStartIndex.. Promise in let url = "\(proxy.address):\(proxy.port)/proxy" - print("[Loki] Proxying request to \(target) through \(proxy).") let parametersAsData = try JSONSerialization.data(withJSONObject: request.parameters, options: []) let proxyRequestParameters: JSON = [ "method" : request.httpMethod, diff --git a/SignalServiceKit/src/Loki/Database/LokiSessionResetImplementation.swift b/SignalServiceKit/src/Loki/Database/LokiSessionResetImplementation.swift index bf6307bd1..e5bfd99b7 100644 --- a/SignalServiceKit/src/Loki/Database/LokiSessionResetImplementation.swift +++ b/SignalServiceKit/src/Loki/Database/LokiSessionResetImplementation.swift @@ -16,7 +16,7 @@ public class LokiSessionResetImplementation : NSObject, SessionResetProtocol { public func validatePreKeyForFriendRequestAcceptance(for recipientID: String, whisperMessage: CipherMessage, protocolContext: Any?) throws { guard let transaction = protocolContext as? YapDatabaseReadWriteTransaction else { - print("[Loki] Could not verify friend request acceptance pre key because an invalid transaction was provided.") + print("[Loki] Couldn't verify friend request acceptance pre key because an invalid transaction was provided.") return } guard let preKeyMessage = whisperMessage as? PreKeyWhisperMessage else { return } @@ -32,7 +32,7 @@ public class LokiSessionResetImplementation : NSObject, SessionResetProtocol { public func getSessionResetStatus(for recipientID: String, protocolContext: Any?) -> SessionResetStatus { guard let transaction = protocolContext as? YapDatabaseReadWriteTransaction else { - print("[Loki] Could not get session reset status for \(recipientID) because an invalid transaction was provided.") + print("[Loki] Couldn't get session reset status for \(recipientID) because an invalid transaction was provided.") return .none } guard let thread = TSContactThread.getWithContactId(recipientID, transaction: transaction) else { return .none } diff --git a/SignalServiceKit/src/Loki/Database/OWSPrimaryStorage+Loki.m b/SignalServiceKit/src/Loki/Database/OWSPrimaryStorage+Loki.m index 38312b1fe..f7e01dd11 100644 --- a/SignalServiceKit/src/Loki/Database/OWSPrimaryStorage+Loki.m +++ b/SignalServiceKit/src/Loki/Database/OWSPrimaryStorage+Loki.m @@ -11,6 +11,7 @@ #import "YapDatabaseTransaction+OWS.h" #import #import "NSObject+Casting.h" +#import @implementation OWSPrimaryStorage (Loki) @@ -58,7 +59,7 @@ @try { return [self throws_loadPreKey:preKeyId]; } @catch (NSException *exception) { - NSLog(@"[Loki] New pre key generated for %@.", pubKey); + [LKLogger print:[NSString stringWithFormat:@"[Loki] New pre key generated for %@.", pubKey]]; return [self generateAndStorePreKeyForContact:pubKey]; } } @@ -95,7 +96,7 @@ [signedPreKeyRecord markAsAcceptedByService]; [self storeSignedPreKey:signedPreKeyRecord.Id signedPreKeyRecord:signedPreKeyRecord]; [self setCurrentSignedPrekeyId:signedPreKeyRecord.Id]; - NSLog(@"[Loki] Pre keys refreshed successfully."); + [LKLogger print:@"[Loki] Pre keys refreshed successfully."]; } SignedPreKeyRecord *_Nullable signedPreKey = self.currentSignedPreKey; @@ -134,7 +135,7 @@ forceClean = YES; } } - OWSLogWarn(@"[Loki] Failed to generate a valid pre key bundle for: %@.", pubKey); + [LKLogger print:[NSString stringWithFormat:@"[Loki] Failed to generate a valid pre key bundle for: %@.", pubKey]]; return nil; } diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.m b/SignalServiceKit/src/Messages/Interactions/TSMessage.m index 562d37057..2d4a2d4f6 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.m @@ -450,7 +450,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4; - (void)saveFriendRequestStatus:(LKMessageFriendRequestStatus)friendRequestStatus withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction { self.friendRequestStatus = friendRequestStatus; - NSLog(@"[Loki] Setting message friend request status to %@.", self.friendRequestStatusDescription); + [LKLogger print:[NSString stringWithFormat:@"[Loki] Setting message friend request status to %@.", self.friendRequestStatusDescription]]; void (^postNotification)() = ^() { [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.messageFriendRequestStatusChanged object:self.uniqueId]; }; diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index bc6ce2031..4ef1241d1 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -450,7 +450,7 @@ NS_ASSUME_NONNULL_BEGIN // Loki: Handle pre key bundle message if needed if (contentProto.prekeyBundleMessage != nil) { - OWSLogInfo(@"[Loki] Received a pre key bundle message from: %@.", envelope.source); + [LKLogger print:[NSString stringWithFormat:@"[Loki] Received a pre key bundle message from: %@.", envelope.source]]; PreKeyBundle *_Nullable bundle = [contentProto.prekeyBundleMessage getPreKeyBundleWithTransaction:transaction]; if (bundle == nil) { OWSFailDebug(@"Failed to create a pre key bundle."); @@ -484,7 +484,7 @@ NS_ASSUME_NONNULL_BEGIN NSData *masterSignature = contentProto.lokiDeviceLinkMessage.masterSignature; NSData *slaveSignature = contentProto.lokiDeviceLinkMessage.slaveSignature; if (masterSignature != nil) { // Authorization - OWSLogInfo(@"[Loki] Received a device linking authorization from: %@", envelope.source); // Not masterHexEncodedPublicKey + [LKLogger print:[NSString stringWithFormat:@"[Loki] Received a device linking authorization from: %@", envelope.source]]; // Not masterHexEncodedPublicKey [LKDeviceLinkingSession.current processLinkingAuthorizationFrom:masterHexEncodedPublicKey for:slaveHexEncodedPublicKey masterSignature:masterSignature slaveSignature:slaveSignature]; // Set any profile info if (contentProto.dataMessage) { @@ -493,7 +493,7 @@ NS_ASSUME_NONNULL_BEGIN [self handleProfileKeyUpdateIfNeeded:dataMessage recipientId:masterHexEncodedPublicKey]; } } else if (slaveSignature != nil) { // Request - OWSLogInfo(@"[Loki] Received a device linking request from: %@", envelope.source); // Not slaveHexEncodedPublicKey + [LKLogger print: [NSString stringWithFormat:@"[Loki] Received a device linking request from: %@", envelope.source]]; // Not slaveHexEncodedPublicKey if (LKDeviceLinkingSession.current == nil) { [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.unexpectedDeviceLinkRequestReceived object:nil]; } @@ -1140,7 +1140,7 @@ NS_ASSUME_NONNULL_BEGIN } } else if (syncMessage.openGroups != nil) { if (wasSentByMasterDevice && syncMessage.openGroups.count > 0) { - OWSLogInfo(@"[Loki] Received open group sync message."); + [LKLogger print:@"[Loki] Received open group sync message."]; for (SSKProtoSyncMessageOpenGroups* openGroup in syncMessage.openGroups) { [LKPublicChatManager.shared addChatWithServer:openGroup.url channel:openGroup.channel]; } @@ -1191,7 +1191,7 @@ NS_ASSUME_NONNULL_BEGIN LKEphemeralMessage *emptyMessage = [[LKEphemeralMessage alloc] initInThread:thread]; [self.messageSenderJobQueue addMessage:emptyMessage transaction:transaction]; - NSLog(@"[Loki] Session reset received from %@.", hexEncodedPublicKey); + [LKLogger print:[NSString stringWithFormat:@"[Loki] Session reset received from %@.", hexEncodedPublicKey]]; } - (void)handleExpirationTimerUpdateMessageWithEnvelope:(SSKProtoEnvelope *)envelope @@ -1788,11 +1788,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)handleFriendRequestMessageIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope data:(SSKProtoDataMessage *)data message:(TSIncomingMessage *)message thread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction { if (envelope.isGroupChatMessage) { - return NSLog(@"[Loki] Ignoring friend request in group chat.", @""); + return [LKLogger print:@"[Loki] Ignoring friend request in group chat."]; } // The envelope type is set during UD decryption. if (envelope.type != SSKProtoEnvelopeTypeFriendRequest) { - return NSLog(@"[Loki] Ignoring friend request logic for non friend request type envelope."); + return [LKLogger print:@"[Loki] Ignoring friend request logic for non friend request type envelope."]; } if ([self canFriendRequestBeAutoAcceptedForThread:thread transaction:transaction]) { [thread saveFriendRequestStatus:LKThreadFriendRequestStatusFriends withTransaction:transaction];