-
Notifications
You must be signed in to change notification settings - Fork 249
add module id in log #2756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add module id in log #2756
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a module identifier to all log entries by capturing a user-defined name and including it in the log text.
- Removes the no-name
init(...)
overload inModuleInfoWorker
to require an explicit module name. - Introduces
moduleId
state and a setter inLoggerMaker
, and updatesinsert()
to prefix each log message with the module ID. - Updates the
Main
classes in both mini-testing and mini-runtime to pass and set the custom module name onLoggerMaker
.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
libs/utils/src/main/java/com/akto/metrics/ModuleInfoWorker.java | Removed the two-argument init(...) overload to enforce providing a module name. |
libs/utils/src/main/java/com/akto/log/LoggerMaker.java | Added moduleId field and setter; updated insert() to include [moduleId] in log messages. |
apps/mini-testing/src/main/java/com/akto/testing/Main.java | Calls loggerMaker.setModuleId(...) after initializing the module with a custom name. |
apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/Main.java | Generates or reads a service name, passes it to ModuleInfoWorker.init(...) , and sets it on loggerMaker . |
Comments suppressed due to low confidence (3)
libs/utils/src/main/java/com/akto/metrics/ModuleInfoWorker.java:53
- Removing this overload breaks backward compatibility for callers relying on the two-arg
init
method. Consider deprecating instead or providing a default name internally to avoid a breaking change.
}
libs/utils/src/main/java/com/akto/log/LoggerMaker.java:53
- There are no unit tests verifying that
moduleId
is correctly prefixed (and that null/empty values are handled). Consider adding tests forinsert()
to ensure consistent log output.
private String moduleId = "";
libs/utils/src/main/java/com/akto/log/LoggerMaker.java:53
- The mutable
moduleId
field is notvolatile
or synchronized, risking visibility issues across threads. Consider declaring itvolatile
or ensuring it's initialized before any worker threads start.
private String moduleId = "";
if (moduleId == null) { | ||
moduleId = ""; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This null check is redundant because moduleId
is initialized to an empty string. It may be clearer to enforce non-null in the setter and remove this guard.
if (moduleId == null) { | |
moduleId = ""; | |
} |
Copilot uses AI. Check for mistakes.
moduleId = ""; | ||
} | ||
|
||
String text = aClass + " : " + " [" + moduleId + " ] " + info; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The extra spaces inside the brackets lead to inconsistent log formatting. Consider simplifying to aClass + " : [" + moduleId + "] " + info
for clarity.
String text = aClass + " : " + " [" + moduleId + " ] " + info; | |
String text = aClass + " : [" + moduleId + "] " + info; |
Copilot uses AI. Check for mistakes.
No description provided.