Skip to content

Commit

Permalink
Bump CocoaLumberjack dependency to master branch
Browse files Browse the repository at this point in the history
This contains all but 1 of the changes we sent upstream, greatly simplifying
our deployment and allowing us to test those changes we pushed upstream.
  • Loading branch information
tmolitor-stud-tu committed Oct 5, 2023
1 parent 8fcf0e4 commit e480f85
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 134 deletions.
1 change: 0 additions & 1 deletion Monal/Classes/HelperTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,6 @@ +(void) configureLogging
self.fileLogger.doNotReuseLogFiles = NO;
self.fileLogger.rollingFrequency = 60 * 60 * 48; // 48 hour rolling
self.fileLogger.maximumFileSize = 128 * 1024 * 1024;
self.fileLogger.archiveAllowed = YES; //everything is configured now, engage logfile archiving
[DDLog addLogger:self.fileLogger];

DDLogDebug(@"Sorted logfiles: %@", [logFileManager sortedLogFileInfos]);
Expand Down
2 changes: 0 additions & 2 deletions Monal/Classes/MLFileLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ NS_ASSUME_NONNULL_BEGIN

@interface MLFileLogger : DDFileLogger

@property (atomic, assign) BOOL archiveAllowed;

@end

NS_ASSUME_NONNULL_END
Expand Down
112 changes: 0 additions & 112 deletions Monal/Classes/MLFileLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,105 +7,11 @@
//

#import <Foundation/Foundation.h>
#include <sys/file.h>
#include <errno.h>

#import "MLFileLogger.h"
#import "HelperTools.h"


extern BOOL doesAppRunInBackground(void);
@interface DDFileLogger ()
-(BOOL) lt_shouldLogFileBeArchived:(DDLogFileInfo*) mostRecentLogFileInfo;
-(void) lt_logData:(NSData*) data;
-(NSFileHandle*) lt_currentLogFileHandle;
@end

@interface MLFileLogger () {
BOOL _archiveAllowed;
}
@end


@implementation MLFileLogger

//overwrite constructor to make sure archiveAllowed is NO when creating this instance
-(instancetype) initWithLogFileManager:(id <DDLogFileManager>) aLogFileManager completionQueue:(nullable dispatch_queue_t) dispatchQueue
{
self = [super initWithLogFileManager:aLogFileManager completionQueue:dispatchQueue];
self.archiveAllowed = NO;
return self;
}

-(BOOL) archiveAllowed
{
//reading an atomic bool does not need to be synchronized
return self->_archiveAllowed;
}

-(void) setArchiveAllowed:(BOOL) archiveAllowed
{
//this must be done on the same queue as lt_shouldLogFileBeArchived is running on to prevent race conditions
dispatch_queue_t globalLoggingQueue = [DDLog loggingQueue];
dispatch_async(globalLoggingQueue, ^{
dispatch_async(self.loggerQueue, ^{
NSLog(@"Setting archiveAllowed = %@", bool2str(archiveAllowed));
self->_archiveAllowed = archiveAllowed;
});
});
}

//patch DDFileLogger to think that this logfile can be reused
-(BOOL) lt_shouldLogFileBeArchived:(DDLogFileInfo*) mostRecentLogFileInfo
{
//just hand over to official implementation once everything is properly configured
if(self.archiveAllowed)
{
NSLog(@"lt_shouldLogFileBeArchived: handing over to super implementation");
return [super lt_shouldLogFileBeArchived:mostRecentLogFileInfo];
}

NSLog(@"lt_shouldLogFileBeArchived: running patched implementation, archiveAllowed==NO");

NSAssert([self isOnInternalLoggerQueue], @"lt_ methods should be on logger queue.");

//this is our change (but the file protection check below is still needed)
// if ([self shouldArchiveRecentLogFileInfo:mostRecentLogFileInfo]) {
// return YES;
// } else if (_maximumFileSize > 0 && mostRecentLogFileInfo.fileSize >= _maximumFileSize) {
// return YES;
// } else if (_rollingFrequency > 0.0 && mostRecentLogFileInfo.age >= _rollingFrequency) {
// return YES;
// }

//this has still to be active, to rotate the logfile if the file protection is wrong (should never happen with our configuration)
#if TARGET_OS_IPHONE
// When creating log file on iOS we're setting NSFileProtectionKey attribute to NSFileProtectionCompleteUnlessOpen.
//
// But in case if app is able to launch from background we need to have an ability to open log file any time we
// want (even if device is locked). Thats why that attribute have to be changed to
// NSFileProtectionCompleteUntilFirstUserAuthentication.
//
// If previous log was created when app wasn't running in background, but now it is - we archive it and create
// a new one.
//
// If user has overwritten to NSFileProtectionNone there is no need to create a new one.
NSFileProtectionType key = mostRecentLogFileInfo.fileAttributes[NSFileProtectionKey];
BOOL isUntilFirstAuth = [key isEqualToString:NSFileProtectionCompleteUntilFirstUserAuthentication];
BOOL isNone = [key isEqualToString:NSFileProtectionNone];

if (key != nil && !isUntilFirstAuth && !isNone) {
NSLog(@"File protection type not sufficient: %@", key);
#ifdef is_ALPHA
unreachable(@"File protection type not sufficient", mostRecentLogFileInfo.fileAttributes);
#endif
return YES;
}
#endif

return NO;
}

-(NSData*) lt_dataForMessage:(DDLogMessage*) logMessage
{
static uint64_t counter = 0;
Expand All @@ -132,22 +38,4 @@ -(NSData*) lt_dataForMessage:(DDLogMessage*) logMessage
return data;
}

-(void) lt_logData:(NSData*) data
{
NSFileHandle* handle = [self lt_currentLogFileHandle];
//this is an error case, just call the super implementation right away (should never happen)
if(handle == nil)
{
NSLog(@"Could not get file handle in lt_logData wrapper!");
return [super lt_logData:data];
}
int fd = [handle fileDescriptor];
while(flock(fd, LOCK_EX) != 0) {
NSLog(@"Could not lock logfile, retrying in 1ms: %s (%d)", strerror(errno), errno);
usleep(1000);
}
[super lt_logData:data];
flock(fd, LOCK_UN);
}

@end
38 changes: 19 additions & 19 deletions Monal/Monal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
8414AE002A7ABC4300EFFCCC /* LibMonalRustSwiftBridge in Frameworks */ = {isa = PBXBuildFile; productRef = 8414ADFF2A7ABC4300EFFCCC /* LibMonalRustSwiftBridge */; };
841898AA2957712000FEC77D /* ViewExtractor in Frameworks */ = {isa = PBXBuildFile; productRef = 841898A92957712000FEC77D /* ViewExtractor */; };
841898AC2957DBAD00FEC77D /* RichAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841898AB2957DBAC00FEC77D /* RichAlert.swift */; };
841B28282ACF75B300BCC42B /* CocoaLumberjack in Frameworks */ = {isa = PBXBuildFile; productRef = 841B28272ACF75B300BCC42B /* CocoaLumberjack */; };
841B282A2ACF75B300BCC42B /* CocoaLumberjackSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 841B28292ACF75B300BCC42B /* CocoaLumberjackSwift */; };
841B282C2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend in Frameworks */ = {isa = PBXBuildFile; productRef = 841B282B2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend */; };
841B6F1A297B18720074F9B7 /* AccountPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841B6F19297B18720074F9B7 /* AccountPicker.swift */; };
841B6F1C297B3CFC0074F9B7 /* AVCallUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841B6F1B297B3CFC0074F9B7 /* AVCallUI.swift */; };
841EE4292A3F46F700D3AF14 /* MLFileLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 841EE4282A3F46F700D3AF14 /* MLFileLogger.m */; };
Expand All @@ -157,9 +160,6 @@
84D31CE628653B83006D7926 /* WebRTCClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D31CE528653B83006D7926 /* WebRTCClient.swift */; };
84E55E7D2964424E003E191A /* ActiveChatsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 261A6284176C156500059090 /* ActiveChatsViewController.m */; };
84E55E8029644279003E191A /* ActiveChatsViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 84E55E7F2964426D003E191A /* ActiveChatsViewController.h */; };
84F498CD2A97A44B00821033 /* CocoaLumberjack in Frameworks */ = {isa = PBXBuildFile; productRef = 84F498CC2A97A44B00821033 /* CocoaLumberjack */; };
84F498CF2A97A44B00821033 /* CocoaLumberjackSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 84F498CE2A97A44B00821033 /* CocoaLumberjackSwift */; };
84F498D12A97A44B00821033 /* CocoaLumberjackSwiftLogBackend in Frameworks */ = {isa = PBXBuildFile; productRef = 84F498D02A97A44B00821033 /* CocoaLumberjackSwiftLogBackend */; };
84FC37552897521500634E3E /* snprintf.m in Sources */ = {isa = PBXBuildFile; fileRef = 84FC37542897521400634E3E /* snprintf.m */; };
84FC37572897523500634E3E /* metamacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 84FC37562897523500634E3E /* metamacros.h */; };
84FC375928981A5600634E3E /* PasswordMigration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FC375828981A5600634E3E /* PasswordMigration.swift */; };
Expand Down Expand Up @@ -780,10 +780,10 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
84F498CD2A97A44B00821033 /* CocoaLumberjack in Frameworks */,
841B28282ACF75B300BCC42B /* CocoaLumberjack in Frameworks */,
BE8B63D2491B1E5582965A8F /* Pods_monalxmpp.framework in Frameworks */,
84F498D12A97A44B00821033 /* CocoaLumberjackSwiftLogBackend in Frameworks */,
84F498CF2A97A44B00821033 /* CocoaLumberjackSwift in Frameworks */,
841B282A2ACF75B300BCC42B /* CocoaLumberjackSwift in Frameworks */,
841B282C2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend in Frameworks */,
8414AE002A7ABC4300EFFCCC /* LibMonalRustSwiftBridge in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1554,10 +1554,10 @@
);
name = monalxmpp;
packageProductDependencies = (
84F498CC2A97A44B00821033 /* CocoaLumberjack */,
84F498CE2A97A44B00821033 /* CocoaLumberjackSwift */,
84F498D02A97A44B00821033 /* CocoaLumberjackSwiftLogBackend */,
8414ADFF2A7ABC4300EFFCCC /* LibMonalRustSwiftBridge */,
841B28272ACF75B300BCC42B /* CocoaLumberjack */,
841B28292ACF75B300BCC42B /* CocoaLumberjackSwift */,
841B282B2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend */,
);
productName = monalxmpp;
productReference = 26CC579223A0867400ABB92A /* monalxmpp.framework */;
Expand Down Expand Up @@ -1707,7 +1707,7 @@
C1F5C7AD2777638B0001F295 /* XCRemoteSwiftPackageReference "swift-collections" */,
C1E1EC79286A025F0097EC74 /* XCRemoteSwiftPackageReference "SwiftSoup" */,
841898A82957712000FEC77D /* XCRemoteSwiftPackageReference "ViewExtractor" */,
84F498CB2A97A44B00821033 /* XCRemoteSwiftPackageReference "cocoalumberjack" */,
841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */,
);
productRefGroup = 19C28FACFE9D520D11CA2CBB /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3987,12 +3987,12 @@
minimumVersion = 2.0.0;
};
};
84F498CB2A97A44B00821033 /* XCRemoteSwiftPackageReference "cocoalumberjack" */ = {
841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/cocoalumberjack/cocoalumberjack";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.0.0;
branch = master;
kind = branch;
};
};
C1E1EC79286A025F0097EC74 /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down Expand Up @@ -4023,19 +4023,19 @@
package = 841898A82957712000FEC77D /* XCRemoteSwiftPackageReference "ViewExtractor" */;
productName = ViewExtractor;
};
84F498CC2A97A44B00821033 /* CocoaLumberjack */ = {
841B28272ACF75B300BCC42B /* CocoaLumberjack */ = {
isa = XCSwiftPackageProductDependency;
package = 84F498CB2A97A44B00821033 /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
package = 841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
productName = CocoaLumberjack;
};
84F498CE2A97A44B00821033 /* CocoaLumberjackSwift */ = {
841B28292ACF75B300BCC42B /* CocoaLumberjackSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 84F498CB2A97A44B00821033 /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
package = 841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
productName = CocoaLumberjackSwift;
};
84F498D02A97A44B00821033 /* CocoaLumberjackSwiftLogBackend */ = {
841B282B2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend */ = {
isa = XCSwiftPackageProductDependency;
package = 84F498CB2A97A44B00821033 /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
package = 841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
productName = CocoaLumberjackSwiftLogBackend;
};
C1E1EC7A286A025F0097EC74 /* SwiftSoup */ = {
Expand Down

0 comments on commit e480f85

Please sign in to comment.