From b554abc5b3f85b654061b82b58c5247228abeb27 Mon Sep 17 00:00:00 2001 From: Yiming Date: Sun, 24 Jun 2018 19:47:01 -0400 Subject: [PATCH 1/4] add action --- .../edu/cuny/hunter/log/core/analysis/Action.java | 12 ++++++++++++ .../cuny/hunter/log/core/analysis/LogInvocation.java | 12 ++++++++++++ .../log/evalution/handlers/EvaluationHandler.java | 11 +++++++++++ 3 files changed, 35 insertions(+) create mode 100644 edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/Action.java 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/LogInvocation.java b/edu.cuny.hunter.log.core/src/edu/cuny/hunter/log/core/analysis/LogInvocation.java index 95fcb92e..2cd44151 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 @@ -40,6 +40,8 @@ public class LogInvocation { private float degreeOfInterestValue; private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME); + + private Action action; public LogInvocation(MethodInvocation logExpression, Level loggingLevel) { this.expression = logExpression; @@ -55,9 +57,15 @@ public LogInvocation(MethodInvocation logExpression, Level loggingLevel) { if (degreeOfInterest != null) { degreeOfInterestValue = degreeOfInterest.getValue(); } + + setAction(degreeOfInterestValue); } + private void setAction(float degreeOfInterestValue2) { + // TODO set action + } + public float getDegreeOfInterestValue() { return degreeOfInterestValue; } @@ -138,5 +146,9 @@ public void logInfo() { LOGGER.info("Find a log expression." + this.getExpression().toString() + " The logging level: " + getLogLevel() + ". 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..f7b2c8ed 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", "DOI", "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; } + } From 12abfa92999ec6c85b59d262428f2d5c455b070a Mon Sep 17 00:00:00 2001 From: Yiming Date: Wed, 27 Jun 2018 20:13:17 -0400 Subject: [PATCH 2/4] set action --- .../hunter/log/core/analysis/LogAnalyzer.java | 24 ++++++++++++++++--- .../log/core/analysis/LogInvocation.java | 11 ++++----- 2 files changed, 25 insertions(+), 10 deletions(-) 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 2cd44151..fbdc9f18 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 @@ -40,7 +40,7 @@ public class LogInvocation { private float degreeOfInterestValue; private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME); - + private Action action; public LogInvocation(MethodInvocation logExpression, Level loggingLevel) { @@ -57,13 +57,10 @@ public LogInvocation(MethodInvocation logExpression, Level loggingLevel) { if (degreeOfInterest != null) { degreeOfInterestValue = degreeOfInterest.getValue(); } - - setAction(degreeOfInterestValue); - } - private void setAction(float degreeOfInterestValue2) { - // TODO set action + public void setAction(Action action) { + this.action = action; } public float getDegreeOfInterestValue() { @@ -146,7 +143,7 @@ public void logInfo() { LOGGER.info("Find a log expression." + this.getExpression().toString() + " The logging level: " + getLogLevel() + ". Degree of Interest " + (degreeOfInterest == null ? "N/A" : degreeOfInterest.getValue()) + ". "); } - + public Action getAction() { return this.action; } From 2779ddff201389388c44aa5fa4e181d73e4d7bc8 Mon Sep 17 00:00:00 2001 From: Yiming Date: Wed, 27 Jun 2018 20:13:32 -0400 Subject: [PATCH 3/4] fix printer --- .../edu/hunter/log/evalution/handlers/EvaluationHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f7b2c8ed..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 @@ -76,7 +76,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { "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", "DOI", "action" }); + "type FQN", "enclosing method", "action" }); // for each selected java project for (IJavaProject project : javaProjectList) { From 53a01c665a96290e22dcb7fa575123f5b19b635d Mon Sep 17 00:00:00 2001 From: Yiming Date: Wed, 27 Jun 2018 20:21:45 -0400 Subject: [PATCH 4/4] initialize action --- .../src/edu/cuny/hunter/log/core/analysis/LogInvocation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fbdc9f18..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,7 +41,7 @@ public class LogInvocation { private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME); - private Action action; + private Action action = Action.NONE; public LogInvocation(MethodInvocation logExpression, Level loggingLevel) { this.expression = logExpression;