All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.craftbukkit.LoggerOutputStream Maven / Gradle / Ivy

package org.bukkit.craftbukkit;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

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))) {
        logger.log(level, record);
      }
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy