2011-02-20 02:53:06 +01:00
|
|
|
package org.bukkit.craftbukkit;
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.IOException;
|
2013-11-04 14:07:38 +01:00
|
|
|
import org.apache.logging.log4j.Level;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2011-02-20 02:53:06 +01:00
|
|
|
|
|
|
|
public class LoggerOutputStream extends ByteArrayOutputStream {
|
|
|
|
private final String separator = System.getProperty("line.separator");
|
|
|
|
private final Logger logger;
|
|
|
|
private final Level level;
|
|
|
|
|
|
|
|
public LoggerOutputStream(Logger logger, Level level) {
|
|
|
|
super();
|
|
|
|
this.logger = logger;
|
|
|
|
this.level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void flush() throws IOException {
|
|
|
|
synchronized (this) {
|
|
|
|
super.flush();
|
|
|
|
String record = this.toString();
|
|
|
|
super.reset();
|
|
|
|
|
|
|
|
if ((record.length() > 0) && (!record.equals(separator))) {
|
2013-11-04 14:07:38 +01:00
|
|
|
logger.log(level, record);
|
2011-02-20 02:53:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|