Skip to content

Commit

Permalink
Implement deleteLogFiles() on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Treny committed Jul 17, 2020
1 parent 9ef27eb commit 5c04853
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class FileLoggerModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;
private String logsDirectory;
private ReadableMap configureOptions;

public FileLoggerModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -101,8 +102,10 @@ public void configure(ReadableMap options, Promise promise) {

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);

configureOptions = options;
promise.resolve(null);
}

Expand Down Expand Up @@ -139,6 +142,22 @@ public void getLogFilePaths(Promise promise) {
}
}

@ReactMethod
public void deleteLogFiles(Promise promise) {
try {
for (File file: getLogFiles()) {
file.delete();
}
if (configureOptions != null) {
configure(configureOptions, promise);
} else {
promise.resolve(null);
}
} catch (Exception e) {
promise.reject(e);
}
}

@ReactMethod
public void sendLogFilesByEmail(ReadableMap options, Promise promise) {
try {
Expand Down

0 comments on commit 5c04853

Please sign in to comment.