Skip to content

Commit 3c23f1d

Browse files
schlosnaadriancole
authored andcommitted
Reduce logging overhead (OpenFeign#439)
* Avoid overhead when logging is disabled.
1 parent bb0f292 commit 3c23f1d

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

core/src/main/java/feign/Logger.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ protected Response logAndRebufferResponse(String configKey, Level logLevel, Resp
178178

179179
@Override
180180
protected void log(String configKey, String format, Object... args) {
181-
logger.fine(String.format(methodTag(configKey) + format, args));
181+
if (logger.isLoggable(java.util.logging.Level.FINE)) {
182+
logger.fine(String.format(methodTag(configKey) + format, args));
183+
}
182184
}
183185

184186
/**

slf4j/src/main/java/feign/slf4j/Slf4jLogger.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ protected Response logAndRebufferResponse(String configKey, Level logLevel, Resp
6868
protected void log(String configKey, String format, Object... args) {
6969
// Not using SLF4J's support for parameterized messages (even though it would be more efficient) because it would
7070
// require the incoming message formats to be SLF4J-specific.
71-
logger.debug(String.format(methodTag(configKey) + format, args));
71+
if (logger.isDebugEnabled()) {
72+
logger.debug(String.format(methodTag(configKey) + format, args));
73+
}
7274
}
7375
}

0 commit comments

Comments
 (0)