diff --git a/libs/utils/src/main/java/com/akto/log/LoggerMaker.java b/libs/utils/src/main/java/com/akto/log/LoggerMaker.java index cae77c8cb0..664855a6d2 100644 --- a/libs/utils/src/main/java/com/akto/log/LoggerMaker.java +++ b/libs/utils/src/main/java/com/akto/log/LoggerMaker.java @@ -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; @@ -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){ } @@ -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) { @@ -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());