Skip to content

Commit

Permalink
Adopt consolidated logging mechanism (#4370)
Browse files Browse the repository at this point in the history
* Adopted the new MXLog and replaced NSLog throughout the application - /issues/4351
* Replaced NSLog() and print() usages with MXLog.debug()
* Added swiftlint rules for NSLog(), print(), println() and os_log()
* Escape paths used to run script build phases for swiftlint and swiftgen
  • Loading branch information
stefanceriu committed Jun 3, 2021
1 parent 7b9a2de commit f7a8163
Show file tree
Hide file tree
Showing 94 changed files with 689 additions and 630 deletions.
28 changes: 28 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,31 @@ type_name:
max_length: # warning and error
warning: 150
error: 1000

custom_rules:
ns_log_deprecation:
regex: "\\b(NSLog)\\b"
match_kinds: identifier
message: "MXLog should be used instead of NSLog()"
severity: error

print_deprecation:
regex: "\\b(print)\\b"
match_kinds: identifier
message: "MXLog should be used instead of print()"
severity: error

print_ln_deprecation:
regex: "\\b(println)\\b"
match_kinds: identifier
message: "MXLog should be used instead of println()"
severity: error

os_log_deprecation:
regex: "\\b(os_log)\\b"
match_kinds: identifier
message: "MXLog should be used instead of os_log()"
severity: error



1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changes to be released in next version
* Navigation: Start decoupling view controllers managed by MasterTabBarController (#3596 and #3618).
* Jitsi: Include optional server name field on JitsiJWTPayloadContextMatrix.
* CallPresenter: Add more logs for group calls.
* Logging: Adopted MXLog throughout the application (vector-im/element-ios/issues/4351).

🐛 Bugfix
* buildRelease.sh: Make bundler operations in the cloned repository folder.
Expand Down
2 changes: 1 addition & 1 deletion Riot/Categories/MXKRoomBubbleTableViewCell+Riot.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ - (void)addTimestampLabelForComponentIndex:(NSInteger)componentIndex
{
if (!self.bubbleInfoContainer)
{
NSLog(@"[MXKRoomBubbleTableViewCell+Riot] bubbleInfoContainer property is missing for cell class: %@", NSStringFromClass(self.class));
MXLogDebug(@"[MXKRoomBubbleTableViewCell+Riot] bubbleInfoContainer property is missing for cell class: %@", NSStringFromClass(self.class));
return;
}

Expand Down
8 changes: 4 additions & 4 deletions Riot/Categories/MXRoom+Riot.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (void)setRoomTag:(NSString*)tag completion:(void (^)(void))completion

NSString* tagOrder = [self.mxSession tagOrderToBeAtIndex:0 from:NSNotFound withTag:tag];

NSLog(@"[MXRoom+Riot] Update the room %@ tag from %@ to %@ with tag order %@", self.roomId, oldTag, tag, tagOrder);
MXLogDebug(@"[MXRoom+Riot] Update the room %@ tag from %@ to %@ with tag order %@", self.roomId, oldTag, tag, tagOrder);

[self replaceTag:oldTag
byTag:tag
Expand All @@ -57,7 +57,7 @@ - (void)setRoomTag:(NSString*)tag completion:(void (^)(void))completion

} failure:^(NSError *error) {

NSLog(@"[MXRoom+Riot] Failed to update the tag %@ of room (%@)", tag, self.roomId);
MXLogDebug(@"[MXRoom+Riot] Failed to update the tag %@ of room (%@)", tag, self.roomId);
NSString *userId = self.mxSession.myUser.userId;

// Notify user
Expand Down Expand Up @@ -166,7 +166,7 @@ - (void)mute:(void (^)(void))completion
// Check whether there is no pending update for this room
if (self.notificationCenterDidUpdateObserver)
{
NSLog(@"[MXRoom+Riot] Request in progress: ignore push rule update");
MXLogDebug(@"[MXRoom+Riot] Request in progress: ignore push rule update");
if (completion)
{
completion();
Expand Down Expand Up @@ -244,7 +244,7 @@ - (void)mentionsOnly:(void (^)(void))completion
// Check whether there is no pending update for this room
if (self.notificationCenterDidUpdateObserver)
{
NSLog(@"[MXRoom+Riot] Request in progress: ignore push rule update");
MXLogDebug(@"[MXRoom+Riot] Request in progress: ignore push rule update");
if (completion)
{
completion();
Expand Down
5 changes: 3 additions & 2 deletions Riot/Categories/UNUserNotificationCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import Foundation
import UserNotifications
import MatrixSDK

@objc extension UNUserNotificationCenter {

Expand All @@ -24,7 +25,7 @@ import UserNotifications
// get identifiers of notifications whose category identifiers are "TO_BE_REMOVED"
let identifiersToBeRemoved = notifications.compactMap({ $0.request.content.categoryIdentifier == Constants.toBeRemovedNotificationCategoryIdentifier ? $0.request.identifier : nil })

NSLog("[UNUserNotificationCenter] removeUnwantedNotifications: Removing \(identifiersToBeRemoved.count) notifications.")
MXLog.debug("[UNUserNotificationCenter] removeUnwantedNotifications: Removing \(identifiersToBeRemoved.count) notifications.")
// remove the notifications with these id's
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiersToBeRemoved)
}
Expand Down Expand Up @@ -52,7 +53,7 @@ import UserNotifications
// get identifiers of notifications that should be removed
let identifiersToBeRemoved = notifications.compactMap({ notificationShouldBeRemoved($0) ? $0.request.identifier : nil })

NSLog("[UNUserNotificationCenter] removeCallNotifications: Removing \(identifiersToBeRemoved.count) notifications.")
MXLog.debug("[UNUserNotificationCenter] removeCallNotifications: Removing \(identifiersToBeRemoved.count) notifications.")
// remove the notifications with these id's
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiersToBeRemoved)
}
Expand Down
2 changes: 1 addition & 1 deletion Riot/Managers/Analytics/Analytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ - (void)start
}
else
{
NSLog(@"[AppDelegate] The user decided to not send analytics");
MXLogDebug(@"[AppDelegate] The user decided to not send analytics");
matomoTracker.isOptedOut = YES;
[MXLogger logCrashes:NO];
}
Expand Down
2 changes: 1 addition & 1 deletion Riot/Managers/Analytics/DecryptionFailureTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ - (void)checkFailures
failuresCounts[failure.reason] = @(failuresCounts[failure.reason].unsignedIntegerValue + 1);
}

NSLog(@"[DecryptionFailureTracker] trackFailures: %@", failuresCounts);
MXLogDebug(@"[DecryptionFailureTracker] trackFailures: %@", failuresCounts);

for (NSString *reason in failuresCounts)
{
Expand Down
4 changes: 2 additions & 2 deletions Riot/Managers/BugReport/RageShakeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ - (void)startShaking:(UIResponder*)responder {
&& RiotSettings.shared.enableRageShake
&& !confirmationAlert)
{
NSLog(@"[RageShakeManager] Start shaking with [%@]", [responder class]);
MXLogDebug(@"[RageShakeManager] Start shaking with [%@]", [responder class]);

startShakingTimeStamp = [[NSDate date] timeIntervalSince1970];
isShaking = YES;
Expand All @@ -124,7 +124,7 @@ - (void)startShaking:(UIResponder*)responder {

- (void)stopShaking:(UIResponder*)responder
{
NSLog(@"[RageShakeManager] Stop shaking with [%@]", [responder class]);
MXLogDebug(@"[RageShakeManager] Stop shaking with [%@]", [responder class]);

if (isShaking && [AppDelegate theDelegate].isAppForeground && !confirmationAlert
&& (([[NSDate date] timeIntervalSince1970] - startShakingTimeStamp) > RAGESHAKEMANAGER_MINIMUM_SHAKING_DURATION))
Expand Down
Loading

0 comments on commit f7a8163

Please sign in to comment.