Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Polishing #213
Browse files Browse the repository at this point in the history
Add author tags. Move currentThread lookup to caching section.

Original pull request: #214.
  • Loading branch information
mp911de committed Dec 3, 2019
1 parent 71bb0da commit 6533e5c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/main/java/biz/paluch/logging/gelf/jul/JulLogEvent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package biz.paluch.logging.gelf.jul;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.IllegalFormatException;
Expand All @@ -17,6 +14,7 @@

/**
* @author Mark Paluch
* @author Loïc Mathieu
* @since 26.09.13 15:22
*/
public class JulLogEvent implements LogEvent {
Expand Down Expand Up @@ -96,22 +94,25 @@ private String createMessage(LogRecord record) {
}

private String getThreadName(LogRecord record) {
if (record.getThreadID() == Thread.currentThread().getId()) {
return Thread.currentThread().getName();
}

String cacheKey = "" + record.getThreadID();
if (threadNameCache.containsKey(cacheKey)) {
return threadNameCache.get(cacheKey);
}

long threadId = record.getThreadID();
String threadName = "" + record.getThreadID();
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
for (Thread thread : threadSet) {
if (thread.getId() == threadId) {
threadName = thread.getName();
break;
String threadName = cacheKey;

Thread currentThread = Thread.currentThread();
if (record.getThreadID() == currentThread.getId()) {
threadName = currentThread.getName();
} else {
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
for (Thread thread : threadSet) {
if (thread.getId() == threadId) {
threadName = thread.getName();
break;
}
}
}

Expand Down

0 comments on commit 6533e5c

Please sign in to comment.