mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 09:01:20 -08:00
Merge remote-tracking branch 'gui/main' into merge-gui-and-server
This commit is contained in:
commit
ae94de39b1
430 files changed
+44297
-50
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package io.eiren.util.logging;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class LoggerOutputStream extends ByteArrayOutputStream {
|
||||
|
||||
private static final String separator = System.getProperty("line.separator");
|
||||
|
||||
private final IGLog logger;
|
||||
private final Level level;
|
||||
private final String prefix;
|
||||
private final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
public LoggerOutputStream(IGLog logger, Level level) {
|
||||
this(logger, level, "");
|
||||
}
|
||||
|
||||
public LoggerOutputStream(IGLog logger, Level level, String prefix) {
|
||||
super();
|
||||
this.logger = logger;
|
||||
this.level = level;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
synchronized (this) {
|
||||
super.flush();
|
||||
String record = this.toString();
|
||||
super.reset();
|
||||
if (record.length() > 0) {
|
||||
buffer.append(record);
|
||||
if (record.contains(separator)) {
|
||||
String s = buffer.toString();
|
||||
String[] split = s.split(separator);
|
||||
for (int i = 0; i < split.length; ++i)
|
||||
logger.log(level, prefix + split[i]);
|
||||
buffer.setLength(0);
|
||||
// buffer.append(split[split.length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user