Class LogNode
java.lang.Object
nonapi.io.github.classgraph.utils.LogNode
A tree-structured threadsafe log that allows you to add log entries in arbitrary order, and have the output
retain a sane order. The order may also be made deterministic by specifying a sort key for log entries.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe child nodes of this log node.private static final SimpleDateFormatThe date/time formatter (not threadsafe).private longThe time between when this log entry was created and addElapsedTime() was called.private static final LoggerThe logger.private static booleanIf true, log entries are output in realtime, as well as added to the LogNode tree.private final StringThe log message.private static final DecimalFormatThe elapsed time formatter.private LogNodeThe parent LogNode.private final StringThe sort key prefix for deterministic ordering of log entries.private static AtomicIntegerThe sort key suffix for this log entry, used to make sort keys unique.private StringThe stacktrace, if this log entry was due to an exception.private final longThe timestamp at which the log node was created, in epoch millis.private final longThe timestamp at which the log node was created (relative to some arbitrary system timepoint). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate LogNodeAdd a child log node for a message.private LogNodeAdd a child log node.private LogNodeAdd a child log node for an exception.voidCall this once the work corresponding with a given log entry has completed if you want to show the time taken after the log entry.private voidappendLine(String timeStampStr, int indentLevel, String line, StringBuilder buf) Append a line to the log output, indenting this log entry according to tree structure.voidflush()Flush out the log to stderr, and clear the log contents.Add a log entry.Add a log entry.Add a log entry.Add a log entry with sort key for deterministic ordering.Add a log entry with sort key for deterministic ordering.Add a log entry with sort key for deterministic ordering.Add a log entry with sort key for deterministic ordering.Add a log entry.Add a log entry.log(Collection<String> msgs) Add a series of log entries.static voidlogInRealtime(boolean logInRealtime) If logInRealtime is true, log entries are output in realtime, as well as added to the LogNode tree.private voidLog the Java version and the JRE paths that were found.toString()Build the log output.private voidtoString(int indentLevel, StringBuilder buf) Recursively build the log output.
-
Field Details
-
log
The logger. -
timeStampNano
private final long timeStampNanoThe timestamp at which the log node was created (relative to some arbitrary system timepoint). -
timeStampMillis
private final long timeStampMillisThe timestamp at which the log node was created, in epoch millis. -
msg
The log message. -
stackTrace
The stacktrace, if this log entry was due to an exception. -
elapsedTimeNanos
private long elapsedTimeNanosThe time between when this log entry was created and addElapsedTime() was called. -
parent
The parent LogNode. -
children
The child nodes of this log node. -
sortKeyPrefix
The sort key prefix for deterministic ordering of log entries. -
sortKeyUniqueSuffix
The sort key suffix for this log entry, used to make sort keys unique. -
dateTimeFormatter
The date/time formatter (not threadsafe). -
nanoFormatter
The elapsed time formatter. -
logInRealtime
private static boolean logInRealtimeIf true, log entries are output in realtime, as well as added to the LogNode tree.
-
-
Constructor Details
-
LogNode
Create a non-toplevel log node. The order may also be made deterministic by specifying a sort key for log entries.- Parameters:
sortKey- the sort keymsg- the log messageelapsedTimeNanos- the elapsed time in nanosexception- the exception that was thrown
-
LogNode
public LogNode()Create a toplevel log node.
-
-
Method Details
-
logInRealtime
public static void logInRealtime(boolean logInRealtime) If logInRealtime is true, log entries are output in realtime, as well as added to the LogNode tree. This can help debug situations where log info is never shown, e.g. deadlocks, or where you need to show the log info right up to the point where you hit a breakpoint.- Parameters:
logInRealtime- whether to log in realtime
-
logJavaInfo
private void logJavaInfo()Log the Java version and the JRE paths that were found. -
appendLine
Append a line to the log output, indenting this log entry according to tree structure.- Parameters:
timeStampStr- the timestamp stringindentLevel- the indent levelline- the line to logbuf- the buf
-
toString
Recursively build the log output.- Parameters:
indentLevel- the indent levelbuf- the buf
-
toString
Build the log output. Call this on the toplevel log node. -
addElapsedTime
public void addElapsedTime()Call this once the work corresponding with a given log entry has completed if you want to show the time taken after the log entry. -
addChild
Add a child log node.- Parameters:
sortKey- the sort keymsg- the log messageelapsedTimeNanos- the elapsed time in nanosexception- the exception that was thrown- Returns:
- the log node
-
addChild
Add a child log node for a message.- Parameters:
sortKey- the sort keymsg- the log messageelapsedTimeNanos- the elapsed time in nanos- Returns:
- the log node
-
addChild
Add a child log node for an exception.- Parameters:
exception- the exception that was thrown- Returns:
- the log node
-
log
Add a log entry with sort key for deterministic ordering.- Parameters:
sortKey- The sort key for the log entry.msg- The message.elapsedTimeNanos- The elapsed time.e- TheThrowablethat was thrown.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a log entry with sort key for deterministic ordering.- Parameters:
sortKey- The sort key for the log entry.msg- The message.elapsedTimeNanos- The elapsed time.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a log entry with sort key for deterministic ordering.- Parameters:
sortKey- The sort key for the log entry.msg- The message.e- TheThrowablethat was thrown.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a log entry with sort key for deterministic ordering.- Parameters:
sortKey- The sort key for the log entry.msg- The message.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a log entry.- Parameters:
msg- The message.elapsedTimeNanos- The elapsed time.e- TheThrowablethat was thrown.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a log entry.- Parameters:
msg- The message.elapsedTimeNanos- The elapsed time.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a log entry.- Parameters:
msg- The message.e- TheThrowablethat was thrown.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a log entry.- Parameters:
msg- The message.- Returns:
- a child log node, which can be used to add sub-entries.
-
log
Add a series of log entries. Returns the last LogNode created.- Parameters:
msgs- The messages.- Returns:
- the last log node created, which can be used to add sub-entries.
-
log
Add a log entry.- Parameters:
e- TheThrowablethat was thrown.- Returns:
- a child log node, which can be used to add sub-entries.
-
flush
public void flush()Flush out the log to stderr, and clear the log contents. Only call this on the toplevel log node, when threads do not have access to references of internal log nodes so that they cannot add more log entries inside the tree, otherwise log entries may be lost.
-