mirror of
https://github.com/tiennm99/tjahzi.git
synced 2026-10-15 22:15:14 +00:00
Added test for loading Tjahzi configuration from property file based config file.
This commit is contained in:
1 parent
b8b309a578
commit
f99c262d70
2 files changed
+67
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package pl.tkowalcz.tjahzi.log4j2;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import pl.tkowalcz.tjahzi.log4j2.infra.IntegrationTest;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static pl.tkowalcz.tjahzi.log4j2.infra.LokiAssert.assertThat;
|
||||
|
||||
class LokiPropertiesFileTest extends IntegrationTest {
|
||||
|
||||
@Test
|
||||
void shouldSendData() {
|
||||
// Given
|
||||
loadConfig("appender-test-with-log-label-set.properties");
|
||||
Logger logger = LogManager.getLogger(LokiPropertiesFileTest.class);
|
||||
|
||||
String expectedLogLine = "Hello World";
|
||||
|
||||
// When
|
||||
logger.info(expectedLogLine);
|
||||
|
||||
// Then
|
||||
assertThat(loki)
|
||||
.returns(response -> response
|
||||
.body("data.result.size()", equalTo(1))
|
||||
.body("data.result[0].stream.server", equalTo("127.0.0.1"))
|
||||
.body("data.result[0].stream.source", equalTo("log4j"))
|
||||
.body(
|
||||
"data.result.values",
|
||||
hasItems(
|
||||
hasItems(
|
||||
hasItems(
|
||||
containsString("INFO LokiPropertiesFileTest - " + expectedLogLine)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
packages="pl.tkowalcz.tjahzi.log4j2"
|
||||
|
||||
# Allows this configuration to be modified at runtime. The file will be checked every 30 seconds.
|
||||
monitorInterval=30
|
||||
|
||||
rootLogger.level = INFO
|
||||
rootLogger.appenderRefs = loki
|
||||
rootLogger.appenderRef.loki.ref = loki-appender
|
||||
|
||||
appender.loki.name = loki-appender
|
||||
appender.loki.type = Loki
|
||||
appender.loki.host = ${sys:loki.host}
|
||||
appender.loki.port = ${sys:loki.port}
|
||||
appender.loki.logLevelLabel = log_level
|
||||
|
||||
appender.loki.layout.type = PatternLayout
|
||||
appender.loki.layout.pattern = %X{tid} [%t] %d{MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n%exception{full}
|
||||
|
||||
appender.loki.labels[0].type = label
|
||||
appender.loki.labels[0].name = server
|
||||
appender.loki.labels[0].value = 127.0.0.1
|
||||
|
||||
appender.loki.labels[1].type = label
|
||||
appender.loki.labels[1].name = source
|
||||
appender.loki.labels[1].value = log4j
|
||||
Reference in new issue
Block a user