diff --git a/pom.xml b/pom.xml
index 512e459..396ff03 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,7 +79,14 @@
+
+ net.logstash.logback
+ logstash-logback-encoder
+ 7.0.1
+
+
+
diff --git a/src/main/java/com/programming/commentService/controller/CommentController.java b/src/main/java/com/programming/commentService/controller/CommentController.java
index 10a5309..3181b8e 100644
--- a/src/main/java/com/programming/commentService/controller/CommentController.java
+++ b/src/main/java/com/programming/commentService/controller/CommentController.java
@@ -27,6 +27,10 @@
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
@@ -39,11 +43,15 @@ public class CommentController {
private final CommentRepository commentRepository;
+ private static final Logger logger = LoggerFactory.getLogger(CommentController.class);
+
@Autowired
private CommentService commentService;
@GetMapping("/")
public String getServiceName() {
+ MDC.put("type", "commentservice");
+ logger.info("Comment Service Start");
return "Comment Service";
}
@@ -100,6 +108,14 @@ public ResponseEntity> uploadComment(@RequestBody Comment comment) {
// Lưu comment đã xử lý vào MongoDB
Comment savedComment = commentRepository.save(sanitizedComment);
+
+ //ELK
+ MDC.put("type", "commentservice");
+ MDC.put("action", "upload");
+ logger.info("CommentId: " + savedComment.getId());
+ logger.info("VideoId: " + comment.getVideoId());
+ logger.info("UserId: " + comment.getUserId());
+
return ResponseEntity.ok(savedComment);
} catch (Exception e) {
return ResponseEntity.internalServerError().body(e.getMessage());
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 34d3127..5d2a2d8 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,2 +1,5 @@
spring.kafka.producer.properties.max.request.size=500000000 # Set the maximum request size for producer
spring.kafka.producer.properties.buffer.memory=1024000000 # Set the buffer memory for producer
+
+# ELK
+logging.config=classpath:logback-spring.xml
\ No newline at end of file
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..4418676
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,10 @@
+
+
+ 192.168.120.213:5060
+
+
+
+
+
+
+
\ No newline at end of file