Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
);
}
}
Original file line number Diff line number Diff line change
@@ -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\""));
}
}