Skip to content

Commit

Permalink
:instrumentation:logback:logback-appender-1.0:library:spotlessApply
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-suhorukov committed Jul 19, 2024
1 parent 5c340b0 commit 567fce4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ private void mapLoggingEvent(
captureLoggerContext(attributes, loggingEvent.getLoggerContextVO().getPropertyMap());
}

if (captureArguments &&
loggingEvent.getArgumentArray()!=null && loggingEvent.getArgumentArray().length > 0) {
captureArguments(attributes, loggingEvent.getMessage(), loggingEvent.getArgumentArray());
if (captureArguments
&& loggingEvent.getArgumentArray() != null
&& loggingEvent.getArgumentArray().length > 0) {
captureArguments(attributes, loggingEvent.getMessage(), loggingEvent.getArgumentArray());
}

builder.setAllAttributes(attributes.build());
Expand All @@ -198,12 +199,12 @@ void captureMdcAttributes(AttributesBuilder attributes, Map<String, String> mdcP
}
}

void captureArguments(AttributesBuilder attributes, String message, Object[] arguments){
void captureArguments(AttributesBuilder attributes, String message, Object[] arguments) {
attributes.put("src_msg_", message);
for (int idx = 0; idx < arguments.length; idx++) {
Object argument = arguments[idx];
attributes.put("log_arg_" + idx, String.valueOf(argument));
}
for (int idx = 0; idx < arguments.length; idx++) {
Object argument = arguments[idx];
attributes.put("log_arg_" + idx, String.valueOf(argument));
}
}

public static AttributeKey<String> getMdcAttributeKey(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ void multipleMarkers() {
void arguments() {
logger
.atInfo()
.setMessage("log message {} and {}").addArgument("'world'").addArgument(Math.PI)
.setMessage("log message {} and {}")
.addArgument("'world'")
.addArgument(Math.PI)
.log();

List<LogRecordData> logDataList = logRecordExporter.getFinishedLogRecordItems();
Expand All @@ -127,13 +129,11 @@ void arguments() {
assertThat(logData.getResource()).isEqualTo(resource);
assertThat(logData.getInstrumentationScopeInfo()).isEqualTo(instrumentationScopeInfo);
assertThat(logData.getBody().asString()).isEqualTo("log message 'world' and 3.141592653589793");
assertThat(logData.getAttributes().size())
.isEqualTo(7);
assertThat(logData.getAttributes().size()).isEqualTo(7);
assertThat(logData)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("log_arg_0"), "'world'"),
equalTo(AttributeKey.stringKey("log_arg_1"), "3.141592653589793"),
equalTo(AttributeKey.stringKey("src_msg_"), "log message {} and {}")
);
equalTo(AttributeKey.stringKey("src_msg_"), "log message {} and {}"));
}
}

0 comments on commit 567fce4

Please sign in to comment.