Skip to content

Commit

Permalink
Fixes asciidoctor#299: Removed rerouting of System.out and System.err…
Browse files Browse the repository at this point in the history
… to JUL
  • Loading branch information
robertpanzer committed May 7, 2015
1 parent 8221e9a commit 3ad80f9
Showing 1 changed file with 0 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,6 @@

public class JRubyAsciidoctor implements Asciidoctor {

static {

final Logger logger = Logger.getLogger("Asciidoctor");
final LoggerOutputStream out = new LoggerOutputStream(logger);
System.setOut(new PrintStream(out));
System.setErr(new PrintStream(out));

Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try { // can log or not something depending logger is already closed or not, best is to call it manually at the end of main if possible
out.flush();
} catch (final IOException e) {
// no-op
}
}
});

}


private static final Logger logger = Logger.getLogger(JRubyAsciidoctor.class.getName());

private static final String GEM_PATH = "GEM_PATH";
Expand Down Expand Up @@ -622,56 +601,4 @@ public Document loadFile(File file, Map<String, Object> options) {
return new Document(this.asciidoctorModule.load(file.getAbsolutePath(), rubyHash), this.rubyRuntime);

}

static class LoggerOutputStream extends OutputStream {
private final StringBuilder builder = new StringBuilder();
private Logger logger;

public LoggerOutputStream(Logger logger) {
this.logger = logger;
}

private boolean doLog() {
synchronized(this) {
if (builder.length() > 0) {
String msg = builder.toString();
logger.info("My message: "+msg);
if(msg.contains("WARNING")) {
logger.logp(Level.WARNING, "", "", msg);
} else {
if(msg.contains("FAILED")) {
logger.logp(Level.SEVERE, "", "", msg);
} else {
logger.logp(Level.FINE, "", "", msg);
}
}
builder.setLength(0);
return true;
}
return false;
}
}

@Override
public void write(int b) throws IOException {
if (b == '\n') {
if (!doLog()) {
logger.info("");
}
} else {
builder.append((char) b);
}
}

@Override
public void flush() throws IOException {
doLog();
}

@Override
public void close() throws IOException {
doLog();
}
};

}

0 comments on commit 3ad80f9

Please sign in to comment.