Skip to content

Commit dde59a5

Browse files
committed
fix: process log messages as templates independently of response
Based on the documentation, log messages should always be processed through the template engine, regardless of whether the response has template=true. The documentation shows an interceptor example with placeholders in the log message but no template flag on the response: ```yaml log: "User accessed ${context.request.headers.User-Agent}" response: statusCode: 401 content: "Unauthorized" # Note: no template: true ``` Changes: - Log messages are now always processed through PlaceholderUtil - Removed template: true from test config (not needed for logs) - Fixed wildcard import in AbstractResourceConfig This allows log messages to use placeholders independently of whether the response content uses templating.
1 parent f0f934d commit dde59a5

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

core/engine/src/main/java/io/gatehill/imposter/service/ResponseServiceImpl.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,14 @@ class ResponseServiceImpl @Inject constructor(
228228
} else {
229229
origResponseData
230230
}
231-
231+
232232
// Process custom log message if present
233+
// Log messages are always processed as templates per documentation
233234
if (resourceConfig is AbstractResourceConfig && resourceConfig.log != null) {
234-
val logMessage = if (template) {
235-
PlaceholderUtil.replace(resourceConfig.log!!, httpExchange, PlaceholderUtil.templateEvaluators)
236-
} else {
237-
resourceConfig.log!!
238-
}
235+
val logMessage = PlaceholderUtil.replace(resourceConfig.log!!, httpExchange, PlaceholderUtil.templateEvaluators)
239236
LOGGER.info("Resource log: {}", logMessage)
240237
}
241-
238+
242239
response.end(responseData)
243240
}
244241

0 commit comments

Comments
 (0)