Top Description Fields Constructors Methods
nonapi.io.github.classgraph.utils

public final Class LogNode

extends Object
Class Inheritance
Imports
java.io.PrintWriter, .StringWriter, java.text.DecimalFormat, .SimpleDateFormat, java.util.Calendar, .Collection, .Locale, .Map, .Map.Entry, java.util.concurrent.ConcurrentSkipListMap, java.util.concurrent.atomic.AtomicInteger, java.util.logging.Logger, io.github.classgraph.ClassGraph, nonapi.io.github.classgraph.classpath.SystemJarFinder

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

Modifier and TypeField and Description
private final Map<String, LogNode>
children

The child nodes of this log node.

private static final SimpleDateFormat
dateTimeFormatter

The date/time formatter (not threadsafe).

private long
elapsedTimeNanos

The time between when this log entry was created and addElapsedTime() was called.

private static final Logger
log

The logger.

private static boolean
logInRealtime

If true, log entries are output in realtime, as well as added to the LogNode tree.

private final String
msg

The log message.

private static final DecimalFormat
nanoFormatter

The elapsed time formatter.

private LogNode
parent

The parent LogNode.

private final String
sortKeyPrefix

The sort key prefix for deterministic ordering of log entries.

private static AtomicInteger
sortKeyUniqueSuffix

The sort key suffix for this log entry, used to make sort keys unique.

private String
stackTrace

The stacktrace, if this log entry was due to an exception.

private final long
timeStampMillis

The timestamp at which the log node was created, in epoch millis.

private final long
timeStampNano

The timestamp at which the log node was created (relative to some arbitrary system timepoint).

Constructor Summary

AccessConstructor and Description
private
LogNode(final String
the sort key
sortKey
,
final String
the log message
msg
,
final long
the elapsed time in nanos
elapsedTimeNanos
,
final Throwable
the exception that was thrown
exception
)

Create a non-toplevel log node.

public
LogNode()

Create a toplevel log node.

Method Summary

Modifier and TypeMethod and Description
private LogNode

Returns:

the log node
addChild
(final String
the sort key
sortKey
,
final String
the log message
msg
,
final long
the elapsed time in nanos
elapsedTimeNanos
,
final Throwable
the exception that was thrown
exception
)

Add a child log node.

private LogNode

Returns:

the log node
addChild
(final String
the sort key
sortKey
,
final String
the log message
msg
,
final long
the elapsed time in nanos
elapsedTimeNanos
)

Add a child log node for a message.

private LogNode

Returns:

the log node
addChild
(final Throwable
the exception that was thrown
exception
)

Add a child log node for an exception.

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.

private void
appendLine(final String
the timestamp string
timeStampStr
,
final int
the indent level
indentLevel
,
final String
the line to log
line
,
final StringBuilder
the buf
buf
)

Append a line to the log output, indenting this log entry according to tree structure.

public void
flush()

Flush out the log to stderr, and clear the log contents.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The sort key for the log entry.
sortKey
,
final String
The message.
msg
,
final long
The elapsed time.
elapsedTimeNanos
,
final Throwable
The Throwable that was thrown.
e
)

Add a log entry with sort key for deterministic ordering.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The sort key for the log entry.
sortKey
,
final String
The message.
msg
,
final long
The elapsed time.
elapsedTimeNanos
)

Add a log entry with sort key for deterministic ordering.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The sort key for the log entry.
sortKey
,
final String
The message.
msg
,
final Throwable
The Throwable that was thrown.
e
)

Add a log entry with sort key for deterministic ordering.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The sort key for the log entry.
sortKey
,
final String
The message.
msg
)

Add a log entry with sort key for deterministic ordering.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The message.
msg
,
final long
The elapsed time.
elapsedTimeNanos
,
final Throwable
The Throwable that was thrown.
e
)

Add a log entry.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The message.
msg
,
final long
The elapsed time.
elapsedTimeNanos
)

Add a log entry.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The message.
msg
,
final Throwable
The Throwable that was thrown.
e
)

Add a log entry.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final String
The message.
msg
)

Add a log entry.

public LogNode

Returns:

the last log node created, which can be used to add sub-entries.
log
(final Collection<String>
The messages.
msgs
)

Add a series of log entries.

public LogNode

Returns:

a child log node, which can be used to add sub-entries.
log
(final Throwable
The Throwable that was thrown.
e
)

Add a log entry.

public static void
logInRealtime(final boolean
whether to log in realtime
logInRealtime
)

If logInRealtime is true, log entries are output in realtime, as well as added to the LogNode tree.

private void
logJavaInfo()

Log the Java version and the JRE paths that were found.

private void
toString(final int
the indent level
indentLevel
,
final StringBuilder
the buf
buf
)

Recursively build the log output.

public String

Returns:

the string
toString
()

Overrides java.lang.Object.toString.

Build the log output.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

childrenback to summary
private final Map<String, LogNode> children

The child nodes of this log node.

dateTimeFormatterback to summary
private static final SimpleDateFormat dateTimeFormatter

The date/time formatter (not threadsafe).

elapsedTimeNanosback to summary
private long elapsedTimeNanos

The time between when this log entry was created and addElapsedTime() was called.

logback to summary
private static final Logger log

The logger.

logInRealtimeback to summary
private static boolean logInRealtime

If true, log entries are output in realtime, as well as added to the LogNode tree.

msgback to summary
private final String msg

The log message.

nanoFormatterback to summary
private static final DecimalFormat nanoFormatter

The elapsed time formatter.

parentback to summary
private LogNode parent

The parent LogNode.

sortKeyPrefixback to summary
private final String sortKeyPrefix

The sort key prefix for deterministic ordering of log entries.

sortKeyUniqueSuffixback to summary
private static AtomicInteger sortKeyUniqueSuffix

The sort key suffix for this log entry, used to make sort keys unique.

stackTraceback to summary
private String stackTrace

The stacktrace, if this log entry was due to an exception.

timeStampMillisback to summary
private final long timeStampMillis

The timestamp at which the log node was created, in epoch millis.

timeStampNanoback to summary
private final long timeStampNano

The timestamp at which the log node was created (relative to some arbitrary system timepoint).

Constructor Detail

LogNodeback to summary
private LogNode(final String sortKey, final String msg, final long elapsedTimeNanos, final Throwable exception)

Create a non-toplevel log node. The order may also be made deterministic by specifying a sort key for log entries.

Parameters
sortKey:String

the sort key

msg:String

the log message

elapsedTimeNanos:long

the elapsed time in nanos

exception:Throwable

the exception that was thrown

LogNodeback to summary
public LogNode()

Create a toplevel log node.

Method Detail

addChildback to summary
private LogNode addChild(final String sortKey, final String msg, final long elapsedTimeNanos, final Throwable exception)

Add a child log node.

Parameters
sortKey:String

the sort key

msg:String

the log message

elapsedTimeNanos:long

the elapsed time in nanos

exception:Throwable

the exception that was thrown

Returns:LogNode

the log node

addChildback to summary
private LogNode addChild(final String sortKey, final String msg, final long elapsedTimeNanos)

Add a child log node for a message.

Parameters
sortKey:String

the sort key

msg:String

the log message

elapsedTimeNanos:long

the elapsed time in nanos

Returns:LogNode

the log node

addChildback to summary
private LogNode addChild(final Throwable exception)

Add a child log node for an exception.

Parameters
exception:Throwable

the exception that was thrown

Returns:LogNode

the log node

addElapsedTimeback to summary
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.

appendLineback to summary
private void appendLine(final String timeStampStr, final int indentLevel, final String line, final StringBuilder buf)

Append a line to the log output, indenting this log entry according to tree structure.

Parameters
timeStampStr:String

the timestamp string

indentLevel:int

the indent level

line:String

the line to log

buf:StringBuilder

the buf

flushback to summary
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.

logback to summary
public LogNode log(final String sortKey, final String msg, final long elapsedTimeNanos, final Throwable e)

Add a log entry with sort key for deterministic ordering.

Parameters
sortKey:String

The sort key for the log entry.

msg:String

The message.

elapsedTimeNanos:long

The elapsed time.

e:Throwable

The Throwable that was thrown.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final String sortKey, final String msg, final long elapsedTimeNanos)

Add a log entry with sort key for deterministic ordering.

Parameters
sortKey:String

The sort key for the log entry.

msg:String

The message.

elapsedTimeNanos:long

The elapsed time.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final String sortKey, final String msg, final Throwable e)

Add a log entry with sort key for deterministic ordering.

Parameters
sortKey:String

The sort key for the log entry.

msg:String

The message.

e:Throwable

The Throwable that was thrown.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final String sortKey, final String msg)

Add a log entry with sort key for deterministic ordering.

Parameters
sortKey:String

The sort key for the log entry.

msg:String

The message.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final String msg, final long elapsedTimeNanos, final Throwable e)

Add a log entry.

Parameters
msg:String

The message.

elapsedTimeNanos:long

The elapsed time.

e:Throwable

The Throwable that was thrown.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final String msg, final long elapsedTimeNanos)

Add a log entry.

Parameters
msg:String

The message.

elapsedTimeNanos:long

The elapsed time.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final String msg, final Throwable e)

Add a log entry.

Parameters
msg:String

The message.

e:Throwable

The Throwable that was thrown.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final String msg)

Add a log entry.

Parameters
msg:String

The message.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logback to summary
public LogNode log(final Collection<String> msgs)

Add a series of log entries. Returns the last LogNode created.

Parameters
msgs:Collection<String>

The messages.

Returns:LogNode

the last log node created, which can be used to add sub-entries.

logback to summary
public LogNode log(final Throwable e)

Add a log entry.

Parameters
e:Throwable

The Throwable that was thrown.

Returns:LogNode

a child log node, which can be used to add sub-entries.

logInRealtimeback to summary
public static void logInRealtime(final 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:boolean

whether to log in realtime

logJavaInfoback to summary
private void logJavaInfo()

Log the Java version and the JRE paths that were found.

toStringback to summary
private void toString(final int indentLevel, final StringBuilder buf)

Recursively build the log output.

Parameters
indentLevel:int

the indent level

buf:StringBuilder

the buf

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Build the log output. Call this on the toplevel log node.

Returns:String

the string

Annotations
@Override