deleting / moving project dir
This commit is contained in:
parent
3563a3e35a
commit
329a01ec93
|
@ -1 +0,0 @@
|
|||
### Relevant Articles:
|
|
@ -1,65 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>logback</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>logback</name>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.loki4j</groupId>
|
||||
<artifactId>loki-logback-appender</artifactId>
|
||||
<version>${loki-logback.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<logback.contrib.version>0.1.5</logback.contrib.version>
|
||||
<loki-logback.version>1.4.2</loki-logback.version>
|
||||
<slf4j.version>2.0.4</slf4j.version>
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
<mockito.version>5.6.0</mockito.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,15 +0,0 @@
|
|||
package com.baeldung.loki;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DemoService {
|
||||
|
||||
private final Logger LOG = LoggerFactory.getLogger(DemoService.class);
|
||||
|
||||
public void log() {
|
||||
LOG.info("DemoService.log invoked");
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<springProperty name="name" source="spring.application.name"/>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>
|
||||
{
|
||||
"level":"%level",
|
||||
"class":"%logger{36}",
|
||||
"thread":"%thread",
|
||||
"message": "%message",
|
||||
"requestId": "%X{X-Request-ID}"
|
||||
}
|
||||
</pattern>
|
||||
<!-- <pattern>-->
|
||||
<!-- %d{HH:mm:ss.SSS} %-5level %logger{36} %X{X-Request-ID} - %msg%n-->
|
||||
<!-- </pattern>-->
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
|
||||
<!-- (1) -->
|
||||
<http>
|
||||
<url>http://localhost:3100/loki/api/v1/push</url>
|
||||
</http>
|
||||
<format>
|
||||
<!-- (2) -->
|
||||
<label>
|
||||
<pattern>app=${name},host=${HOSTNAME},level=%level</pattern>
|
||||
<!-- (3) -->
|
||||
<readMarkers>true</readMarkers>
|
||||
</label>
|
||||
<message>
|
||||
<!-- (4) -->
|
||||
<pattern>
|
||||
{
|
||||
"level":"%level",
|
||||
"class":"%logger{36}",
|
||||
"thread":"%thread",
|
||||
"message": "%message",
|
||||
"requestId": "%X{X-Request-ID}"
|
||||
}
|
||||
</pattern>
|
||||
</message>
|
||||
</format>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="LOKI"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
|
@ -1,49 +0,0 @@
|
|||
package com.baeldung.loki;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.Appender;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest(classes = DemoService.class)
|
||||
public class DemoServiceTest {
|
||||
|
||||
@Mock
|
||||
Appender<ILoggingEvent> appender;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<ILoggingEvent> captor;
|
||||
|
||||
@Test
|
||||
public void givenLokiAppender_whenSampleServiceInvoked_ThenCaptureInfoLog() throws ParseException {
|
||||
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||
when(appender.getName()).thenReturn("loki-logback-appender");
|
||||
logger.addAppender(appender);
|
||||
|
||||
DemoService service = new DemoService();
|
||||
service.log();
|
||||
|
||||
verify(appender, times(1)).doAppend(captor.capture());
|
||||
List<ILoggingEvent> allValues = captor.getAllValues();
|
||||
assertEquals(1, allValues.size());
|
||||
ILoggingEvent event = allValues.get(0);
|
||||
assertEquals(event.getLevel(), Level.INFO);
|
||||
assertEquals("DemoService.log invoked", event.getFormattedMessage());
|
||||
}
|
||||
}
|
|
@ -27,12 +27,6 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -10,6 +10,6 @@ public class DemoService {
|
|||
private final Logger LOG = LoggerFactory.getLogger(DemoService.class);
|
||||
|
||||
public void log() {
|
||||
LOG.info("DemoService.log invoked!!!");
|
||||
LOG.info("DemoService.log invoked");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package com.baeldung.extensions;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootLogbackExtensionsApplication {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SpringBootLogbackExtensionsApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootLogbackExtensionsApplication.class, args);
|
||||
|
||||
logger.debug("Debug log message");
|
||||
logger.info("Info log message");
|
||||
logger.error("Error log message");
|
||||
logger.warn("Warn log message");
|
||||
logger.trace("Trace log message");
|
||||
}
|
||||
}
|
|
@ -2,21 +2,6 @@
|
|||
<configuration>
|
||||
|
||||
<springProperty name="name" source="spring.application.name"/>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>
|
||||
{
|
||||
"level":"%level",
|
||||
"class":"%logger{36}",
|
||||
"thread":"%thread",
|
||||
"message": "%message",
|
||||
"requestId": "%X{X-Request-ID}"
|
||||
}
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
|
||||
<http>
|
||||
<url>http://localhost:3100/loki/api/v1/push</url>
|
||||
|
@ -41,7 +26,6 @@
|
|||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="LOKI"/>
|
||||
</root>
|
||||
|
||||
|
|
|
@ -37,17 +37,18 @@ public class DemoServiceLiveTest {
|
|||
service.log();
|
||||
Thread.sleep(2000);
|
||||
String baseUrl = "http://localhost:3100/loki/api/v1/query_range";
|
||||
|
||||
// Set up query parameters
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
String query = "{level=\"INFO\"} |= `DemoService.log invoked!!!`";
|
||||
String query = "{level=\"INFO\"} |= `DemoService.log invoked`";
|
||||
|
||||
// Get current time in UTC
|
||||
LocalDateTime currentDateTime = LocalDateTime.now(ZoneOffset.UTC);
|
||||
String current_time_est = currentDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"));
|
||||
|
||||
LocalDateTime tenMinsAgo = currentDateTime.minusMinutes(10);
|
||||
String start_time_est = tenMinsAgo.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"));
|
||||
System.out.println(start_time_est);
|
||||
|
||||
URI uri = UriComponentsBuilder.fromUriString(baseUrl)
|
||||
.queryParam("query", query)
|
||||
|
@ -80,7 +81,7 @@ public class DemoServiceLiveTest {
|
|||
System.out.println("Error: " + response.getStatusCodeValue());
|
||||
}
|
||||
|
||||
String expected = "DemoService.log invoked!!!";
|
||||
String expected = "DemoService.log invoked";
|
||||
assertTrue(messages.stream().anyMatch(e -> e.contains(expected)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue