diff --git a/src/main/java/com/github/ignorant05/log_processing_system/LogEntry.java b/src/main/java/com/github/ignorant05/log_processing_system/LogEntry.java new file mode 100644 index 0000000..351f113 --- /dev/null +++ b/src/main/java/com/github/ignorant05/log_processing_system/LogEntry.java @@ -0,0 +1,32 @@ +package com.github.ignorant05.log_processing_system; + +import java.time.Instant; +import java.util.UUID; + +public class LogEntry { + private String id; + private String level; + private String message; + private String timestamp; + + public LogEntry(String level, String message) { + this.id = UUID.randomUUID().toString(); + this.level = level; + this.message = message; + this.timestamp = Instant.now().toString(); + } + + // Getters + public String getId() { return id; } + public String getLevel() { return level; } + public String getMessage() { return message; } + public String getTimestamp() { return timestamp; } + + // Serialization for the task + public String toJson() { + return String.format( + "{\"id\":\"%s\", \"level\":\"%s\", \"message\":\"%s\", \"timestamp\":\"%s\"}", + id, level, message, timestamp + ); + } +} diff --git a/src/test/java/com/github/ignorant05/log_processing_system/LogEntryTest.java b/src/test/java/com/github/ignorant05/log_processing_system/LogEntryTest.java new file mode 100644 index 0000000..e449755 --- /dev/null +++ b/src/test/java/com/github/ignorant05/log_processing_system/LogEntryTest.java @@ -0,0 +1,21 @@ +package com.github.ignorant05.log_processing_system; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class LogEntryTest { + + @Test + void testLogEntryCreation() { + LogEntry log = new LogEntry("INFO", "Test log message"); + assertNotNull(log.getId()); + assertEquals("INFO", log.getLevel()); + } + + @Test + void testJsonFormat() { + LogEntry log = new LogEntry("DEBUG", "JSON check"); + String json = log.toJson(); + assertTrue(json.contains("\"level\":\"DEBUG\"")); + } +}