Skip to content

Commit

Permalink
Merge pull request #995 from carlo-rtr/configurable_callerdata
Browse files Browse the repository at this point in the history
includeCallerData should be configurable
  • Loading branch information
jplock committed Apr 16, 2015
2 parents 75a5197 + 24fb50e commit 983932c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Expand Up @@ -43,6 +43,14 @@
* <td>The maximum capacity of the blocking queue.</td>
* </tr>
* <tr>
* <td>{@code includeCallerData}</td>
* <td>{@link AsyncAppenderBase}</td>
* <td>
* Whether to include caller data, required for line numbers.
* Beware, is considered expensive.
* </td>
* </tr>
* <tr>
* <td>{@code discardingThreshold}</td>
* <td>{@link AsyncAppenderBase}</td>
* <td>
Expand All @@ -65,6 +73,8 @@ public abstract class AbstractAppenderFactory implements AppenderFactory {

private int discardingThreshold = -1;

private boolean includeCallerData = false;

@JsonProperty
public int getQueueSize() {
return queueSize;
Expand Down Expand Up @@ -105,12 +115,23 @@ public void setLogFormat(String logFormat) {
this.logFormat = logFormat;
}

@JsonProperty
public boolean isIncludeCallerData() {
return includeCallerData;
}

@JsonProperty
public void setIncludeCallerData(boolean includeCallerData) {
this.includeCallerData = includeCallerData;
}

protected Appender<ILoggingEvent> wrapAsync(Appender<ILoggingEvent> appender) {
return wrapAsync(appender, appender.getContext());
}

protected Appender<ILoggingEvent> wrapAsync(Appender<ILoggingEvent> appender, Context context) {
final AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.setIncludeCallerData(includeCallerData);
asyncAppender.setQueueSize(queueSize);
asyncAppender.setDiscardingThreshold(discardingThreshold);
asyncAppender.setContext(context);
Expand Down
@@ -1,6 +1,8 @@
package io.dropwizard.logging;

import ch.qos.logback.classic.AsyncAppender;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender;
import io.dropwizard.jackson.DiscoverableSubtypeResolver;
Expand All @@ -16,6 +18,17 @@ public void isDiscoverable() throws Exception {
.contains(ConsoleAppenderFactory.class);
}

@Test
public void includesCallerData() {
ConsoleAppenderFactory consoleAppenderFactory = new ConsoleAppenderFactory();
AsyncAppender asyncAppender = (AsyncAppender) consoleAppenderFactory.build(new LoggerContext(), "test", null);
assertThat(asyncAppender.isIncludeCallerData()).isFalse();

consoleAppenderFactory.setIncludeCallerData(true);
asyncAppender = (AsyncAppender) consoleAppenderFactory.build(new LoggerContext(), "test", null);
assertThat(asyncAppender.isIncludeCallerData()).isTrue();
}

@Test
public void appenderContextIsSet() throws Exception {
final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
Expand Down
@@ -1,5 +1,6 @@
package io.dropwizard.logging;

import ch.qos.logback.classic.AsyncAppender;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
Expand All @@ -19,6 +20,18 @@ public void isDiscoverable() throws Exception {
.contains(FileAppenderFactory.class);
}

@Test
public void includesCallerData() {
FileAppenderFactory fileAppenderFactory = new FileAppenderFactory();
fileAppenderFactory.setArchive(false);
AsyncAppender asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", null);
assertThat(asyncAppender.isIncludeCallerData()).isFalse();

fileAppenderFactory.setIncludeCallerData(true);
asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", null);
assertThat(asyncAppender.isIncludeCallerData()).isTrue();
}

@Test
public void isRolling() throws Exception {
// the method we want to test is protected, so we need to override it so we can see it
Expand Down

0 comments on commit 983932c

Please sign in to comment.