Skip to content

Commit

Permalink
refs : #18514 : Optimized log priority based logging
Browse files Browse the repository at this point in the history
  • Loading branch information
remiges-surajg committed May 31, 2024
1 parent 4ef87bf commit abb557f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public String postActivityLogs() throws Exception {
logharbour.getLoggerContext(LogPriorityLevels.INFO), logharbour.getKafkaTopic(),
new ObjectMapper());

lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.INFO, "User1",
lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.DEBUG1, "User1",
"Insert", LHLogger.class.getName().toString(), "Instance Id", Status.SUCCESS, "", "127.1.2.1");

lhLogger.logActivity("Log Activitiy Test", loginUser);
Expand Down Expand Up @@ -192,7 +192,7 @@ public String postChangeLogs() throws Exception {
logharbour.getLoggerContext(LogPriorityLevels.INFO), logharbour.getKafkaTopic(),
new ObjectMapper());

lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.INFO, "User2",
lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.DEBUG0, "User2",
"Changing", LHLoggerController.class.getName().toString(), "Instance Id", Status.SUCCESS, "",
"127.6.2.1");

Expand All @@ -211,7 +211,7 @@ public String postDebugLogs() throws Exception {
logharbour.getLoggerContext(LogPriorityLevels.INFO), logharbour.getKafkaTopic(),
new ObjectMapper());

lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.INFO, "Kra User",
lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.DEBUG2, "Kra User",
"Insert", LHLogger.class.getName().toString(), "Instance Id", Status.SUCCESS, "", "187.0.2.1");

lhLogger.logDebug("Log Activitiy Test", loginUser);
Expand Down

This file was deleted.

17 changes: 11 additions & 6 deletions logharbour/src/main/java/com/remiges/logharbour/util/LHLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void log(String logMessage) throws LogException {
*/
public boolean shouldLog(LogPriority priority) {
synchronized (loggerContext) {
return priority.ordinal() <= loggerContext.getMinLogPriority().ordinal();
return priority.ordinal() >= loggerContext.getMinLogPriority().ordinal();
}
}

Expand All @@ -193,8 +193,10 @@ public void logActivity(String message, Object data) throws JsonProcessingExcept
} else {
entry = newLogEntry(message, null);
}
entry.setLogType(LogType.ACTIVITY);
log(objectMapper.writeValueAsString(entry));
if (shouldLog(entry.getPri())) {
entry.setLogType(LogType.ACTIVITY);
log(objectMapper.writeValueAsString(entry));
}
}

/**
Expand All @@ -218,8 +220,9 @@ public void logDataChange(String message, ChangeInfo data) throws JsonProcessing

LogEntry entry = newLogEntry(message, logData);
entry.setLogType(LogEntry.LogType.CHANGE);

log(objectMapper.writeValueAsString(entry));
if (shouldLog(entry.getPri())) {
log(objectMapper.writeValueAsString(entry));
}

}

Expand Down Expand Up @@ -260,7 +263,9 @@ public void logDebug(String message, Object data) throws JsonProcessingException
logData.setDebugData(debugInfo);
entry = newLogEntry(message, logData);
entry.setLogType(LogEntry.LogType.DEBUG);
log(objectMapper.writeValueAsString(entry));
if (shouldLog(entry.getPri())) {
log(objectMapper.writeValueAsString(entry));
}
}
}

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion logharbour/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kafka:

elasticsearch:
username: elastic
password: jWddl*kneXQ_wEGVextg
password: K*d695i1uM3fRhnQ59G2

host: localhost
port: 9200
Expand Down

0 comments on commit abb557f

Please sign in to comment.