Skip to content

Commit

Permalink
Avoid string concat in log statements
Browse files Browse the repository at this point in the history
Update Slf4j to allow varargs, otherwise we have to do new Object[] {}
  • Loading branch information
ryantenney committed Nov 27, 2013
1 parent 060d6d7 commit 8ab7d07
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ private void submitEndpoint(HttpServletRequest request) {
String localAddr = request.getLocalAddr();
int localPort = request.getLocalPort();
endPointSubmitter.submit(localAddr, localPort, contextPath);
logger.debug("Setting endpoint: addr: " + localAddr + ", port: " + localPort +
", contextpath: " + contextPath);
logger.debug("Setting endpoint: addr: {}, port: {}, contextpath: {}", localAddr, localPort, contextPath);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ClientResponse<?> execute(final ClientExecutionContext ctx) throws Except

final SpanId newSpanId = clientTracer.startNewSpan(spanName);
if (newSpanId != null) {
LOGGER.debug("Will trace request. Span Id returned from ClientTracer: " + newSpanId.toString());
LOGGER.debug("Will trace request. Span Id returned from ClientTracer: {}", newSpanId);
request.header(BraveHttpHeaders.Sampled.getName(), TRUE);
request.header(BraveHttpHeaders.TraceId.getName(), newSpanId.getTraceId());
request.header(BraveHttpHeaders.SpanId.getName(), newSpanId.getSpanId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ private void submitEndpoint() {
final String localAddr = servletRequest.getLocalAddr();
final int localPort = servletRequest.getLocalPort();
final String contextPath = servletRequest.getContextPath();
LOGGER.debug("Setting endpoint: addr: " + localAddr + ", port: " + localPort +
", contextpath: " + contextPath);
LOGGER.debug("Setting endpoint: addr: {}, port: {}, contextpath: {}", localAddr, localPort, contextPath);
endPointSubmitter.submit(localAddr, localPort, contextPath);
}
}
Expand All @@ -124,7 +123,7 @@ private TraceData getTraceData(final HttpRequest request) {
final TraceData traceData = new TraceData();

for (final Entry<String, List<String>> headerEntry : requestHeaders.entrySet()) {
LOGGER.debug(headerEntry.getKey() + "=" + headerEntry.getValue());
LOGGER.debug("{}={}", headerEntry.getKey(), headerEntry.getValue());
if (BraveHttpHeaders.TraceId.getName().equalsIgnoreCase(headerEntry.getKey())) {
traceData.setTraceId(getFirstLongValueFor(headerEntry));
} else if (BraveHttpHeaders.SpanId.getName().equalsIgnoreCase(headerEntry.getKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void process(final WatchedEvent event) {

if (sampleRateZNode.equals(path)) {
sampleRate = getSampleRate();
LOGGER.info("SampleRate znode [" + sampleRateZNode + "] changed. New value: " + sampleRate);
LOGGER.info("SampleRate znode [{}] changed. New value: {}", sampleRateZNode, sampleRate);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void collect(final Span span) {

final boolean offer = spanQueue.offer(span);
if (!offer) {
LOGGER.error("Queue rejected Span, span not submitted: " + span);
LOGGER.error("Queue rejected Span, span not submitted: {}", span);
} else {
final long end = System.currentTimeMillis();
if (LOGGER.isDebugEnabled()) {
Expand Down Expand Up @@ -155,7 +155,7 @@ public void close() {
for (final Future<Integer> future : futures) {
try {
final Integer spansProcessed = future.get();
LOGGER.info("SpanProcessingThread processed " + spansProcessed + " spans.");
LOGGER.info("SpanProcessingThread processed {} spans.", spansProcessed);
} catch (final Exception e) {
LOGGER.error("Exception when getting result of SpanProcessingThread.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ public void configure(final Context context) {
sinkCounter = new SinkCounter(getName());
}

LOGGER.info("Configuring ZipkinSpanCollectorSink. hostname: " + hostName + ", port: " + port + ", batchsize: "
+ batchSize);
LOGGER.info("Configuring ZipkinSpanCollectorSink. hostname: {}, port: {}, batchsize: {}", hostName, port, batchSize);
}

private LogEntry create(final Event event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,26 @@ public void configure(final Context context) {
throw new IllegalStateException(GRAPHITE_HOST + " and " + GRAPHITE_PORT + " properties are mandatory.");
}

LOGGER.info("Graphite host: " + graphiteHost);
LOGGER.info("Graphite port: " + graphitePort);
LOGGER.info("Graphite host: {}", graphiteHost);
LOGGER.info("Graphite port: {}", graphitePort);

metricPrefix = context.getString(METRIC_PREFIX);
pollTimeMinutes = context.getInteger(POLL_TIME, 1);
LOGGER.info("Reporter poll time in minutes: " + pollTimeMinutes);
LOGGER.info("Reporter poll time in minutes: {}", pollTimeMinutes);

final String reservoir = context.getString(METRICS_RESERVOIR, DEFAULT_RESERVOIR);

if (UNIFORM_RESERVOIR.equals(reservoir)) {
LOGGER.info("Reservoir: " + UNIFORM_RESERVOIR);
LOGGER.info("Reservoir: {}", UNIFORM_RESERVOIR);
initializeUniformHistogramBuilder(context);
} else if (EXPONENTIALLY_DECAYING_RESERVOIR.equals(reservoir)) {
LOGGER.info("Reservoir: " + EXPONENTIALLY_DECAYING_RESERVOIR);
LOGGER.info("Reservoir: {}", EXPONENTIALLY_DECAYING_RESERVOIR);
initializeExponentiallyDecayingReservoir(context);
} else if (SLIDING_TIME_WINDOW_RESERVOIR.equals(reservoir)) {
LOGGER.info("Reservoir: " + SLIDING_TIME_WINDOW_RESERVOIR);
LOGGER.info("Reservoir: {}", SLIDING_TIME_WINDOW_RESERVOIR);
initializeSlidingTimeWindowReservoir(context);
} else if (SLIDING_WINDOW_RESERVOIR.equals(reservoir)) {
LOGGER.info("Reservoir: " + SLIDING_WINDOW_RESERVOIR);
LOGGER.info("Reservoir: {}", SLIDING_WINDOW_RESERVOIR);
initializeSlidingWindowReservoir(context);
} else {
throw new IllegalStateException("Invalid value for reservoir: " + reservoir);
Expand All @@ -109,7 +109,7 @@ public MetricReporter build() {
GraphiteReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL);
if (StringUtils.isNotBlank(metricPrefix)) {
LOGGER.info("Metric prefix: " + metricPrefix);
LOGGER.info("Metric prefix: {}", metricPrefix);
builder.prefixedWith(metricPrefix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void configure(final Context context) {
sinkCounter = new SinkCounter(getName());
}

LOGGER.info("batchsize: " + batchSize);
LOGGER.info("batchsize: {}", batchSize);

}

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.1</version>
<version>1.7.5</version>
</dependency>
</dependencies>

Expand Down

0 comments on commit 8ab7d07

Please sign in to comment.