diff --git a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/Action.java b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/Action.java new file mode 100644 index 00000000..116438a4 --- /dev/null +++ b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/Action.java @@ -0,0 +1,12 @@ +package edu.cuny.hunter.log.core.analysis; + +public enum Action { + NONE, + CONVERT_TO_SEVERE, + CONVERT_TO_WARNING, + CONVERT_TO_INFO, + CONVERT_TO_CONFIG, + CONVERT_TO_FINE, + CONVERT_TO_FINER, + CONVERT_TO_FINEST +} diff --git a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java index 77b3f721..6238814d 100644 --- a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java +++ b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogAnalyzer.java @@ -49,8 +49,8 @@ public void analyze() { // check whether action is needed for (LogInvocation logInvocation : this.logInvocationSet) if (this.doAction(logInvocation)) - // TODO: add more log messages here - LOGGER.info("Refactoring happens!"); + LOGGER.info("Do action: " + logInvocation.getAction() + "! The changed log expression is " + + logInvocation.getExpression()); } @@ -58,11 +58,25 @@ private boolean doAction(LogInvocation logInvocation) { Level currentLogLevel = logInvocation.getLogLevel(); Level suggestedLogLevel = getSuggestedLogLevel(boundary, logInvocation.getDegreeOfInterestValue()); - // TODO: do action here if (currentLogLevel == suggestedLogLevel) return false; if (suggestedLogLevel == null || currentLogLevel == null) return false; + + if (suggestedLogLevel == Level.FINEST) + logInvocation.setAction(Action.CONVERT_TO_FINEST); + if (suggestedLogLevel == Level.FINER) + logInvocation.setAction(Action.CONVERT_TO_FINER); + if (suggestedLogLevel == Level.FINE) + logInvocation.setAction(Action.CONVERT_TO_FINE); + if (suggestedLogLevel == Level.CONFIG) + logInvocation.setAction(Action.CONVERT_TO_CONFIG); + if (suggestedLogLevel == Level.INFO) + logInvocation.setAction(Action.CONVERT_TO_INFO); + if (suggestedLogLevel == Level.WARNING) + logInvocation.setAction(Action.CONVERT_TO_WARNING); + if (suggestedLogLevel == Level.SEVERE) + logInvocation.setAction(Action.CONVERT_TO_SEVERE); return true; } @@ -76,6 +90,10 @@ private boolean doAction(LogInvocation logInvocation) { private static Level getSuggestedLogLevel(LinkedList boundary, float DOI) { if (boundary == null) return null; + if (Float.compare(boundary.getFirst(), boundary.getLast()) == 0) { + LOGGER.info("The DOI values are all same. Cannot get valid results."); + return null; + } if (DOI >= boundary.get(0) && DOI < boundary.get(1)) return Level.FINEST; if (DOI < boundary.get(2)) diff --git a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogInvocation.java b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogInvocation.java index 95fcb92e..897f4d77 100644 --- a/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogInvocation.java +++ b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogInvocation.java @@ -41,6 +41,8 @@ public class LogInvocation { private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME); + private Action action = Action.NONE; + public LogInvocation(MethodInvocation logExpression, Level loggingLevel) { this.expression = logExpression; this.logLevel = loggingLevel; @@ -55,7 +57,10 @@ public LogInvocation(MethodInvocation logExpression, Level loggingLevel) { if (degreeOfInterest != null) { degreeOfInterestValue = degreeOfInterest.getValue(); } + } + public void setAction(Action action) { + this.action = action; } public float getDegreeOfInterestValue() { @@ -139,4 +144,8 @@ public void logInfo() { + ". Degree of Interest " + (degreeOfInterest == null ? "N/A" : degreeOfInterest.getValue()) + ". "); } + public Action getAction() { + return this.action; + } + } diff --git a/edu.cuny.hunter.log.evalution/src/edu/hunter/log/evalution/handlers/EvaluationHandler.java b/edu.cuny.hunter.log.evalution/src/edu/hunter/log/evalution/handlers/EvaluationHandler.java index d4bd4e0f..97437bd3 100644 --- a/edu.cuny.hunter.log.evalution/src/edu/hunter/log/evalution/handlers/EvaluationHandler.java +++ b/edu.cuny.hunter.log.evalution/src/edu/hunter/log/evalution/handlers/EvaluationHandler.java @@ -74,6 +74,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { CSVPrinter resultPrinter = createCSVPrinter("result.csv", new String[] { "subject raw", "log expression", "start pos", "logging level", "type FQN", "enclosing method", "DOI" }); + CSVPrinter actionPrinter = createCSVPrinter("log_actions.csv", + new String[] { "subject raw", "log expression", "start pos", "logging level", + "type FQN", "enclosing method", "action" }); // for each selected java project for (IJavaProject project : javaProjectList) { @@ -95,10 +98,17 @@ public Object execute(ExecutionEvent event) throws ExecutionException { logInvocation.getEnclosingType().getFullyQualifiedName(), Util.getMethodIdentifier(logInvocation.getEnclosingEclipseMethod()), logInvocation.getDegreeOfInterestValue()); + + actionPrinter.printRecord(project.getElementName(), logInvocation.getExpression(), + logInvocation.getStartPosition(), logInvocation.getLogLevel(), + logInvocation.getEnclosingType().getFullyQualifiedName(), + Util.getMethodIdentifier(logInvocation.getEnclosingEclipseMethod()), + logInvocation.getAction()); } } resultPrinter.close(); + actionPrinter.close(); } catch (IOException e) { LOGGER.severe("Cannot create printer."); } catch (OperationCanceledException | CoreException e) { @@ -108,4 +118,5 @@ public Object execute(ExecutionEvent event) throws ExecutionException { } return null; } + }