Skip to content

Commit 1c53eb6

Browse files
Merge pull request zalando#170 from zalando/feature/curl-correlation-id
Added correlation id to curl log
2 parents ce126b7 + 6c1aa3e commit 1c53eb6

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

logbook-core/src/main/java/org/zalando/logbook/CurlHttpLogFormatter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public String format(final Precorrelation<HttpRequest> precorrelation) throws IO
2626
final HttpRequest request = precorrelation.getRequest();
2727
final List<String> command = new ArrayList<>();
2828

29+
command.add(precorrelation.getId());
2930
command.add("curl");
3031
command.add("-v"); // TODO optional?
3132

logbook-core/src/test/java/org/zalando/logbook/CurlHttpLogFormatterTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public void shouldLogRequest() throws IOException {
3030
final HttpLogFormatter unit = new CurlHttpLogFormatter();
3131
final String curl = unit.format(new SimplePrecorrelation<>(correlationId, request));
3232

33-
assertThat(curl, is("curl -v -X GET 'http://localhost/test?limit=1' -H 'Accept: application/json' -H 'Content-Type: text/plain' --data-binary 'Hello, world!'"));
33+
assertThat(curl, is("c9408eaa-677d-11e5-9457-10ddb1ee7671 " +
34+
"curl -v -X GET 'http://localhost/test?limit=1' -H 'Accept: application/json' -H 'Content-Type: text/plain' --data-binary 'Hello, world!'"));
3435
}
3536

3637
@Test
@@ -43,7 +44,8 @@ public void shouldLogRequestWithoutBody() throws IOException {
4344
final HttpLogFormatter unit = new CurlHttpLogFormatter();
4445
final String curl = unit.format(new SimplePrecorrelation<>(correlationId, request));
4546

46-
assertThat(curl, is("curl -v -X GET 'http://localhost/test' -H 'Accept: application/json'"));
47+
assertThat(curl, is("0eae9f6c-6824-11e5-8b0a-10ddb1ee7671 " +
48+
"curl -v -X GET 'http://localhost/test' -H 'Accept: application/json'"));
4749
}
4850

4951
@Test
@@ -62,7 +64,8 @@ public void shouldEscape() throws IOException {
6264
final HttpLogFormatter unit = new CurlHttpLogFormatter();
6365
final String curl = unit.format(new SimplePrecorrelation<>(correlationId, request));
6466

65-
assertThat(curl, is("curl -v -X GET 'http://localhost/test?char=\\'' -H 'Foo\\'Bar: Baz' --data-binary '{\"message\":\"Hello, \\'world\\'!\"}'"));
67+
assertThat(curl, is("c9408eaa-677d-11e5-9457-10ddb1ee7671 " +
68+
"curl -v -X GET 'http://localhost/test?char=\\'' -H 'Foo\\'Bar: Baz' --data-binary '{\"message\":\"Hello, \\'world\\'!\"}'"));
6669
}
6770

6871
@Test

logbook-spring-boot-starter/src/test/java/org/zalando/logbook/spring/FormatStyleCurlTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void shouldUseHttpFormatter() throws IOException {
5555

5656
private Matcher<Precorrelation<String>> isCurlFormatter() {
5757
final Function<Precorrelation<String>, String> getRequest = Precorrelation::getRequest;
58-
return hasFeature("request", getRequest, is("curl -v -X GET 'http://localhost/'"));
58+
return hasFeature("request", getRequest, containsString("curl -v -X GET 'http://localhost/'"));
5959
}
6060

6161
}

0 commit comments

Comments
 (0)