forked from Luohuayu/CatServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package catserver.server.utils; | ||
|
||
import com.mojang.util.QueueLogAppender; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.locks.ReadWriteLock; | ||
|
||
public class Log4jUitls { | ||
public static void flush() { | ||
try { | ||
Field filed_QUEUES = QueueLogAppender.class.getDeclaredField("QUEUES"); | ||
filed_QUEUES.setAccessible(true); | ||
|
||
Field filed_QUEUE_LOCK = QueueLogAppender.class.getDeclaredField("QUEUE_LOCK"); | ||
filed_QUEUE_LOCK.setAccessible(true); | ||
|
||
Map<String, BlockingQueue<String>> QUEUES = (Map<String, BlockingQueue<String>>) filed_QUEUES.get(null); | ||
ReadWriteLock QUEUE_LOCK = (ReadWriteLock) filed_QUEUE_LOCK.get(null); | ||
|
||
QUEUE_LOCK.readLock().lock(); | ||
final BlockingQueue<String> queue = QUEUES.get("TerminalConsole"); | ||
if (queue != null) { | ||
String message; | ||
while ((message = queue.poll()) != null) { | ||
System.out.write(message.getBytes()); | ||
System.out.flush(); | ||
} | ||
} | ||
QUEUE_LOCK.readLock().unlock(); | ||
} catch (Exception ignored) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters