Skip to content

Commit

Permalink
Move to newest CocoaLumberjack implementation (current master)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Dec 12, 2023
1 parent 9f06cae commit c8d1c00
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 99 deletions.
4 changes: 2 additions & 2 deletions Monal/Classes/HelperTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@class XMPPStanza;
@class UNNotificationRequest;
@class DDLogMessage;
@class MLFileLogger;
@class DDFileLogger;
@class UIView;
@class UITapGestureRecognizer;

Expand All @@ -37,7 +37,7 @@ void swizzle(Class c, SEL orig, SEL new);

@interface HelperTools : NSObject

@property (class, nonatomic, strong) MLFileLogger* fileLogger;
@property (class, nonatomic, strong) DDFileLogger* fileLogger;

+(NSData* _Nullable) convertLogmessageToJsonData:(DDLogMessage*) logMessage counter:(uint64_t*) counter andError:(NSError** _Nullable) error;
+(void) initSystem;
Expand Down
6 changes: 3 additions & 3 deletions Monal/Classes/HelperTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#import "DataLayer.h"
#import "OmemoState.h"
#import "MLUDPLogger.h"
#import "MLFileLogger.h"
#import "MLStreamRedirect.h"

@import UserNotifications;
Expand Down Expand Up @@ -1626,8 +1625,9 @@ +(void) configureLogging

//file logger
id<DDLogFileManager> logFileManager = [[MLLogFileManager alloc] initWithLogsDirectory:containerUrl defaultFileProtectionLevel:NSFileProtectionCompleteUntilFirstUserAuthentication];
logFileManager.maximumNumberOfLogFiles = 5;
self.fileLogger = [[MLFileLogger alloc] initWithLogFileManager:logFileManager];
logFileManager.logMessageSerializer = [DDFileLogMLVMessageSerializer new];
logFileManager.maximumNumberOfLogFiles = 4;
self.fileLogger = [[DDFileLogger alloc] initWithLogFileManager:logFileManager];
self.fileLogger.doNotReuseLogFiles = NO;
self.fileLogger.rollingFrequency = 60 * 60 * 48; // 48 hour rolling
self.fileLogger.maximumFileSize = 128 * 1024 * 1024;
Expand Down
1 change: 0 additions & 1 deletion Monal/Classes/MLConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define DDLogStdout(frmt, ...) LOG_MAYBE(NO, ddLogLevel, LOG_FLAG_STDOUT, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
static const DDLogLevel ddLogLevel = LOG_LEVEL_STDOUT;
#import "MLLogFileManager.h"
#import "MLFileLogger.h"


//configure app group constants
Expand Down
23 changes: 0 additions & 23 deletions Monal/Classes/MLFileLogger.h

This file was deleted.

41 changes: 0 additions & 41 deletions Monal/Classes/MLFileLogger.m

This file was deleted.

4 changes: 3 additions & 1 deletion Monal/Classes/MLLogFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
//

#import <Foundation/Foundation.h>
#import "MLConstants.h"

NS_ASSUME_NONNULL_BEGIN

@interface DDFileLogMLVMessageSerializer : NSObject <DDFileLogMessageSerializer>
@end

@interface MLLogFileManager : DDLogFileManagerDefault

-(NSString*) newLogFileName;
Expand Down
38 changes: 37 additions & 1 deletion Monal/Classes/MLLogFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,50 @@
//

#import <Foundation/Foundation.h>
#import "HelperTools.h"
#import "MLLogFileManager.h"

@interface MLLogFileManager ()
@interface DDFileLogMLVMessageSerializer ()
@end

@interface MLLogFileManager ()
@end

static NSString* appName = @"Monal";

@implementation DDFileLogMLVMessageSerializer

-(NSData*) dataForString:(NSString*) string originatingFromMessage:(DDLogMessage*) logMessage
{
static uint64_t counter = 0;

if(logMessage == nil)
{
NSLog(@"Error: logMessage should never be nil when calling dataForString:originatingFromMessage. Given log string: %@", string);
return [NSData new]; //return empty data, e.g. write nothing
}

//encode log message
NSError* error;
NSData* rawData = [HelperTools convertLogmessageToJsonData:logMessage counter:&counter andError:&error];
if(error != nil || rawData == nil)
{
NSLog(@"Error jsonifying log message: %@, logMessage: %@", error, logMessage);
return [NSData new]; //return empty data, e.g. write nothing
}

//add 32bit length prefix
NSAssert(rawData.length < (NSUInteger)1<<30, @"LogMessage is longer than 1<<30 bytes!");
uint32_t length = CFSwapInt32HostToBig((uint32_t)rawData.length);
NSMutableData* data = [[NSMutableData alloc] initWithBytes:&length length:sizeof(length)];
[data appendData:rawData];

//return length_prefix + json_encoded_data
return data;
}

@end

@implementation MLLogFileManager

-(NSString*) newLogFileName
Expand Down
46 changes: 19 additions & 27 deletions Monal/Monal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,8 @@
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 */; };
841EE42B2A3F471100D3AF14 /* MLFileLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 841EE42A2A3F471100D3AF14 /* MLFileLogger.h */; };
841EE4302A426F2300D3AF14 /* MLCrashReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 841EE42F2A426F2300D3AF14 /* MLCrashReporter.m */; };
8420EA9B2915E4FE0038FF40 /* OmemoState.h in Headers */ = {isa = PBXBuildFile; fileRef = 8420EA9A2915E4FE0038FF40 /* OmemoState.h */; };
8420EA9D2915E5100038FF40 /* OmemoState.m in Sources */ = {isa = PBXBuildFile; fileRef = 8420EA9C2915E5100038FF40 /* OmemoState.m */; };
Expand All @@ -160,6 +155,9 @@
84C1CD522A8F617F007076ED /* MLStreamRedirect.m in Sources */ = {isa = PBXBuildFile; fileRef = 84C1CD512A8F617F007076ED /* MLStreamRedirect.m */; };
84C1CD542A8F6196007076ED /* MLStreamRedirect.h in Headers */ = {isa = PBXBuildFile; fileRef = 84C1CD532A8F6196007076ED /* MLStreamRedirect.h */; };
84D31CE628653B83006D7926 /* WebRTCClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D31CE528653B83006D7926 /* WebRTCClient.swift */; };
84DD7EF22B283574005AC131 /* CocoaLumberjack in Frameworks */ = {isa = PBXBuildFile; productRef = 84DD7EF12B283574005AC131 /* CocoaLumberjack */; };
84DD7EF42B283574005AC131 /* CocoaLumberjackSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 84DD7EF32B283574005AC131 /* CocoaLumberjackSwift */; };
84DD7EF62B283574005AC131 /* CocoaLumberjackSwiftLogBackend in Frameworks */ = {isa = PBXBuildFile; productRef = 84DD7EF52B283574005AC131 /* CocoaLumberjackSwiftLogBackend */; };
84E55E7D2964424E003E191A /* ActiveChatsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 261A6284176C156500059090 /* ActiveChatsViewController.m */; };
84E55E8029644279003E191A /* ActiveChatsViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 84E55E7F2964426D003E191A /* ActiveChatsViewController.h */; };
84FC37552897521500634E3E /* snprintf.m in Sources */ = {isa = PBXBuildFile; fileRef = 84FC37542897521400634E3E /* snprintf.m */; };
Expand All @@ -173,7 +171,7 @@
C104918B261301530054AC9E /* monalxmpp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26CC579223A0867400ABB92A /* monalxmpp.framework */; };
C1049199261301710054AC9E /* MLCryptoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1049198261301710054AC9E /* MLCryptoTest.swift */; };
C117F7E12B086390001F2BC6 /* CreateGroupMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D88BB76295BB6DC00FB30BA /* CreateGroupMenu.swift */; };
C117F7E22B0863B3001F2BC6 /* ContactList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D631822294BAB1D00026BE7 /* ContactList.swift */; };
C117F7E22B0863B3001F2BC6 /* ContactPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D631822294BAB1D00026BE7 /* ContactPicker.swift */; };
C12436142434AB5D00B8F074 /* MLAttributedLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = C12436132434AB5D00B8F074 /* MLAttributedLabel.m */; };
C13A0BCE26E78B7B00987E29 /* ContactDetailsHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = C19C919A26E26AF000F8CC57 /* ContactDetailsHeader.swift */; };
C13EBB8E24DC685C008AADDA /* MLPrivacySettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C13EBB8D24DC685C008AADDA /* MLPrivacySettingsViewController.m */; };
Expand Down Expand Up @@ -566,8 +564,6 @@
841898AB2957DBAC00FEC77D /* RichAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RichAlert.swift; sourceTree = "<group>"; };
841B6F19297B18720074F9B7 /* AccountPicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountPicker.swift; sourceTree = "<group>"; };
841B6F1B297B3CFC0074F9B7 /* AVCallUI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AVCallUI.swift; sourceTree = "<group>"; };
841EE4282A3F46F700D3AF14 /* MLFileLogger.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MLFileLogger.m; sourceTree = "<group>"; };
841EE42A2A3F471100D3AF14 /* MLFileLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MLFileLogger.h; sourceTree = "<group>"; };
841EE42F2A426F2300D3AF14 /* MLCrashReporter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MLCrashReporter.m; path = Classes/MLCrashReporter.m; sourceTree = "<group>"; };
841EE4312A426F3D00D3AF14 /* MLCrashReporter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MLCrashReporter.h; path = Classes/MLCrashReporter.h; sourceTree = "<group>"; };
8420EA9A2915E4FE0038FF40 /* OmemoState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OmemoState.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -791,10 +787,10 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
841B28282ACF75B300BCC42B /* CocoaLumberjack in Frameworks */,
84DD7EF22B283574005AC131 /* CocoaLumberjack in Frameworks */,
BE8B63D2491B1E5582965A8F /* Pods_monalxmpp.framework in Frameworks */,
841B282A2ACF75B300BCC42B /* CocoaLumberjackSwift in Frameworks */,
841B282C2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend in Frameworks */,
84DD7EF42B283574005AC131 /* CocoaLumberjackSwift in Frameworks */,
84DD7EF62B283574005AC131 /* CocoaLumberjackSwiftLogBackend in Frameworks */,
8414AE002A7ABC4300EFFCCC /* LibMonalRustSwiftBridge in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1242,8 +1238,6 @@
541E4CBF254AA0E700FD7B28 /* MLHandler.m */,
C10490482612ED2F0054AC9E /* MLEmoji.swift */,
54A22D2426185C2900B56EAD /* MLNotificationQueue.m */,
841EE4282A3F46F700D3AF14 /* MLFileLogger.m */,
841EE42A2A3F471100D3AF14 /* MLFileLogger.h */,
84C1CD4F2A8C764D007076ED /* SwiftHelpers.swift */,
84C1CD512A8F617F007076ED /* MLStreamRedirect.m */,
84C1CD532A8F6196007076ED /* MLStreamRedirect.h */,
Expand Down Expand Up @@ -1468,7 +1462,6 @@
54E594BD2523C34B00E4172B /* MLPubSub.h in Headers */,
540BD0D224D8D1F40087A743 /* IPC.h in Headers */,
C1C839DD24F15DF800BBCF17 /* MLOMEMO.h in Headers */,
841EE42B2A3F471100D3AF14 /* MLFileLogger.h in Headers */,
26D4389123A5EB6C00242AAA /* MLConstants.h in Headers */,
C158D40025A0AB810005AA40 /* MLMucProcessor.h in Headers */,
54A22D2D26185E7E00B56EAD /* MLNotificationQueue.h in Headers */,
Expand Down Expand Up @@ -1571,9 +1564,9 @@
name = monalxmpp;
packageProductDependencies = (
8414ADFF2A7ABC4300EFFCCC /* LibMonalRustSwiftBridge */,
841B28272ACF75B300BCC42B /* CocoaLumberjack */,
841B28292ACF75B300BCC42B /* CocoaLumberjackSwift */,
841B282B2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend */,
84DD7EF12B283574005AC131 /* CocoaLumberjack */,
84DD7EF32B283574005AC131 /* CocoaLumberjackSwift */,
84DD7EF52B283574005AC131 /* CocoaLumberjackSwiftLogBackend */,
);
productName = monalxmpp;
productReference = 26CC579223A0867400ABB92A /* monalxmpp.framework */;
Expand Down Expand Up @@ -1723,7 +1716,7 @@
C1F5C7AD2777638B0001F295 /* XCRemoteSwiftPackageReference "swift-collections" */,
C1E1EC79286A025F0097EC74 /* XCRemoteSwiftPackageReference "SwiftSoup" */,
841898A82957712000FEC77D /* XCRemoteSwiftPackageReference "ViewExtractor" */,
841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */,
84DD7EF02B283574005AC131 /* XCRemoteSwiftPackageReference "cocoalumberjack" */,
);
productRefGroup = 19C28FACFE9D520D11CA2CBB /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -2019,7 +2012,7 @@
841B6F1A297B18720074F9B7 /* AccountPicker.swift in Sources */,
3D65B791272350F0005A30F4 /* SwiftuiHelpers.swift in Sources */,
C1A80DA424D9552400B99E01 /* MLChatViewHelper.m in Sources */,
C117F7E22B0863B3001F2BC6 /* ContactList.swift in Sources */,
C117F7E22B0863B3001F2BC6 /* ContactPicker.swift in Sources */,
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1D3623260D0F684500981E51 /* MonalAppDelegate.m in Sources */,
26158AF21FFA6E4500E53BDC /* MLWebViewController.m in Sources */,
Expand Down Expand Up @@ -2141,7 +2134,6 @@
26CC57A223A086AA00ABB92A /* xmpp.m in Sources */,
26CC57B423A086CC00ABB92A /* XMPPPresence.m in Sources */,
541E4CC0254AA0E700FD7B28 /* MLHandler.m in Sources */,
841EE4292A3F46F700D3AF14 /* MLFileLogger.m in Sources */,
C158D41425A0AC630005AA40 /* MLMucProcessor.m in Sources */,
C16D18362792A4AF00F869A0 /* DataLayerMigrations.m in Sources */,
54507CE5255D8C14007092F4 /* MLFiletransfer.m in Sources */,
Expand Down Expand Up @@ -4002,7 +3994,7 @@
minimumVersion = 2.0.0;
};
};
841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */ = {
84DD7EF02B283574005AC131 /* XCRemoteSwiftPackageReference "cocoalumberjack" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/cocoalumberjack/cocoalumberjack";
requirement = {
Expand Down Expand Up @@ -4038,19 +4030,19 @@
package = 841898A82957712000FEC77D /* XCRemoteSwiftPackageReference "ViewExtractor" */;
productName = ViewExtractor;
};
841B28272ACF75B300BCC42B /* CocoaLumberjack */ = {
84DD7EF12B283574005AC131 /* CocoaLumberjack */ = {
isa = XCSwiftPackageProductDependency;
package = 841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
package = 84DD7EF02B283574005AC131 /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
productName = CocoaLumberjack;
};
841B28292ACF75B300BCC42B /* CocoaLumberjackSwift */ = {
84DD7EF32B283574005AC131 /* CocoaLumberjackSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
package = 84DD7EF02B283574005AC131 /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
productName = CocoaLumberjackSwift;
};
841B282B2ACF75B300BCC42B /* CocoaLumberjackSwiftLogBackend */ = {
84DD7EF52B283574005AC131 /* CocoaLumberjackSwiftLogBackend */ = {
isa = XCSwiftPackageProductDependency;
package = 841B28262ACF75B200BCC42B /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
package = 84DD7EF02B283574005AC131 /* XCRemoteSwiftPackageReference "cocoalumberjack" */;
productName = CocoaLumberjackSwiftLogBackend;
};
C1E1EC7A286A025F0097EC74 /* SwiftSoup */ = {
Expand Down

0 comments on commit c8d1c00

Please sign in to comment.