Skip to content

Commit

Permalink
refs : #18514 : Handled Exceptions and optimized File Writer functions
Browse files Browse the repository at this point in the history
  • Loading branch information
remiges-surajg committed Jun 3, 2024
1 parent df7a133 commit 419b5c3
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 140 deletions.
39 changes: 39 additions & 0 deletions logharbour/logharbour.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.remiges.logharbour.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -17,11 +16,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.remiges.logharbour.model.ChangeDetails;
import com.remiges.logharbour.model.ChangeInfo;
import com.remiges.logharbour.model.GetLogsResponse;
import com.remiges.logharbour.model.LogEntry;
import com.remiges.logharbour.model.LogEntry.LogPriority;
import com.remiges.logharbour.model.LogEntry.Status;
import com.remiges.logharbour.model.LoggerContext;
import com.remiges.logharbour.model.LogharbourRequestBo;
import com.remiges.logharbour.model.LoginUser;
import com.remiges.logharbour.service.LHLoggerTestService;
Expand Down Expand Up @@ -160,7 +157,7 @@ public String postActivityLogs() throws Exception {
logharbour.getLoggerContext(LogPriority.INFO), logharbour.getKafkaTopic(),
new ObjectMapper());

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

lhLogger.logActivity("Log Activitiy Test", loginUser);
Expand All @@ -172,7 +169,7 @@ public String postActivityLogs() throws Exception {
@PostMapping("/changes-log")
public String postChangeLogs() throws Exception {

LoginUser loginUser = new LoginUser("3", "Shivendra", "2121");
LoginUser loginUser = new LoginUser("4", "Shivendra", "2121");

ChangeInfo changeInfo = new ChangeInfo();
changeInfo.setEntity(loginUser.getName());
Expand All @@ -188,8 +185,8 @@ public String postChangeLogs() throws Exception {
logharbour.getLoggerContext(LogPriority.INFO), logharbour.getKafkaTopic(),
new ObjectMapper());

lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.INFO, "User2",
"Update", LHLogger.class.getName().toString(), "Instance Id", Status.SUCCESS, "",
lhLogger.setLogDetails("Kra", "Linux System", "Adhaar Kyc Module", LogPriority.DEBUG1, "User3",
"Update", LHLogger.class.getName().toString(), "instance3", Status.SUCCESS, "",
"127.0.0");

lhLogger.logDataChange("Log Data change", changeInfo);
Expand All @@ -207,7 +204,7 @@ public String postDebugLogs() throws Exception {
logharbour.getLoggerContext(LogPriority.INFO), logharbour.getKafkaTopic(),
new ObjectMapper());

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

lhLogger.logDebug("Log Activitiy Test", loginUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public ResponseEntity<String> handleIllegalArgumentException(IllegalArgumentExce
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(LogException.class)
public ResponseEntity<String> handleLogException(LogException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}

}
117 changes: 56 additions & 61 deletions logharbour/src/main/java/com/remiges/logharbour/model/LogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,87 +61,82 @@ public LogEntry(String app, String system, String module, LogPriority pri, Strin
this.data = data;
}

// public enum LogPriority {
// DEBUG2,
// DEBUG1,
// DEBUG0,
// INFO,
// WARN,
// ERR,
// CRIT,
// SEC
// }

/**
* Enum representing different log types.
*/
public enum LogType {
CHANGE,
ACTIVITY,
DEBUG,
UNKNOWN;
}

/**
* Enum representing Failure or Success status.
*/
public enum Status {
FAILURE,
SUCCESS
}

/**
* Enum representing different levels of log priorities.
*/
public enum LogPriority {
DEBUG2(1, "Debug2"),
DEBUG1(2, "Debug1"),
DEBUG0(3, "Debug0"),
INFO(4, "Info"),
WARN(5, "Warn"),
ERR(6, "Err"),
CRIT(7, "Crit"),
SEC(8, "Sec"),
UNKNOWN(0, "Unknown");

private final int level;
private final String name;

/**
* Constructor for LogPriorityLevels.
*
* @param level the numerical level of the log priority
* @param name the name of the log priority
* Enum representing different levels of log priorities.
*/
LogPriority(int level, String name) {
this.level = level;
this.name = name;
}
public enum LogPriority {
DEBUG2(1, "Debug2"),
DEBUG1(2, "Debug1"),
DEBUG0(3, "Debug0"),
INFO(4, "Info"),
WARN(5, "Warn"),
ERR(6, "Err"),
CRIT(7, "Crit"),
SEC(8, "Sec"),
UNKNOWN(0, "Unknown");

private final int level;
private final String name;

/**
* Constructor for LogPriorityLevels.
*
* @param level the numerical level of the log priority
* @param name the name of the log priority
*/
LogPriority(int level, String name) {
this.level = level;
this.name = name;
}

@JsonValue
public String getName() {
return name;
}
@JsonValue
public String getName() {
return name;
}

/**
* Creates a LogPriorityLevels instance from the provided name.
*
* @param name the name of the log priority level
* @return the corresponding LogPriorityLevels instance, or UNKNOWN if no match is found
*/
@JsonCreator
public static LogPriority fromName(String name) {
for (LogPriority priority : LogPriority.values()) {
if (priority.name.equalsIgnoreCase(name)) {
return priority;
/**
* Creates a LogPriorityLevels instance from the provided name.
*
* @param name the name of the log priority level
* @return the corresponding LogPriorityLevels instance, or UNKNOWN if no match
* is found
*/
@JsonCreator
public static LogPriority fromName(String name) {
for (LogPriority priority : LogPriority.values()) {
if (priority.name.equalsIgnoreCase(name)) {
return priority;
}
}
return UNKNOWN;
}
return UNKNOWN;
}

public int getLevel() {
return level;
}
public int getLevel() {
return level;
}

@Override
public String toString() {
return name;
@Override
public String toString() {
return name;
}
}
}


}
Loading

0 comments on commit 419b5c3

Please sign in to comment.