2024-01-15 13:27:35 +00:00
|
|
|
#import "LogManager.h"
|
|
|
|
#import "React/RCTBridge.h"
|
|
|
|
#import "React/RCTEventDispatcher.h"
|
|
|
|
#import "Statusgo.h"
|
|
|
|
#import "Utils.h"
|
|
|
|
#import "SSZipArchive.h"
|
2024-11-19 10:50:01 +00:00
|
|
|
#import "StatusBackendClient.h"
|
2024-01-15 13:27:35 +00:00
|
|
|
|
|
|
|
@implementation LogManager
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
|
|
|
|
#pragma mark - SendLogs method
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
|
|
|
|
jsLogs:(NSString *)jsLogs
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2024-11-04 12:40:36 +00:00
|
|
|
NSLog(@"SendLogs() method called");
|
2024-01-15 13:27:35 +00:00
|
|
|
#endif
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSError *error = nil;
|
2024-11-19 10:50:01 +00:00
|
|
|
NSURL *rootUrl =[Utils getRootUrl];
|
2024-01-15 13:27:35 +00:00
|
|
|
|
|
|
|
NSURL *zipFile = [rootUrl URLByAppendingPathComponent:@"logs.zip"];
|
|
|
|
[fileManager removeItemAtPath:zipFile.path error:nil];
|
|
|
|
|
|
|
|
NSURL *logsFolderName = [rootUrl URLByAppendingPathComponent:@"logs"];
|
|
|
|
|
|
|
|
if (![fileManager fileExistsAtPath:logsFolderName.path])
|
|
|
|
[fileManager createDirectoryAtPath:logsFolderName.path withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
|
|
|
|
|
NSURL *dbFile = [logsFolderName URLByAppendingPathComponent:@"db.json"];
|
|
|
|
NSURL *jsLogsFile = [logsFolderName URLByAppendingPathComponent:@"Status.log"];
|
|
|
|
|
|
|
|
NSURL *mainGethLogsFile = [rootUrl URLByAppendingPathComponent:@"geth.log"];
|
|
|
|
NSURL *mainLogsFile = [logsFolderName URLByAppendingPathComponent:@"geth.log"];
|
|
|
|
|
2024-09-17 03:28:38 +00:00
|
|
|
NSURL *requestsLogFile = [rootUrl URLByAppendingPathComponent:@"requests.log"];
|
|
|
|
|
2024-01-15 13:27:35 +00:00
|
|
|
[dbJson writeToFile:dbFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
|
|
[jsLogs writeToFile:jsLogsFile.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
|
|
|
|
|
|
|
[fileManager copyItemAtPath:mainGethLogsFile.path toPath:mainLogsFile.path error:nil];
|
2024-09-17 03:28:38 +00:00
|
|
|
|
|
|
|
if ([fileManager fileExistsAtPath:requestsLogFile.path]) {
|
|
|
|
[fileManager copyItemAtPath:requestsLogFile.path toPath:[logsFolderName URLByAppendingPathComponent:@"requests.log"].path error:nil];
|
|
|
|
}
|
2024-01-15 13:27:35 +00:00
|
|
|
|
|
|
|
[SSZipArchive createZipFileAtPath:zipFile.path withContentsOfDirectory:logsFolderName.path];
|
|
|
|
[fileManager removeItemAtPath:logsFolderName.path error:nil];
|
|
|
|
|
|
|
|
callback(@[zipFile.absoluteString]);
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(initLogging:(BOOL)enabled
|
|
|
|
mobileSystem:(BOOL)mobileSystem
|
|
|
|
logLevel:(NSString *)logLevel
|
2024-09-17 03:28:38 +00:00
|
|
|
logRequestGo:(BOOL)logRequestGo
|
2024-01-15 13:27:35 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback)
|
|
|
|
{
|
|
|
|
NSString *logDirectory = [self logFileDirectory];
|
|
|
|
NSString *logFilePath = [logDirectory stringByAppendingPathComponent:@"geth.log"];
|
2024-09-17 03:28:38 +00:00
|
|
|
NSString *logRequestFilePath = [logDirectory stringByAppendingPathComponent:@"requests.log"];
|
2024-01-15 13:27:35 +00:00
|
|
|
|
2024-11-19 10:50:01 +00:00
|
|
|
NSDictionary *config = @{
|
|
|
|
@"Enabled": @(enabled),
|
|
|
|
@"MobileSystem": @(mobileSystem),
|
|
|
|
@"Level": logLevel,
|
|
|
|
@"File": logFilePath,
|
|
|
|
@"LogRequestGo": @(logRequestGo),
|
|
|
|
@"LogRequestFile": logRequestFilePath
|
|
|
|
};
|
|
|
|
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:config options:0 error:&error];
|
|
|
|
|
2024-01-15 13:27:35 +00:00
|
|
|
if (error) {
|
2024-11-19 10:50:01 +00:00
|
|
|
NSLog(@"Error creating JSON: %@", [error localizedDescription]);
|
2024-01-15 13:27:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-11-19 10:50:01 +00:00
|
|
|
|
|
|
|
NSString *configJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
2024-01-15 13:27:35 +00:00
|
|
|
|
2024-11-19 10:50:01 +00:00
|
|
|
[StatusBackendClient executeStatusGoRequestWithCallback:@"InitLogging"
|
|
|
|
body:configJson
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoInitLogging(configJson);
|
|
|
|
}
|
|
|
|
callback:callback];
|
2024-01-15 13:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(logFileDirectory) {
|
2024-11-19 10:50:01 +00:00
|
|
|
NSURL *rootUrl = [Utils getRootUrl];
|
2024-01-15 13:27:35 +00:00
|
|
|
return rootUrl.path;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|