Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async logs #1773

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions libs/utils/src/main/java/com/akto/log/LoggerMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -140,7 +141,7 @@ protected String basicError(String err, LogDb db) {
}
logger.error(err);
try{
insert(err, "error", db);
asyncInsert(err, "error", db, Context.accountId.get());
} catch (Exception e){

}
Expand Down Expand Up @@ -187,11 +188,7 @@ public void infoAndAddToDb(String info, LogDb db) {
String accountId = Context.accountId.get() != null ? Context.accountId.get().toString() : "NA";
String infoMessage = "acc: " + accountId + ", " + info;
logger.info(infoMessage);
try{
insert(infoMessage, "info",db);
} catch (Exception e){

}
asyncInsert(infoMessage, "info", db, Context.accountId.get());
}

public void errorAndAddToDb(String err) {
Expand All @@ -213,7 +210,15 @@ private Boolean checkUpdate(){
}
return true;
}



private void asyncInsert(String text, String key, LogDb db, int accountId) {
CompletableFuture.runAsync(() -> {
Context.accountId.set(accountId);
insert(text, key, db);
});
}

private void insert(String info, String key, LogDb db) {
String text = aClass + " : " + info;
Log log = new Log(text, key, Context.now());
Expand Down
Loading