blob: 372ad42af3b7b046e70e51d09d41c038b5f1f2d6 [file] [log] [blame]
package annotations.io;
import java.io.PrintWriter;
import java.util.logging.Level;
/**
* @author dbro
*/
public class DebugWriter {
private PrintWriter out = new PrintWriter(System.out);
private Level level = Level.WARNING;
public DebugWriter or(final DebugWriter other) {
return new DebugWriter() {
@Override
public boolean isEnabled() {
return super.isEnabled() || other.isEnabled();
}
};
}
public static boolean anyEnabled(DebugWriter... debugs) {
for (DebugWriter debug : debugs) {
if (debug.isEnabled()) { return true; }
}
return false;
}
public boolean isEnabled() {
return level == Level.INFO;
}
public void setEnabled(boolean enabled) {
level = enabled ? Level.INFO : Level.WARNING;
}
public void debug(String format, Object... args) {
if (isEnabled()) {
out.print(String.format(format, args));
out.flush();
}
}
}