17
17
18
18
import java .util .function .Supplier ;
19
19
20
- import org .slf4j . Logger ;
21
- import org .slf4j . LoggerFactory ;
20
+ import org .apache . commons . logging . Log ;
21
+ import org .apache . commons . logging . LogFactory ;
22
22
import org .springframework .http .HttpStatus ;
23
23
import org .springframework .lang .Nullable ;
24
24
import org .springframework .util .ObjectUtils ;
25
25
26
26
/**
27
27
* Logging Utility to log client requests and responses. Logs client requests and responses to Elasticsearch to a
28
- * dedicated logger: {@code org.springframework.data.elasticsearch.client.WIRE} on {@link org.slf4j.event.Level#TRACE}
29
- * level.
28
+ * dedicated logger: {@code org.springframework.data.elasticsearch.client.WIRE} on trace level.
30
29
*
31
30
* @author Mark Paluch
32
31
* @author Christoph Strobl
35
34
public abstract class ClientLogger {
36
35
37
36
private static final String lineSeparator = System .getProperty ("line.separator" );
38
- private static final Logger WIRE_LOGGER = LoggerFactory
39
- .getLogger ("org.springframework.data.elasticsearch.client.WIRE" );
37
+ private static final Log WIRE_LOGGER = LogFactory .getLog ("org.springframework.data.elasticsearch.client.WIRE" );
40
38
41
39
private ClientLogger () {}
42
40
@@ -52,24 +50,23 @@ public static boolean isEnabled() {
52
50
/**
53
51
* Log an outgoing HTTP request.
54
52
*
55
- * @param logId the correlation Id , see {@link #newLogId()}.
53
+ * @param logId the correlation id , see {@link #newLogId()}.
56
54
* @param method HTTP method
57
55
* @param endpoint URI
58
56
* @param parameters optional parameters.
59
57
*/
60
58
public static void logRequest (String logId , String method , String endpoint , Object parameters ) {
61
59
62
60
if (isEnabled ()) {
63
-
64
- WIRE_LOGGER .trace ("[{}] Sending request {} {} with parameters: {}" , logId , method .toUpperCase (), endpoint ,
65
- parameters );
61
+ WIRE_LOGGER .trace (String .format ("[%s] Sending request %s %s with parameters: %s" , logId , method .toUpperCase (),
62
+ endpoint , parameters ));
66
63
}
67
64
}
68
65
69
66
/**
70
67
* Log an outgoing HTTP request with a request body.
71
68
*
72
- * @param logId the correlation Id , see {@link #newLogId()}.
69
+ * @param logId the correlation id , see {@link #newLogId()}.
73
70
* @param method HTTP method
74
71
* @param endpoint URI
75
72
* @param parameters optional parameters.
@@ -79,43 +76,43 @@ public static void logRequest(String logId, String method, String endpoint, Obje
79
76
Supplier <Object > body ) {
80
77
81
78
if (isEnabled ()) {
82
-
83
- WIRE_LOGGER .trace ("[{}] Sending request {} {} with parameters: {}{}Request body: {}" , logId , method .toUpperCase (),
84
- endpoint , parameters , lineSeparator , body .get ());
79
+ WIRE_LOGGER .trace (String .format ("[%s] Sending request %s %s with parameters: %s%sRequest body: %s" , logId ,
80
+ method .toUpperCase (), endpoint , parameters , lineSeparator , body .get ()));
85
81
}
86
82
}
87
83
88
84
/**
89
85
* Log a raw HTTP response without logging the body.
90
86
*
91
- * @param logId the correlation Id , see {@link #newLogId()}.
87
+ * @param logId the correlation id , see {@link #newLogId()}.
92
88
* @param statusCode the HTTP status code.
93
89
*/
94
90
public static void logRawResponse (String logId , @ Nullable HttpStatus statusCode ) {
95
91
96
92
if (isEnabled ()) {
97
- WIRE_LOGGER .trace ("[{} ] Received raw response: {} " , logId , statusCode );
93
+ WIRE_LOGGER .trace (String . format ( "[%s ] Received raw response: %s " , logId , statusCode ) );
98
94
}
99
95
}
100
96
101
97
/**
102
98
* Log a raw HTTP response along with the body.
103
99
*
104
- * @param logId the correlation Id , see {@link #newLogId()}.
100
+ * @param logId the correlation id , see {@link #newLogId()}.
105
101
* @param statusCode the HTTP status code.
106
102
* @param body body content.
107
103
*/
108
104
public static void logResponse (String logId , HttpStatus statusCode , String body ) {
109
105
110
106
if (isEnabled ()) {
111
- WIRE_LOGGER .trace ("[{}] Received response: {}{}Response body: {}" , logId , statusCode , lineSeparator , body );
107
+ WIRE_LOGGER .trace (
108
+ String .format ("[%s] Received response: %s%sResponse body: %s" , logId , statusCode , lineSeparator , body ));
112
109
}
113
110
}
114
111
115
112
/**
116
- * Creates a new, unique correlation Id to improve tracing across log events.
113
+ * Creates a new, unique correlation id to improve tracing across log events.
117
114
*
118
- * @return a new, unique correlation Id .
115
+ * @return a new, unique correlation id .
119
116
*/
120
117
public static String newLogId () {
121
118
0 commit comments