From ce6b014a430cd87a274efd328d168147e95b9496 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?T=E1=BA=A1=20=C4=90=E1=BB=A9c=20B=E1=BA=A3o?=
<146197243+DucBaoUIT@users.noreply.github.com>
Date: Fri, 13 Dec 2024 10:31:43 +0700
Subject: [PATCH] ELK update
---
pom.xml | 7 +++++++
.../controller/CommentController.java | 16 ++++++++++++++++
src/main/resources/application.properties | 3 +++
src/main/resources/logback-spring.xml | 10 ++++++++++
4 files changed, 36 insertions(+)
create mode 100644 src/main/resources/logback-spring.xml
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