Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix logback-750

  • Loading branch information...
commit dae058dca833e7ac2c92b567785eb593ccc5648f 1 parent d3babf0
@ceki ceki authored
View
33 logback-classic/src/main/java/ch/qos/logback/classic/net/SyslogAppender.java
@@ -73,23 +73,16 @@ protected void postProcess(Object eventObject, OutputStream sw) {
ILoggingEvent event = (ILoggingEvent) eventObject;
IThrowableProxy tp = event.getThrowableProxy();
- if(tp == null)
+ if (tp == null)
return;
String stackTracePrefix = stackTraceLayout.doLayout(event);
- boolean topException = true;
+ boolean isRootException = true;
while (tp != null) {
StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
try {
- StringBuilder stackTraceHeaderLine = new StringBuilder().append(stackTracePrefix);
- if (topException) {
- topException = false;
- } else {
- stackTraceHeaderLine = stackTraceHeaderLine.append(CoreConstants.CAUSED_BY);
- }
- stackTraceHeaderLine.append(tp.getClassName()).append(": ").append(tp.getMessage());
- sw.write(stackTraceHeaderLine.toString().getBytes());
- sw.flush();
+ writeHeaderLine(sw, tp, stackTracePrefix, isRootException);
+ isRootException = false;
for (StackTraceElementProxy step : stepArray) {
StringBuilder sb = new StringBuilder();
sb.append(stackTracePrefix).append(step);
@@ -103,6 +96,22 @@ protected void postProcess(Object eventObject, OutputStream sw) {
}
}
+ private void writeHeaderLine(OutputStream sw, IThrowableProxy tp, String stackTracePrefix, boolean isRootException) throws IOException {
+ StringBuilder sb = new StringBuilder().append(stackTracePrefix);
+
+ if (!isRootException) {
+ sb.append(CoreConstants.CAUSED_BY);
+ }
+ sb.append(tp.getClassName()).append(": ").append(tp.getMessage());
+ sw.write(sb.toString().getBytes());
+ sw.flush();
+ }
+
+ boolean stackTraceHeaderLine(StringBuilder sb, boolean topException) {
+
+ return false;
+ }
+
public Layout<ILoggingEvent> buildLayout() {
PatternLayout layout = new PatternLayout();
layout.getInstanceConverterMap().put("syslogStart",
@@ -114,7 +123,7 @@ protected void postProcess(Object eventObject, OutputStream sw) {
layout.setContext(getContext());
layout.start();
return layout;
- }
+ }
private void setupStackTraceLayout() {
stackTraceLayout.getInstanceConverterMap().put("syslogStart",
View
4 logback-classic/src/test/java/ch/qos/logback/classic/net/SyslogAppenderTest.java
@@ -136,6 +136,10 @@ public void tException() throws InterruptedException {
checkRegexMatch(msg, regex);
msg = mockServer.getMessageList().get(1);
+ assertTrue(msg.contains(ex.getClass().getName()));
+ assertTrue(msg.contains(ex.getMessage()));
+
+ msg = mockServer.getMessageList().get(2);
assertTrue(msg.startsWith(expected));
regex = expectedPrefix + "\\[" + threadName + "\\] " + "foo "+CoreConstants.TAB + "at ch\\.qos.*";
checkRegexMatch(msg, regex);
View
45 logback-core/src/test/java/ch/qos/logback/core/recovery/ResilientOutputStreamTest.java
@@ -0,0 +1,45 @@
+package ch.qos.logback.core.recovery;
+
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.testUtil.RandomUtil;
+import ch.qos.logback.core.util.CoreTestConstants;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+/**
+ * @author Ceki G&uuml;c&uuml;
+ */
+public class ResilientOutputStreamTest {
+
+ int diff = RandomUtil.getPositiveInt();
+ Context context = new ContextBase();
+
+
+ @Test
+ public void verifyRecuperationAfterFailure() throws Exception {
+ File file = new File(CoreTestConstants.OUTPUT_DIR_PREFIX+"resilient"+diff+".log");
+ ResilientFileOutputStream rfos = new ResilientFileOutputStream(file, true);
+ rfos.setContext(context);
+
+ ResilientFileOutputStream spy = spy(rfos);
+
+ spy.write("a".getBytes());
+ spy.flush();
+
+ spy.getChannel().close();
+ spy.write("b".getBytes());
+ spy.flush();
+ Thread.sleep(RecoveryCoordinator.BACKOFF_COEFFICIENT_MIN+10);
+ spy.write("c".getBytes());
+ spy.flush();
+ verify(spy).openNewOutputStream();
+
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.