/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
map.put("timestamp", getTimestamp(event.getInstant()));
map.put("severity", event.getLevel().toString());
map.put("message", event.getFormattedMessage());
- Map<String, String> extraDatamap = new HashMap<>();
+ Map<String, Object> extraDatamap = new HashMap<>();
extraDatamap.put("logger", event.getLoggerName());
extraDatamap.put("thread", event.getThreadName());
var throwableProxy = event.getThrowableProxy();
if (throwableProxy != null) {
- extraDatamap.put("exception", ThrowableProxyUtil.asString(throwableProxy));
+ var m = Map.of("stack_trace", ThrowableProxyUtil.asString(throwableProxy));
+ extraDatamap.put("exception", m);
}
map.put("extra_data", extraDatamap);
map.putAll(staticParameterMap);
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.LoggerContextVO;
+import ch.qos.logback.classic.spi.ThrowableProxy;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
layout.setTimestampFormatTimezoneId("");
layout.start();
testingResult(layout, event);
+
+ //event with exception
+ layout.setTimestampFormat(FORMAT);
+ layout.setTimestampFormatTimezoneId("UTC");
+ layout.setStaticParameters("service_id=policy-acm|application_id=policy-acm");
+ layout.start();
+ var throwable = new Throwable("PSQL Exception: Unable to modify object");
+ event.setThrowableProxy(new ThrowableProxy(throwable));
+ testingResult(layout, event);
}
private void testingResult(LoggingConsoleLayout layout, DummyEvent event) throws CoderException {
assertEquals(event.level.toString(), map.get("severity"));
assertEquals(event.message, map.get("message"));
@SuppressWarnings("unchecked")
- var extraData = (Map<String, String>) map.get("extra_data");
+ var extraData = (Map<String, Object>) map.get("extra_data");
assertEquals(event.loggerName, extraData.get("logger"));
assertEquals(event.threadName, extraData.get("thread"));
+ if (event.getThrowableProxy() != null) {
+ assertTrue(((Map<?, ?>) extraData.get("exception")).containsKey("stack_trace"));
+ }
}
}