Skip to content
Snippets Groups Projects
Commit ac9030d2 authored by kfilippopolitis's avatar kfilippopolitis
Browse files

Update logs on /experiments/runAlgorithm to output the parameters of the algorithm

parent 2a8732d7
No related branches found
No related tags found
1 merge request!16Dev/251 refactor logging
This diff is collapsed.
......@@ -3,34 +3,38 @@ package eu.hbp.mip.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;
public class Logging {
private static final Logger LOGGER = LoggerFactory.getLogger(Logging.class);
private static Integer maxEndpointLen = 5;
private static Integer maxInfoLen = 5;
public static void LogUserAction(String userName, String endpoint, String actionInfo) {
maxEndpointLen = (maxEndpointLen < userName.length() ? userName.length() : maxEndpointLen);
maxInfoLen = (maxInfoLen < endpoint.length() ? endpoint.length() : maxInfoLen);
String endpointSpacing = String.format("%" + (maxEndpointLen - userName.length() + 2) + "s", "");
String infoSpacing = String.format("%" + (maxInfoLen - endpoint.length() + 2) + "s", "");
LOGGER.info(" User -> " + userName
+ endpointSpacing
+ ", Endpoint -> " + endpoint
+ infoSpacing
+ ", Info -> " + actionInfo);
LOGGER.info(" User -> " + userName + " ,"
+ calculateAdditionalSpacing(userName.length(), 8)
+ "Endpoint -> " + endpoint + " ,"
+ calculateAdditionalSpacing(endpoint.length(), 32)
+ "Info -> " + actionInfo);
}
// Used from Threads because threads can't get userName.
public static void LogExperimentAction(String experimentName, String actionInfo) {
public static void LogExperimentAction(String experimentName, UUID experimentId, String actionInfo) {
LOGGER.info(" Experiment -> " + experimentName
+ " , Info -> " + actionInfo);
+ "(" + experimentId + ") ,"
+ calculateAdditionalSpacing(experimentName.length() + experimentId.toString().length() + 2, 20)
+ "Info -> " + actionInfo);
}
// Used when a user is not authorised yet
public static void LogAction(String actionName, String actionIdInfo) {
LOGGER.info(" Action -> " + actionName
+ " , Info -> " + actionIdInfo);
LOGGER.info(" Action -> " + actionName + " ,"
+ calculateAdditionalSpacing(actionName.length() + 2, 20)
+ "Info -> " + actionIdInfo);
}
// Calculates the spacing that is needed to create consistent logs.
private static String calculateAdditionalSpacing(Integer currentLen, Integer maxLen) {
int additionalSpacing = (maxLen > currentLen ? maxLen - currentLen + 2 : 2);
return String.format("%" + additionalSpacing + "s", "");
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment