Skip to content

Commit

Permalink
#223 fix in MethodLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed May 25, 2016
1 parent e6f7a8c commit 7bacc59
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/main/java/com/jcabi/aspects/aj/MethodLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public Object wrapMethod(final ProceedingJoinPoint point) throws Throwable {
* @param annotation The annotation
* @return The result of call
* @throws Throwable If something goes wrong inside
* @checkstyle ExecutableStatementCountCheck (100 lines)
*/
private Object wrap(final ProceedingJoinPoint point, final Method method,
final Loggable annotation) throws Throwable {
Expand Down Expand Up @@ -226,22 +227,27 @@ private Object wrap(final ProceedingJoinPoint point, final Method method,
} catch (final Throwable ex) {
if (!MethodLogger.contains(annotation.ignore(), ex)
&& !ex.getClass().isAnnotationPresent(Loggable.Quiet.class)) {
final StackTraceElement trace = ex.getStackTrace()[0];
final StackTraceElement[] traces = ex.getStackTrace();
final String origin;
if (traces.length > 0) {
final StackTraceElement trace = traces[0];
origin = MethodLogger.oneText(trace);
} else {
origin = "somewhere";
}
LogHelper.log(
level,
method.getDeclaringClass(),
Logger.format(
"%s: thrown %s out of %s#%s[%d] in %[nano]s",
"%s: thrown %s out of %s in %[nano]s",
Mnemos.toText(
point,
annotation.trim(),
annotation.skipArgs(),
annotation.logThis()
),
Mnemos.toText(ex),
trace.getClassName(),
trace.getMethodName(),
trace.getLineNumber(),
origin,
System.nanoTime() - start
)
);
Expand Down Expand Up @@ -367,24 +373,31 @@ private static boolean instanceOf(final Class<?> child,
* @param trace Array of stacktrace elements
* @return The text
*/
private static String textualize(final StackTraceElement... trace) {
private static String allText(final StackTraceElement... trace) {
final StringBuilder text = new StringBuilder();
for (int pos = 0; pos < trace.length; ++pos) {
if (text.length() > 0) {
text.append(", ");
}
text.append(
String.format(
"%s#%s[%d]",
trace[pos].getClassName(),
trace[pos].getMethodName(),
trace[pos].getLineNumber()
)
);
text.append(MethodLogger.oneText(trace[pos]));
}
return text.toString();
}

/**
* Textualize a stacktrace.
* @param trace One stacktrace element
* @return The text
*/
private static String oneText(final StackTraceElement trace) {
return String.format(
"%s#%s[%d]",
trace.getClassName(),
trace.getMethodName(),
trace.getLineNumber()
);
}

/**
* Marker of a running method.
*/
Expand Down Expand Up @@ -452,7 +465,7 @@ public void monitor() {
Mnemos.toText(this.point, true, this.annotation.skipArgs()),
this.thread.getName(),
this.thread.getState(),
MethodLogger.textualize(this.thread.getStackTrace())
MethodLogger.allText(this.thread.getStackTrace())
);
this.logged.set(cycle);
}
Expand Down

0 comments on commit 7bacc59

Please sign in to comment.