@@ -54,6 +54,10 @@ public final class LoggingEventMapper {
54
54
55
55
private static final AttributeKey <List <String >> LOG_MARKER =
56
56
AttributeKey .stringArrayKey ("logback.marker" );
57
+ private static final AttributeKey <String > LOG_BODY_TEMPLATE =
58
+ AttributeKey .stringKey ("log.body.template" );
59
+ private static final AttributeKey <List <String >> LOG_BODY_PARAMETERS =
60
+ AttributeKey .stringArrayKey ("log.body.parameters" );
57
61
58
62
private final boolean captureExperimentalAttributes ;
59
63
private final List <String > captureMdcAttributes ;
@@ -202,10 +206,9 @@ void captureMdcAttributes(AttributesBuilder attributes, Map<String, String> mdcP
202
206
}
203
207
204
208
void captureArguments (AttributesBuilder attributes , String message , Object [] arguments ) {
205
- String bodyKey = "log.body.template" ;
206
- attributes .put (bodyKey , message );
209
+ attributes .put (LOG_BODY_TEMPLATE , message );
207
210
attributes .put (
208
- AttributeKey . stringArrayKey ( "log.body.parameters" ) ,
211
+ LOG_BODY_PARAMETERS ,
209
212
Arrays .stream (arguments ).map (String ::valueOf ).collect (Collectors .toList ()));
210
213
}
211
214
@@ -249,26 +252,22 @@ private static void captureKeyValuePairAttributes(
249
252
if (keyValuePairs != null ) {
250
253
for (KeyValuePair keyValuePair : keyValuePairs ) {
251
254
Object value = keyValuePair .value ;
252
- propagateAttribute (attributes , keyValuePair .key , value );
253
- }
254
- }
255
- }
256
-
257
- @ NoMuzzle
258
- private static void propagateAttribute (AttributesBuilder attributes , String key , Object value ) {
259
- if (value != null ) {
260
- // preserve type for boolean and numeric values, everything else is converted to String
261
- if (value instanceof Boolean ) {
262
- attributes .put (key , (Boolean ) value );
263
- } else if (value instanceof Byte
264
- || value instanceof Integer
265
- || value instanceof Long
266
- || value instanceof Short ) {
267
- attributes .put (key , ((Number ) value ).longValue ());
268
- } else if (value instanceof Double || value instanceof Float ) {
269
- attributes .put (key , ((Number ) value ).doubleValue ());
270
- } else {
271
- attributes .put (getAttributeKey (key ), value .toString ());
255
+ if (value != null ) {
256
+ String key = keyValuePair .key ;
257
+ // preserve type for boolean and numeric values, everything else is converted to String
258
+ if (value instanceof Boolean ) {
259
+ attributes .put (key , (Boolean ) value );
260
+ } else if (value instanceof Byte
261
+ || value instanceof Integer
262
+ || value instanceof Long
263
+ || value instanceof Short ) {
264
+ attributes .put (key , ((Number ) value ).longValue ());
265
+ } else if (value instanceof Double || value instanceof Float ) {
266
+ attributes .put (key , ((Number ) value ).doubleValue ());
267
+ } else {
268
+ attributes .put (getAttributeKey (key ), value .toString ());
269
+ }
270
+ }
272
271
}
273
272
}
274
273
}
0 commit comments