-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af104d9
commit 1e37588
Showing
22 changed files
with
672 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
asciidoctorj-core/src/main/java/org/asciidoctor/log/LogHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.asciidoctor.log; | ||
|
||
public interface LogHandler { | ||
|
||
void log(LogRecord logRecord); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
asciidoctorj-core/src/main/java/org/asciidoctor/log/LogRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.asciidoctor.log; | ||
|
||
import org.asciidoctor.ast.Cursor; | ||
|
||
public class LogRecord { | ||
|
||
private final Severity severity; | ||
|
||
private final Cursor cursor; | ||
|
||
private final String message; | ||
|
||
private final String sourceFileName; | ||
|
||
private final String sourceMethodName; | ||
|
||
public LogRecord(Severity severity, Cursor cursor, String message, String sourceFileName, String sourceMethodName) { | ||
this.severity = severity; | ||
this.cursor = cursor; | ||
this.message = message; | ||
this.sourceFileName = sourceFileName; | ||
this.sourceMethodName = sourceMethodName; | ||
} | ||
|
||
public Severity getSeverity() { | ||
return severity; | ||
} | ||
|
||
public Cursor getCursor() { | ||
return cursor; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public String getSourceFileName() { | ||
return sourceFileName; | ||
} | ||
|
||
public String getSourceMethodName() { | ||
return sourceMethodName; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
asciidoctorj-core/src/main/java/org/asciidoctor/log/Severity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.asciidoctor.log; | ||
|
||
public enum Severity { | ||
DEBUG(0), | ||
INFO(1), | ||
WARN(2), | ||
ERROR(3), | ||
FATAL(4), | ||
UNKNOWN(5); | ||
|
||
private int rubyId; | ||
|
||
private Severity(final int rubyId) { | ||
this.rubyId = rubyId; | ||
} | ||
|
||
public int getRubyId() { | ||
return rubyId; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
asciidoctorj-core/src/main/java/org/asciidoctor/log/internal/JULLogHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.asciidoctor.log.internal; | ||
|
||
import org.asciidoctor.log.LogHandler; | ||
import org.asciidoctor.log.LogRecord; | ||
import org.asciidoctor.log.Severity; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class JULLogHandler implements LogHandler { | ||
|
||
private final static Logger LOGGER = Logger.getLogger("asciidoctor"); | ||
|
||
@Override | ||
public void log(LogRecord logRecord) { | ||
final java.util.logging.LogRecord julLogRecord = | ||
new java.util.logging.LogRecord( | ||
mapSeverity(logRecord.getSeverity()), | ||
logRecord.getCursor() != null ? logRecord.getCursor().toString() + ": " + logRecord.getMessage() : logRecord.getMessage()); | ||
|
||
julLogRecord.setSourceClassName(logRecord.getSourceFileName()); | ||
julLogRecord.setSourceMethodName(logRecord.getSourceMethodName()); | ||
julLogRecord.setParameters(new Object[] { logRecord.getCursor() }); | ||
LOGGER.log(julLogRecord); | ||
} | ||
|
||
private static Level mapSeverity(Severity severity) { | ||
switch (severity) { | ||
case DEBUG: | ||
return Level.FINEST; | ||
case INFO: | ||
return Level.INFO; | ||
case WARN: | ||
return Level.WARNING; | ||
case ERROR: | ||
return Level.SEVERE; | ||
case FATAL: | ||
return Level.SEVERE; | ||
case UNKNOWN: | ||
default: | ||
return Level.INFO; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.