-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 threadId to PatternLayout #710
Comments
Unlike platform threads, virtual threads do not return a name unless explicitly set. From the javadoc:
Given that libraries and frameworks (e.g. Spring) create virtual threads but don't explicitly set a name, the logs don't contain any thread name which affects the troubleshooting experience. Another solution could perhaps be to synthesize a thread name, something like: public String getThreadName() {
if (this.threadName == null) {
final Thread currentThread = Thread.currentThread();
if (currentThread.getName() != null) {
this.threadName = currentThread.getName();
} else if (currentThread.isVirtual()) { // replace with the reflective call when building with older JDKs
this.threadName = "virtual-thread-" + currentThread.threadId();
} else {
this.threadName = "unnamed-" + currentThread.threadId();
}
}
return this.threadName;
} @ceki any thoughts on this? |
@danishnawab Thank you for the proposal. See commit 5a36133 |
That's amazing @ceki, thank you! |
It seems that the build failed for some (apparently) temporary errors. Could this be retried? It would be very useful to have this now that Spring Boot has support for virtual threads. |
This is part of 1.5 now. I think this can be closed? |
Given the project already supports printing the current thread name, it should also be able to retrieve the
threadId
.This would be useful when dealing with virtual threads, I noticed that ones created via
Executors.newVirtualThreadPerTaskExecutor()
don't have a name and they would be shown as an empty string:The text was updated successfully, but these errors were encountered: