public final class SimpleLog extends Object
| Modifier and Type | Field and Description |
|---|---|
boolean |
enabled
If false, do no output.
|
private @Nullable String |
filename
The file for logging output.
|
private String |
INDENT_STR_ONE_LEVEL
Indentation string for one level of indentation.
|
private int |
indentLevel
The current indentation level.
|
private @Nullable String |
indentString
Cache for the current indentation string, or null if needs to be recomputed.
|
private List<String> |
indentStrings
Cache of indentation strings that have been computed so far.
|
private @MonotonicNonNull PrintStream |
logfile
Where to write logging output.
|
| Constructor and Description |
|---|
SimpleLog()
Create a new SimpleLog object with logging to standard out enabled.
|
SimpleLog(boolean enabled)
Create a new SimpleLog object with logging to standard out.
|
SimpleLog(@Nullable String filename)
Create a new SimpleLog object with logging to a file enabled.
|
SimpleLog(@Nullable String filename,
boolean enabled)
Create a new SimpleLog object with logging to a file.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
enabled()
Return whether logging is enabled.
|
void |
exdent()
Decreases indentation by one level.
|
private String |
getIndentString()
Return the current indentation string.
|
void |
indent()
Increases indentation by one level.
|
void |
log(String format,
Object... args)
Log a message.
|
void |
logStackTrace()
Print a stack trace to the log.
|
void |
resetIndent()
Resets indentation to none.
|
private void |
setLogfile()
Set the private field logfile, based on the private field
filename. |
public boolean enabled
private @MonotonicNonNull PrintStream logfile
private @Nullable String filename
private int indentLevel
private final String INDENT_STR_ONE_LEVEL
private @Nullable String indentString
getIndentString().public SimpleLog()
public SimpleLog(boolean enabled)
enabled - whether the logger starts out enabledpublic SimpleLog(@Nullable String filename)
filename - file name, or use "-" or null for System.outpublic SimpleLog(@Nullable String filename, boolean enabled)
filename - file name, or use "-" or null for System.outenabled - whether the logger starts out enabledpublic boolean enabled()
@EnsuresNonNull(value="logfile") private void setLogfile()
filename.
This creates the file if it does not exist. This should be called lazily, when output is performed. Otherwise, it would be annoying to create a zero-size logfile if no output is ever written.
@FormatMethod public void log(String format, Object... args)
format - format string for messageargs - values to be substituted into formatpublic void logStackTrace()
private String getIndentString()
public void indent()
public void exdent()
public void resetIndent()