Skip to content

Commit ce6b014

Browse files
committed
ELK update
1 parent d6a2e33 commit ce6b014

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@
7979
</dependency>
8080

8181

82+
<dependency>
83+
<groupId>net.logstash.logback</groupId>
84+
<artifactId>logstash-logback-encoder</artifactId>
85+
<version>7.0.1</version>
86+
</dependency>
87+
8288

89+
8390
</dependencies>
8491
<build>
8592
<plugins>

src/main/java/com/programming/commentService/controller/CommentController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
import org.springframework.web.bind.annotation.RequestBody;
2828
import lombok.AllArgsConstructor;
2929

30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
import org.slf4j.MDC;
33+
3034
@RestController
3135
@RequestMapping("/comment")
3236
@AllArgsConstructor
@@ -39,11 +43,15 @@ public class CommentController {
3943

4044
private final CommentRepository commentRepository;
4145

46+
private static final Logger logger = LoggerFactory.getLogger(CommentController.class);
47+
4248
@Autowired
4349
private CommentService commentService;
4450

4551
@GetMapping("/")
4652
public String getServiceName() {
53+
MDC.put("type", "commentservice");
54+
logger.info("Comment Service Start");
4755
return "Comment Service";
4856
}
4957

@@ -100,6 +108,14 @@ public ResponseEntity<?> uploadComment(@RequestBody Comment comment) {
100108

101109
// Lưu comment đã xử lý vào MongoDB
102110
Comment savedComment = commentRepository.save(sanitizedComment);
111+
112+
//ELK
113+
MDC.put("type", "commentservice");
114+
MDC.put("action", "upload");
115+
logger.info("CommentId: " + savedComment.getId());
116+
logger.info("VideoId: " + comment.getVideoId());
117+
logger.info("UserId: " + comment.getUserId());
118+
103119
return ResponseEntity.ok(savedComment);
104120
} catch (Exception e) {
105121
return ResponseEntity.internalServerError().body(e.getMessage());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
spring.kafka.producer.properties.max.request.size=500000000 # Set the maximum request size for producer
22
spring.kafka.producer.properties.buffer.memory=1024000000 # Set the buffer memory for producer
3+
4+
# ELK
5+
logging.config=classpath:logback-spring.xml
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<configuration>
2+
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
3+
<destination>192.168.120.213:5060</destination>
4+
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
5+
</encoder>
6+
</appender>
7+
<root level="INFO">
8+
<appender-ref ref="LOGSTASH"/>
9+
</root>
10+
</configuration>

0 commit comments

Comments
 (0)