Skip to content

Commit

Permalink
ELK first test
Browse files Browse the repository at this point in the history
  • Loading branch information
DucBaoUIT committed Oct 2, 2024
1 parent 3274741 commit de27247
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>



<!--ELK Dependencies-->
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.0.1</version>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -21,12 +22,22 @@
import org.springframework.web.bind.annotation.RequestBody;
import lombok.AllArgsConstructor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

@RestController
@RequestMapping("/comment")
@AllArgsConstructor
public class CommentController {

private static final Logger logger = LoggerFactory.getLogger(CommentController.class);

@GetMapping("/")
public String getServiceName() {
//ELK
MDC.put("type", "commentservice");
logger.info("Comment Service Start");
return "Comment Service";
}
private final CommentRepository commentRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# logstash
logging.config=classpath:logback-spring.xml
11 changes: 11 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<configuration>
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>192.168.120.213:5060</destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="LOGSTASH"/>
</root>
</configuration>

0 comments on commit de27247

Please sign in to comment.