diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java index ec5fc462..5e834a9b 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java @@ -58,6 +58,9 @@ public int invoke(String... parameters) { + "' missing or cannot be read"); } + MaxSeverityLogHandler maxSeverityLogHandler = new MaxSeverityLogHandler(); + asciidoctor.registerLogHandler(maxSeverityLogHandler); + Options options = asciidoctorCliOptions.parse(); if (asciidoctorCliOptions.isRequire()) { @@ -72,7 +75,7 @@ public int invoke(String... parameters) { convertInput(asciidoctor, options, inputFiles); - if (asciidoctorCliOptions.getFailureLevel().compareTo(asciidoctor.getMaxSeverity()) <= 0) { + if (asciidoctorCliOptions.getFailureLevel().compareTo(maxSeverityLogHandler.getMaxSeverity()) <= 0) { return 1; } diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/MaxSeverityLogHandler.java b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/MaxSeverityLogHandler.java new file mode 100644 index 00000000..5cfdd504 --- /dev/null +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/MaxSeverityLogHandler.java @@ -0,0 +1,20 @@ +package org.asciidoctor.jruby.cli; + +import org.asciidoctor.log.LogHandler; +import org.asciidoctor.log.LogRecord; +import org.asciidoctor.log.Severity; + +public class MaxSeverityLogHandler implements LogHandler { + private Severity maxSeverity = Severity.DEBUG; + + @Override + public void log(LogRecord logRecord) { + if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) { + this.maxSeverity = logRecord.getSeverity(); + } + } + + public Severity getMaxSeverity() { + return this.maxSeverity; + } +} diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java index 4d561d17..ff85e1e2 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java @@ -22,7 +22,6 @@ import org.asciidoctor.jruby.syntaxhighlighter.internal.SyntaxHighlighterRegistryExecutor; import org.asciidoctor.log.LogHandler; import org.asciidoctor.log.LogRecord; -import org.asciidoctor.log.Severity; import org.asciidoctor.syntaxhighlighter.SyntaxHighlighterRegistry; import org.jruby.*; import org.jruby.exceptions.RaiseException; @@ -47,8 +46,6 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler { private List logHandlers = new ArrayList<>(); - private Severity maxSeverity = Severity.DEBUG; - public JRubyAsciidoctor() { this(createRubyRuntime(Collections.singletonMap(GEM_PATH, null), new ArrayList<>(), null)); processRegistrations(this); @@ -510,15 +507,8 @@ private RubyClass getExtensionGroupClass() { @Override public void log(LogRecord logRecord) { - if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) { - this.maxSeverity = logRecord.getSeverity(); - } for (LogHandler logHandler : logHandlers) { logHandler.log(logRecord); } } - - public Severity getMaxSeverity() { - return this.maxSeverity; - } }