diff --git a/patches/react-native-file-logger+0.4.1.patch b/patches/react-native-file-logger+0.4.1.patch index 448e27ff6..e0cef917b 100644 --- a/patches/react-native-file-logger+0.4.1.patch +++ b/patches/react-native-file-logger+0.4.1.patch @@ -1,86 +1,57 @@ -diff --git a/node_modules/react-native-file-logger/ios/FileLogger.m b/node_modules/react-native-file-logger/ios/FileLogger.m -index 7ee491d..978ce4e 100644 ---- a/node_modules/react-native-file-logger/ios/FileLogger.m -+++ b/node_modules/react-native-file-logger/ios/FileLogger.m -@@ -4,6 +4,7 @@ - #import - #import - #import "FileLoggerFormatter.h" -+#import "RCTLog.h" +diff --git a/node_modules/react-native-file-logger/android/src/main/java/com/betomorrow/rnfilelogger/FileLoggerModule.java b/node_modules/react-native-file-logger/android/src/main/java/com/betomorrow/rnfilelogger/FileLoggerModule.java +index 1f3903d..b687e5b 100644 +--- a/node_modules/react-native-file-logger/android/src/main/java/com/betomorrow/rnfilelogger/FileLoggerModule.java ++++ b/node_modules/react-native-file-logger/android/src/main/java/com/betomorrow/rnfilelogger/FileLoggerModule.java +@@ -26,6 +26,7 @@ import ch.qos.logback.classic.Level; + import ch.qos.logback.classic.LoggerContext; + import ch.qos.logback.classic.encoder.PatternLayoutEncoder; + import ch.qos.logback.classic.spi.ILoggingEvent; ++import ch.qos.logback.core.Appender; + import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; + import ch.qos.logback.core.rolling.RollingFileAppender; + import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy; +@@ -37,6 +38,7 @@ public class FileLoggerModule extends ReactContextBaseJavaModule { + private static final int LOG_LEVEL_INFO = 1; + private static final int LOG_LEVEL_WARNING = 2; + private static final int LOG_LEVEL_ERROR = 3; ++ public static final String APPENDER_NAME = "FileLoggerAppender"; - enum LogLevel { - LOG_LEVEL_DEBUG, -@@ -19,6 +20,17 @@ @interface FileLogger () - @end + private static Logger logger = LoggerFactory.getLogger(FileLoggerModule.class); - @implementation FileLogger -+{ -+ NSMutableDictionary *_promisesList; -+} -+ -+- (instancetype)init -+{ -+ if ((self = [super init])) { -+ _promisesList = [[NSMutableDictionary alloc] init]; -+ } -+ return self; -+} +@@ -69,6 +71,7 @@ public class FileLoggerModule extends ReactContextBaseJavaModule { - RCT_EXPORT_MODULE() + RollingFileAppender rollingFileAppender = new RollingFileAppender<>(); + rollingFileAppender.setContext(loggerContext); ++ rollingFileAppender.setName(APPENDER_NAME); + rollingFileAppender.setFile(logsDirectory + "/" + logPrefix + "-latest.log"); -@@ -101,6 +113,8 @@ - (dispatch_queue_t)methodQueue { - [composeViewController setMessageBody:body isHTML:NO]; - } - -+ _promisesList[RCTKeyForInstance(composeViewController)] = @[resolve, reject]; -+ - NSArray* logFiles = self.fileLogger.logFileManager.sortedLogFilePaths; - for (NSString* logFile in logFiles) { - NSData* data = [NSData dataWithContentsOfFile:logFile]; -@@ -112,13 +126,44 @@ - (dispatch_queue_t)methodQueue { - presentingViewController = presentingViewController.presentedViewController; + if (dailyRolling) { +@@ -108,15 +111,24 @@ public class FileLoggerModule extends ReactContextBaseJavaModule { + rollingFileAppender.setEncoder(encoder); + rollingFileAppender.start(); + +- ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); +- root.setLevel(Level.DEBUG); +- root.detachAndStopAllAppenders(); +- root.addAppender(rollingFileAppender); ++ this.renewAppender(rollingFileAppender); + + configureOptions = options; + promise.resolve(null); } - [presentingViewController presentViewController:composeViewController animated:YES completion:nil]; -- -- resolve(nil); - } - - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { -+ NSString *key = RCTKeyForInstance(controller); -+ -+ NSMutableArray *promise = _promisesList[key]; -+ if (promise) { -+ RCTPromiseResolveBlock resolve = promise[0]; -+ RCTPromiseRejectBlock reject = promise[1]; -+ switch (result) { -+ case MFMailComposeResultSent: -+ resolve(@"sent"); -+ break; -+ case MFMailComposeResultSaved: -+ resolve(@"saved"); -+ break; -+ case MFMailComposeResultCancelled: -+ resolve(@"cancelled"); -+ break; -+ case MFMailComposeResultFailed: -+ reject(@"failed", error.localizedDescription, nil); -+ break; -+ default: -+ reject(@"error", @"Unknown error", nil); -+ break; ++ private void renewAppender(Appender appender) { ++ ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); ++ root.setLevel(Level.DEBUG); ++ // Stopping the previous appender to release any resources it might be holding (file handles) and to ensure a clean shutdown. ++ Appender previousFileLoggerAppender = root.getAppender(APPENDER_NAME); ++ if (previousFileLoggerAppender != null) { ++ previousFileLoggerAppender.stop(); ++ root.detachAppender(APPENDER_NAME); + } -+ [_promisesList removeObjectForKey:key]; -+ } else { -+ RCTLogWarn(@"No promise registered for mail: %@", controller.title); ++ root.addAppender(appender); + } -+ - [controller dismissViewControllerAnimated:YES completion:nil]; - } - -+static NSString *RCTKeyForInstance(id instance) -+{ -+ return [NSString stringWithFormat:@"%p", instance]; -+} + - @end - + @ReactMethod + public void write(int level, String str) { + switch (level) { diff --git a/src/App.js b/src/App.js index cfd7e12ee..68f3428ef 100644 --- a/src/App.js +++ b/src/App.js @@ -62,12 +62,9 @@ import LauncherView from '/screens/konnectors/LauncherView' import { useShareFiles } from '/app/domain/osReceive/services/shareFilesService' import { ClouderyOffer } from '/app/view/IAP/ClouderyOffer' import { useDimensions } from '/libs/dimensions' -// Temporarily disable FileLogger until we fix issue https://github.com/BeTomorrow/react-native-file-logger/issues/64 -/* import { configureFileLogger } from '/app/domain/logger/fileLogger' configureFileLogger() -//*/ // Polyfill needed for cozy-client connection if (!global.btoa) {