Skip to content

feat: implement LogEntry model and pass unit tests#8

Open
ANKUSHG11 wants to merge 1 commit intoignorant05:mainfrom
ANKUSHG11:main
Open

feat: implement LogEntry model and pass unit tests#8
ANKUSHG11 wants to merge 1 commit intoignorant05:mainfrom
ANKUSHG11:main

Conversation

@ANKUSHG11
Copy link
Copy Markdown

I have implemented the LogEntry class and added unit tests as requested in the issue. All tests passed locally.

Copy link
Copy Markdown
Owner

@ignorant05 ignorant05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it is still doesn't conform with the intended use, you need just some little tweaks and it'll pas.
And the best practice is to separate to use two commit:

  • One for LogEntry class and it's unit tests
  • One for JsonUtil class and it's unit tests.
    so that it becomes more organized.
    Thanks for your work, much appreciated.

private String message;
private String timestamp;

public LogEntry(String level, String message) {
Copy link
Copy Markdown
Owner

@ignorant05 ignorant05 Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far, it is good but i'd like to add a bit more attributes and modify some:

	private String id; // this is good
   private Instant timestamp; // i'd like it to be of type Instant, so don't toString it
	private String level; // this is good
	private String service; // i like the logs to be more specific, i.g; adding the exact source/service of the log in microservices architecture
	private String message; // this is good
	private String userID; // i'd like it to be more user specific too
	private String ipAddr; // the ip address is needed for potential network troubleshooting need or geographical specific log tracking
	private int durationMS; // this is needed for performance monitoring, to know how long the logging operation took

this.timestamp = Instant.now().toString();
}

// Getters
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update getters to match the intended attributes and their type.

this.message = message;
this.timestamp = Instant.now().toString();
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For potential need, can you please add setters too ?

public String getTimestamp() { return timestamp; }

// Serialization for the task
public String toJson() {
Copy link
Copy Markdown
Owner

@ignorant05 ignorant05 Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good for a tarting point, but i wish that you can migrate it to ./src/main/java/com/github/ignorant05/log_processing_system/util/JsonUtil.java and add it's own unit tests in the ./src/test/java/com/github/ignorant05/log_processing_system/util/JsonUtilTest.java file

Note: if you run into a problem with this and didn't understand how will it work, you can either ask me and i'll help you out.

"{\"id\":\"%s\", \"level\":\"%s\", \"message\":\"%s\", \"timestamp\":\"%s\"}",
id, level, message, timestamp
);
}
Copy link
Copy Markdown
Owner

@ignorant05 ignorant05 Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd like to add more methods to the main LogEntry class, since it is merely hardcoded data, i wish that you can:

  • Override the equals method which takes an object of type Object (import this : java.util.Objects) and compare each attribute with the current instance,
  • Override hashcode method, it returns a hashed version of the current set of attribute values, use Objects.hash method for this.
  • Override toString method, to return it in a more custom format, i predfer if you separate each attribute/value combination with a new line and add an indentation at each one's begginng.
  • Add more unit tests to test the intended results with each one, i want these kind of unit tests, shouldCreateLogEntryWithConstructor(), shouldSetAndGetFields(), shouldImplementEqualsAndHashCode(), shouldProduceValidStringRepresentation()and shouldCreateLogEntryWithBuilder(), you can add more if you want, but do tell me why about it's utility and why you see it is needed.

private String level;
private String message;
private String timestamp;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a default empty constructor here please.

public String getLevel() { return level; }
public String getMessage() { return message; }
public String getTimestamp() { return timestamp; }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a builder class to avoid the pain that comes with setters :
here's a snippet of what i want it to be like, and don't forget the unit tests please, even a single one for this suffices, but this is much needed.

	public static Builder builder() {
		return new Builder();
	}

	public static class Builder {
		private String id;
		private Instant timestamp;
		private String level;
		private String service;
		private String message;
		private String userID;
		private String ipAddr;
		private int durationMS;

		public Builder id(String id) {
			this.id = id;
			return this;
		}

		public Builder timestamp(Instant timestamp) {
			this.timestamp = timestamp;
			return this;
		}

		public Builder level(String level) {
			this.level = level;
			return this;
		}

		public Builder service(String service) {
			this.service = service;
			return this;
		}

		public Builder message(String message) {
			this.message = message;
			return this;
		}

		public Builder userID(String userID) {
			this.userID = userID;
			return this;
		}

		public Builder ipAddr(String ipAddr) {
			this.ipAddr = ipAddr;
			return this;
		}

		public Builder durationMS(int durationMS) {
			this.durationMS = durationMS;
			return this;
		}

		public LogEntry build() {
			return new LogEntry(id, timestamp, level, service, message, userID, ipAddr, durationMS);
		}
	}

@ANKUSHG11
Copy link
Copy Markdown
Author

ANKUSHG11 commented Feb 7, 2026 via email

@ignorant05
Copy link
Copy Markdown
Owner

ignorant05 commented Feb 7, 2026

Hi @ANKUSHG11, i appreciate you enthusiasm about contributing to the project, and i am not demanding many things, for now, you can just try to implement what you can gasp from the feedback i wrote earlier and i'll take it from there, you'll save me sometime by doing that.

Again, i much appreciate your contribution, feel free to see future issues and try your best if you want.

@ANKUSHG11
Copy link
Copy Markdown
Author

ANKUSHG11 commented Feb 7, 2026 via email

@ignorant05
Copy link
Copy Markdown
Owner

It's fine, looking forward for your contribution in the future.

@ANKUSHG11
Copy link
Copy Markdown
Author

ANKUSHG11 commented Feb 7, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants