Skip to content

Commit f488718

Browse files
Add ios native logs (#8555) (#8631)
* Add ios native logs * Use correct version * Revert unneeded changes in package-lock (cherry picked from commit a1ccdcb) Co-authored-by: Daniel Espino García <[email protected]>
1 parent d17516e commit f488718

File tree

7 files changed

+123
-33
lines changed

7 files changed

+123
-33
lines changed

ios/Mattermost.xcodeproj/project.pbxproj

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
27C667A529523F0A00E590D5 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = 27C667A429523F0A00E590D5 /* Sentry */; };
1717
27C667A9295241B600E590D5 /* Sentry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C667A8295241B600E590D5 /* Sentry.swift */; };
1818
27C667AA295241B600E590D5 /* Sentry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27C667A8295241B600E590D5 /* Sentry.swift */; };
19+
413A0FD06EA0DB2B3F30403F /* libPods-NotificationService.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AEDDC97F55A1F6C056C6B1BC /* libPods-NotificationService.a */; };
1920
49AE370126D4455D00EF4E52 /* Gekidou in Frameworks */ = {isa = PBXBuildFile; productRef = 49AE370026D4455D00EF4E52 /* Gekidou */; };
2021
536CC6C323E79287002C478C /* RNNotificationEventHandler+HandleReplyAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 536CC6C123E79287002C478C /* RNNotificationEventHandler+HandleReplyAction.m */; };
2122
58495E36BF1A4EAB93609E57 /* Metropolis-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 54956DEFEBB74EF78C3A6AE5 /* Metropolis-SemiBold.ttf */; };
@@ -379,6 +380,8 @@
379380
83ABFD0F2C1C90D90029685B /* calls_cheerful.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; name = calls_cheerful.mp3; path = ../assets/sounds/calls_cheerful.mp3; sourceTree = "<group>"; };
380381
83ABFD102C1C90D90029685B /* calls_calm.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; name = calls_calm.mp3; path = ../assets/sounds/calls_calm.mp3; sourceTree = "<group>"; };
381382
83ABFD112C1C90D90029685B /* calls_urgent.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; name = calls_urgent.mp3; path = ../assets/sounds/calls_urgent.mp3; sourceTree = "<group>"; };
383+
A10297DBBE728B2BF1BC045E /* Pods-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.debug.xcconfig"; sourceTree = "<group>"; };
384+
AEDDC97F55A1F6C056C6B1BC /* libPods-NotificationService.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-NotificationService.a"; sourceTree = BUILT_PRODUCTS_DIR; };
382385
BC977883E2624E05975CA65B /* OpenSans-Regular.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "OpenSans-Regular.ttf"; path = "../assets/fonts/OpenSans-Regular.ttf"; sourceTree = "<group>"; };
383386
BE17F630DB5D41FD93F32D22 /* OpenSans-LightItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "OpenSans-LightItalic.ttf"; path = "../assets/fonts/OpenSans-LightItalic.ttf"; sourceTree = "<group>"; };
384387
C9A1070F2BBD7C8700753CDC /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
@@ -388,6 +391,7 @@
388391
E5C16B14E1CE4868886A1A00 /* OpenSans-SemiBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "OpenSans-SemiBold.ttf"; path = "../assets/fonts/OpenSans-SemiBold.ttf"; sourceTree = "<group>"; };
389392
E7BEDFCF1660521CCB3EADEF /* Pods-Mattermost.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mattermost.release.xcconfig"; path = "Target Support Files/Pods-Mattermost/Pods-Mattermost.release.xcconfig"; sourceTree = "<group>"; };
390393
FBBEC29EE2D3418D9AC33BD5 /* OpenSans-ExtraBoldItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "OpenSans-ExtraBoldItalic.ttf"; path = "../assets/fonts/OpenSans-ExtraBoldItalic.ttf"; sourceTree = "<group>"; };
394+
FF7D3AE3E5E892576497A111 /* Pods-NotificationService.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.release.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.release.xcconfig"; sourceTree = "<group>"; };
391395
/* End PBXFileReference section */
392396

393397
/* Begin PBXFrameworksBuildPhase section */
@@ -406,6 +410,7 @@
406410
files = (
407411
49AE370126D4455D00EF4E52 /* Gekidou in Frameworks */,
408412
27C667A329523ECA00E590D5 /* Sentry in Frameworks */,
413+
413A0FD06EA0DB2B3F30403F /* libPods-NotificationService.a in Frameworks */,
409414
);
410415
runOnlyForDeploymentPostprocessing = 0;
411416
};
@@ -527,6 +532,8 @@
527532
children = (
528533
2E17B88EAD6181B9E9A24084 /* Pods-Mattermost.debug.xcconfig */,
529534
E7BEDFCF1660521CCB3EADEF /* Pods-Mattermost.release.xcconfig */,
535+
A10297DBBE728B2BF1BC045E /* Pods-NotificationService.debug.xcconfig */,
536+
FF7D3AE3E5E892576497A111 /* Pods-NotificationService.release.xcconfig */,
530537
);
531538
path = Pods;
532539
sourceTree = "<group>";
@@ -561,6 +568,7 @@
561568
7F43D6051F6BF9EB001FC614 /* libPods-Mattermost.a */,
562569
81061F4CBB31484A94D5A8EE /* libz.tbd */,
563570
7A83BBA09DE89A630126EA06 /* libPods-Mattermost.a */,
571+
AEDDC97F55A1F6C056C6B1BC /* libPods-NotificationService.a */,
564572
);
565573
name = Frameworks;
566574
sourceTree = "<group>";
@@ -1080,9 +1088,11 @@
10801088
isa = PBXNativeTarget;
10811089
buildConfigurationList = 7F581D82221ED5C60099E66B /* Build configuration list for PBXNativeTarget "NotificationService" */;
10821090
buildPhases = (
1091+
656D4CFDAC0EC1C1E94D9329 /* [CP] Check Pods Manifest.lock */,
10831092
7F581D2E221ED5C60099E66B /* Sources */,
10841093
7F581D2F221ED5C60099E66B /* Frameworks */,
10851094
7F581D30221ED5C60099E66B /* Resources */,
1095+
FABCD84BD2A468FFB374B89C /* [CP] Copy Pods Resources */,
10861096
);
10871097
buildRules = (
10881098
);
@@ -1473,6 +1483,28 @@
14731483
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Mattermost/Pods-Mattermost-resources.sh\"\n";
14741484
showEnvVarsInLog = 0;
14751485
};
1486+
656D4CFDAC0EC1C1E94D9329 /* [CP] Check Pods Manifest.lock */ = {
1487+
isa = PBXShellScriptBuildPhase;
1488+
buildActionMask = 2147483647;
1489+
files = (
1490+
);
1491+
inputFileListPaths = (
1492+
);
1493+
inputPaths = (
1494+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
1495+
"${PODS_ROOT}/Manifest.lock",
1496+
);
1497+
name = "[CP] Check Pods Manifest.lock";
1498+
outputFileListPaths = (
1499+
);
1500+
outputPaths = (
1501+
"$(DERIVED_FILE_DIR)/Pods-NotificationService-checkManifestLockResult.txt",
1502+
);
1503+
runOnlyForDeploymentPostprocessing = 0;
1504+
shellPath = /bin/sh;
1505+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
1506+
showEnvVarsInLog = 0;
1507+
};
14761508
A40F47AC8A062DFCF1B2A23E /* [CP] Embed Pods Frameworks */ = {
14771509
isa = PBXShellScriptBuildPhase;
14781510
buildActionMask = 2147483647;
@@ -1529,6 +1561,24 @@
15291561
shellPath = /bin/sh;
15301562
shellScript = "./uploadDebugSymbols.sh\n";
15311563
};
1564+
FABCD84BD2A468FFB374B89C /* [CP] Copy Pods Resources */ = {
1565+
isa = PBXShellScriptBuildPhase;
1566+
buildActionMask = 2147483647;
1567+
files = (
1568+
);
1569+
inputPaths = (
1570+
"${PODS_ROOT}/Target Support Files/Pods-NotificationService/Pods-NotificationService-resources.sh",
1571+
"${PODS_CONFIGURATION_BUILD_DIR}/CocoaLumberjack/CocoaLumberjackPrivacy.bundle",
1572+
);
1573+
name = "[CP] Copy Pods Resources";
1574+
outputPaths = (
1575+
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/CocoaLumberjackPrivacy.bundle",
1576+
);
1577+
runOnlyForDeploymentPostprocessing = 0;
1578+
shellPath = /bin/sh;
1579+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NotificationService/Pods-NotificationService-resources.sh\"\n";
1580+
showEnvVarsInLog = 0;
1581+
};
15321582
/* End PBXShellScriptBuildPhase section */
15331583

15341584
/* Begin PBXSourcesBuildPhase section */
@@ -2070,6 +2120,7 @@
20702120
};
20712121
7F581D3A221ED5C60099E66B /* Debug */ = {
20722122
isa = XCBuildConfiguration;
2123+
baseConfigurationReference = A10297DBBE728B2BF1BC045E /* Pods-NotificationService.debug.xcconfig */;
20732124
buildSettings = {
20742125
CLANG_ANALYZER_NONNULL = YES;
20752126
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
@@ -2118,6 +2169,7 @@
21182169
};
21192170
7F581D3B221ED5C60099E66B /* Release */ = {
21202171
isa = XCBuildConfiguration;
2172+
baseConfigurationReference = FF7D3AE3E5E892576497A111 /* Pods-NotificationService.release.xcconfig */;
21212173
buildSettings = {
21222174
CLANG_ANALYZER_NONNULL = YES;
21232175
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;

ios/Mattermost/AppDelegate.mm

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#import <RNKeychain/RNKeychainManager.h>
88
#import <ReactNativeNavigation/ReactNativeNavigation.h>
99
#import <UserNotifications/UserNotifications.h>
10+
#import <TurboLogIOSNative/TurboLog.h>
1011

1112
#import "Mattermost-Swift.h"
1213
#import <os/log.h>
@@ -28,14 +29,23 @@ -(void)application:(UIApplication *)application handleEventsForBackgroundURLSess
2829

2930
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
3031
{
32+
NSString *appGroupId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppGroupIdentifier"];
33+
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId];
34+
containerURL = [containerURL URLByAppendingPathComponent:@"Logs"];
35+
NSError *error = nil;
36+
[TurboLog configureWithDailyRolling:FALSE maximumFileSize:1024*1024 maximumNumberOfFiles:2 logsDirectory:containerURL.path logsFilename:@"MMLogs" error:&error];
37+
if (error) {
38+
NSLog(@"Failed to configure TurboLog: %@", error.localizedDescription);
39+
}
40+
[TurboLog writeWithLogLevel:TurboLogLevelInfo message:@[@"Configured turbolog"]];
3141
OrientationManager.shared.delegate = self;
3242

3343
// Clear keychain on first run in case of reinstallation
3444
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FirstRun"]) {
3545

3646
RNKeychainManager *keychain = [[RNKeychainManager alloc] init];
3747
NSArray<NSString*> *servers = [keychain getAllServersForInternetPasswords];
38-
NSLog(@"Servers %@", servers);
48+
[TurboLog writeWithLogLevel:TurboLogLevelInfo message:@[@"Servers", servers]];
3949
for (NSString *server in servers) {
4050
[keychain deleteCredentialsForServer:server withOptions:nil];
4151
}

ios/NotificationService/NotificationService.swift

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Gekidou
22
import UserNotifications
33
import Intents
44
import os.log
5+
import TurboLogIOSNative
56

67
class NotificationService: UNNotificationServiceExtension {
78
var contentHandler: ((UNNotificationContent) -> Void)?
@@ -10,47 +11,56 @@ class NotificationService: UNNotificationServiceExtension {
1011
override init() {
1112
super.init()
1213
initSentryAppExt()
14+
do {
15+
let appGroupId = Bundle.main.object(forInfoDictionaryKey: "AppGroupIdentifier") as! String
16+
let containerUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupId)
17+
try TurboLogIOSNative.TurboLogger.configure(dailyRolling: false, maximumFileSize: 1024*1024, maximumNumberOfFiles: 2, logsDirectory: containerUrl!.appendingPathComponent("Logs").path, logsFilename: "MMLogs")
18+
} catch {
19+
os_log(OSLogType.default, "Failed to configure TurboLogger: %{public}@", String(describing: error))
20+
}
1321
}
1422

1523
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
1624
self.contentHandler = contentHandler
1725

26+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: received notification")
1827
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
1928
if let bestAttemptContent = bestAttemptContent {
2029
PushNotification.default.postNotificationReceipt(bestAttemptContent, completionHandler: {[weak self] notification in
2130
if let notification = notification {
2231
self?.bestAttemptContent = notification
2332
if (!PushNotification.default.verifySignatureFromNotification(notification)) {
33+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: signature not verified. Will call sendInvalidNotificationIntent")
2434
self?.sendInvalidNotificationIntent()
2535
return
2636
}
2737
if (Gekidou.Preferences.default.object(forKey: "ApplicationIsRunning") as? String != "true") {
2838
PushNotification.default.fetchAndStoreDataForPushNotification(bestAttemptContent, withContentHandler: {notification in
29-
os_log(OSLogType.default, "Mattermost Notifications: processed data for db. Will call sendMessageIntent")
39+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: processed data for db. Will call sendMessageIntent")
3040
self?.sendMessageIntent()
3141
})
3242
} else {
3343
bestAttemptContent.badge = nil
34-
os_log(OSLogType.default, "Mattermost Notifications: app in use, no data processed. Will call sendMessageIntent")
44+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: app in use, no data processed. Will call sendMessageIntent")
3545
self?.sendMessageIntent()
3646
}
3747
return
3848
}
3949

40-
os_log(OSLogType.default, "Mattermost Notifications: notification receipt seems to be empty, will call sendMessageIntent")
50+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: notification receipt seems to be empty, will call sendMessageIntent")
4151
self?.sendMessageIntent()
4252
})
4353
} else {
44-
os_log(OSLogType.default, "Mattermost Notifications: bestAttemptContent seems to be empty, will call sendMessageIntent")
54+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: bestAttemptContent seems to be empty, will call sendMessageIntent")
4555
sendMessageIntent()
4656
}
4757
}
4858

4959
override func serviceExtensionTimeWillExpire() {
5060
// Called just before the extension will be terminated by the system.
5161
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
52-
os_log(OSLogType.default, "Mattermost Notifications: service extension time expired")
53-
os_log(OSLogType.default, "Mattermost Notifications: calling sendMessageIntent before expiration")
62+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: service extension time expired")
63+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: calling sendMessageIntent before expiration")
5464
sendMessageIntent()
5565
}
5666

@@ -62,13 +72,13 @@ class NotificationService: UNNotificationServiceExtension {
6272

6373
guard let serverUrl = notification.userInfo["server_url"] as? String
6474
else {
65-
os_log(OSLogType.default, "Mattermost Notifications: No intent created. will call contentHandler to present notification")
75+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: No intent created. will call contentHandler to present notification")
6676
self.contentHandler?(notification)
6777
return
6878
}
6979

7080
let overrideIconUrl = notification.userInfo["override_icon_url"] as? String
71-
os_log(OSLogType.default, "Mattermost Notifications: Fetching profile Image in server %{public}@ for sender %{public}@", serverUrl, senderId ?? overrideUsername ?? "no sender is set")
81+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: Fetching profile Image in server", serverUrl, "for sender", senderId ?? overrideUsername ?? "no sender is set")
7282
if senderId != nil || overrideIconUrl != nil {
7383
PushNotification.default.fetchProfileImageSync(serverUrl, senderId: senderId ?? "", overrideIconUrl: overrideIconUrl) {[weak self] data in
7484
self?.sendMessageIntentCompletion(data)
@@ -81,7 +91,7 @@ class NotificationService: UNNotificationServiceExtension {
8191

8292
private func sendInvalidNotificationIntent() {
8393
guard let notification = bestAttemptContent else { return }
84-
os_log(OSLogType.default, "Mattermost Notifications: creating invalid intent")
94+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: creating invalid intent")
8595

8696
bestAttemptContent?.body = NSLocalizedString( "native.ios.notifications.not_verified",
8797
value: "We could not verify this notification with the server",
@@ -103,15 +113,15 @@ class NotificationService: UNNotificationServiceExtension {
103113
interaction.donate { error in
104114
if error != nil {
105115
self.contentHandler?(notification)
106-
os_log(OSLogType.default, "Mattermost Notifications: sendMessageIntent intent error %{public}@", error! as CVarArg)
116+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: sendMessageIntent intent error", error! as CVarArg)
107117
}
108118

109119
do {
110120
let updatedContent = try notification.updating(from: intent)
111-
os_log(OSLogType.default, "Mattermost Notifications: present updated notification")
121+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: present updated notification")
112122
self.contentHandler?(updatedContent)
113123
} catch {
114-
os_log(OSLogType.default, "Mattermost Notifications: something failed updating the notification %{public}@", error as CVarArg)
124+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: something failed updating the notification", error as CVarArg)
115125
self.contentHandler?(notification)
116126
}
117127
}
@@ -125,7 +135,7 @@ class NotificationService: UNNotificationServiceExtension {
125135
if #available(iOSApplicationExtension 15.0, *),
126136
let imgData = avatarData,
127137
let channelId = notification.userInfo["channel_id"] as? String {
128-
os_log(OSLogType.default, "Mattermost Notifications: creating intent")
138+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: creating intent")
129139

130140
let isCRTEnabled = notification.userInfo["is_crt_enabled"] as? Bool ?? false
131141
let rootId = notification.userInfo["root_id"] as? String ?? ""
@@ -171,15 +181,15 @@ class NotificationService: UNNotificationServiceExtension {
171181
interaction.donate { error in
172182
if error != nil {
173183
self.contentHandler?(notification)
174-
os_log(OSLogType.default, "Mattermost Notifications: sendMessageIntent intent error %{public}@", error! as CVarArg)
184+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: sendMessageIntent intent error", error! as CVarArg)
175185
}
176186

177187
do {
178188
let updatedContent = try notification.updating(from: intent)
179-
os_log(OSLogType.default, "Mattermost Notifications: present updated notification")
189+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: present updated notification")
180190
self.contentHandler?(updatedContent)
181191
} catch {
182-
os_log(OSLogType.default, "Mattermost Notifications: something failed updating the notification %{public}@", error as CVarArg)
192+
TurboLogIOSNative.TurboLogger.write(level: .info, message: "Mattermost Notifications: something failed updating the notification", error as CVarArg)
183193
self.contentHandler?(notification)
184194
}
185195
}

0 commit comments

Comments
 (0)