Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log exception backtrace in one log record #3403

Merged
merged 2 commits into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/exceptions/RaiseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void preRaise(ThreadContext context, StackTraceElement[] javaTrace) {

exception.prepareIntegratedBacktrace(context, javaTrace);

if (RubyInstanceConfig.LOG_EXCEPTIONS) TraceType.dumpException(exception);
if (RubyInstanceConfig.LOG_EXCEPTIONS) TraceType.logException(exception);
}

private void preRaise(ThreadContext context, IRubyObject backtrace) {
Expand All @@ -227,7 +227,7 @@ private void preRaise(ThreadContext context, IRubyObject backtrace) {
setStackTrace(RaiseException.javaTraceFromRubyTrace(exception.getBacktraceElements()));
}

if (RubyInstanceConfig.LOG_EXCEPTIONS) TraceType.dumpException(exception);
if (RubyInstanceConfig.LOG_EXCEPTIONS) TraceType.logException(exception);
}

private static void doCallEventHook(final ThreadContext context) {
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,9 @@ public IRubyObject createCallerBacktrace(int level, Integer length, StackTraceEl
RubyString str = RubyString.newString(runtime, trace[i - level].mriStyleString());
newTrace.append(str);
}
if (RubyInstanceConfig.LOG_CALLERS) TraceType.dumpCaller(newTrace);

if (RubyInstanceConfig.LOG_CALLERS) TraceType.logCaller(newTrace);

return newTrace;
}

Expand Down Expand Up @@ -842,9 +842,9 @@ private RubyStackTraceElement[] getTraceSubset(int level, Integer length, StackT
if (traceLength < 0) return null;

trace = Arrays.copyOfRange(trace, level, level + traceLength);
if (RubyInstanceConfig.LOG_CALLERS) TraceType.dumpCaller(trace);

if (RubyInstanceConfig.LOG_CALLERS) TraceType.logCaller(trace);

return trace;
}

Expand All @@ -863,7 +863,7 @@ public RubyStackTraceElement[] createWarningBacktrace(Ruby runtime) {

RubyStackTraceElement[] trace = gatherCallerBacktrace();

if (RubyInstanceConfig.LOG_WARNINGS) TraceType.dumpWarning(trace);
if (RubyInstanceConfig.LOG_WARNINGS) TraceType.logWarning(trace);

return trace;
}
Expand Down
48 changes: 40 additions & 8 deletions core/src/main/java/org/jruby/runtime/backtrace/TraceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,63 @@ public String printBacktrace(RubyException exception, boolean console) {
}

public static void logBacktrace(RubyStackTraceElement[] trace) {
LOG.info("Backtrace generated:");
for (RubyStackTraceElement element : trace) {
LOG.info(" " + element.getFileName() + ":" + element.getLineNumber() + " in " + element.getMethodName());
if (trace == null) trace = RubyStackTraceElement.EMPTY_ARRAY;
final StringBuilder buffer = new StringBuilder(128);
renderBacktraceJRuby(trace, buffer, false);
final int len = buffer.length();
if ( len > 0 && buffer.charAt(len - 1) == '\n' ) {
buffer.setLength(len - 1); // remove last '\n'
}
LOG.info("Backtrace generated:\n{}", buffer);
}

public static void dumpException(RubyException exception) {
public static void logException(RubyException exception) {
LOG.info("Exception raised: {} : {}", exception.getMetaClass(), exception);
}

/**
* @deprecated use {@link #logException(org.jruby.RubyException)}
*/
public static void dumpException(RubyException exception) {
logException(exception);
}

public static void dumpBacktrace(RubyException exception) {
Ruby runtime = exception.getRuntime();
System.err.println("Backtrace generated:\n" + Format.JRUBY.printBacktrace(exception, runtime.getPosix().isatty(FileDescriptor.err)));
System.err.println("Backtrace generated:\n" + printBacktraceJRuby(exception, runtime.getPosix().isatty(FileDescriptor.err)));
}

public static void logCaller(RubyArray trace) {
LOG.info("Caller backtrace generated:\n{}", trace);
}

/**
* @deprecated use {@link #logCaller(org.jruby.RubyArray)}
*/
public static void dumpCaller(RubyArray trace) {
LOG.info("Caller backtrace generated:\n" + trace);
logCaller(trace);
}

public static void logCaller(RubyStackTraceElement[] trace) {
LOG.info("Caller backtrace generated:\n{}", Arrays.toString(trace));
}

/**
* @deprecated use {@link #logCaller(org.jruby.runtime.backtrace.RubyStackTraceElement[]) }
*/
public static void dumpCaller(RubyStackTraceElement[] trace) {
LOG.info("Caller backtrace generated:\n" + Arrays.toString(trace));
logCaller(trace);
}

public static void logWarning(RubyStackTraceElement[] trace) {
LOG.info("Warning backtrace generated:\n{}", Arrays.toString(trace));
}

/**
* @deprecated use {@link #logWarning(org.jruby.runtime.backtrace.RubyStackTraceElement[])
*/
public static void dumpWarning(RubyStackTraceElement[] trace) {
LOG.info("Warning backtrace generated:\n" + Arrays.toString(trace));
logWarning(trace);
}

public static TraceType traceTypeFor(String style) {
Expand Down