Skip to content

Commit

Permalink
improve variable naming in ConsoleLogDumpApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardWarburton committed Jan 9, 2015
1 parent 41a895c commit 291928d
Showing 1 changed file with 23 additions and 25 deletions.
Expand Up @@ -57,64 +57,62 @@ public void setLogLocation(File logLocation) {
} }


public void run() { public void run() {

final PrintStream err = error.stream(); final PrintStream err = error.stream();

if (!logLocation.exists() || !logLocation.canRead()) { if (!logLocation.exists() || !logLocation.canRead()) {
err.println("Unable to find log file at: " + logLocation); err.println("Unable to find log file at: " + logLocation);
return; return;
} }


final PrintStream out = output.stream(); final PrintStream out = output.stream();
out.println("Printing text represantation for: " + logLocation.getAbsolutePath()); out.println("Printing text representation for: " + logLocation.getAbsolutePath());


Monitor.consumeFile(new FileLogSource(logLocation), new LogEventListener() { Monitor.consumeFile(new FileLogSource(logLocation), new LogEventListener() {
int indent; int indent;
long traceidx; long traceidx;
long errCount; long errCount;
Map<Long, ClassMethod> methodNames = new HashMap<>(); Map<Long, BoundMethod> methodNames = new HashMap<>();


@Override @Override
public void handle(Method m) { public void handle(Method method) {
ClassMethod cm = new ClassMethod(m.getClassName(), m.getMethodName()); BoundMethod boundMethod = new BoundMethod(method.getClassName(), method.getMethodName());
out.printf("Method : %d -> %s.%s\n", m.getMethodId(), m.getClassName(), m.getMethodName()); out.printf("Method : %d -> %s.%s\n", method.getMethodId(), method.getClassName(), method.getMethodName());
methodNames.put(m.getMethodId(), cm); methodNames.put(method.getMethodId(), boundMethod);
} }


@Override @Override
public void handle(StackFrame sf) { public void handle(StackFrame stackFrame) {
indent--; indent--;
long methodId = sf.getMethodId(); long methodId = stackFrame.getMethodId();
ClassMethod cm = methodNames.get(methodId); BoundMethod boundMethod = methodNames.get(methodId);
if (methodId == 0) { // null method if (methodId == 0) { // null method
errCount++; errCount++;
out.print("StackFrame: "); out.print("StackFrame: ");
indent(out); indent(out);
out.printf("%d @ %s\n", methodId, sf.getLineNumber()); out.printf("%d @ %s\n", methodId, stackFrame.getLineNumber());
} else if (cm == null) { } else if (boundMethod == null) {
out.print("StackFrame: "); out.print("StackFrame: ");
indent(out); indent(out);
out.printf("%d @ %s\n", methodId, sf.getLineNumber()); out.printf("%d @ %s\n", methodId, stackFrame.getLineNumber());
} else { } else {
out.print("StackFrame: "); out.print("StackFrame: ");
indent(out); indent(out);
out.printf("%s::%s @ %s\n", cm.cName, cm.mName, sf.getLineNumber()); out.printf("%s::%s @ %s\n", boundMethod.className, boundMethod.methodName, stackFrame.getLineNumber());
} }
} }


private void indent(final PrintStream out) { private void indent(final PrintStream out) {
for (int i = 0; i < indent; i++) for (int i = 0; i < indent; i++)
out.print(" "); out.print(' ');
} }


@Override @Override
public void handle(TraceStart ts) { public void handle(TraceStart traceStart) {
int frames = ts.getNumberOfFrames(); int frames = traceStart.getNumberOfFrames();
if (frames <= 0) { if (frames <= 0) {
out.printf("TraceStart: [%d] tid=%d,frames=%d\n", traceidx, ts.getThreadId(), frames); out.printf("TraceStart: [%d] tid=%d,frames=%d\n", traceidx, traceStart.getThreadId(), frames);
errCount++; errCount++;
} else { } else {
out.printf("TraceStartL [%d] tid=%d,frames=%d\n", traceidx, ts.getThreadId(), frames); out.printf("TraceStartL [%d] tid=%d,frames=%d\n", traceidx, traceStart.getThreadId(), frames);
} }
indent = frames; indent = frames;
traceidx++; traceidx++;
Expand All @@ -127,12 +125,12 @@ public void endOfLog() {
}); });
} }


static class ClassMethod { private static class BoundMethod {
final String cName, mName; private final String className, methodName;


public ClassMethod(String className, String methodName) { public BoundMethod(String className, String methodName) {
this.cName = className; this.className = className;
this.mName = methodName; this.methodName = methodName;
} }
} }


Expand Down

0 comments on commit 291928d

Please sign in to comment.