Skip to content

Commit

Permalink
Implement maxSeverity tracking on log handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pasieronen committed Sep 9, 2022
1 parent dac99a5 commit beb9f6b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,8 +46,6 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {

private List<LogHandler> logHandlers = new ArrayList<>();

private Severity maxSeverity = Severity.DEBUG;

public JRubyAsciidoctor() {
this(createRubyRuntime(Collections.singletonMap(GEM_PATH, null), new ArrayList<>(), null));
processRegistrations(this);
Expand Down Expand Up @@ -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;
}
}

0 comments on commit beb9f6b

Please sign in to comment.