Skip to content

Commit

Permalink
Merge pull request #51 from saledouble/master_new
Browse files Browse the repository at this point in the history
Fix #40.
  • Loading branch information
khatchad committed Jul 2, 2018
2 parents 802a52e + 53a01c6 commit 648912c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,34 @@ 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());

}

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;
}

Expand All @@ -76,6 +90,10 @@ private boolean doAction(LogInvocation logInvocation) {
private static Level getSuggestedLogLevel(LinkedList<Float> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -139,4 +144,8 @@ public void logInfo() {
+ ". Degree of Interest " + (degreeOfInterest == null ? "N/A" : degreeOfInterest.getValue()) + ". ");
}

public Action getAction() {
return this.action;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -108,4 +118,5 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
}
return null;
}

}

0 comments on commit 648912c

Please sign in to comment.