public class PrettyPrinter
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
PrettyPrinter.Alignment
Table column alignment
|
static interface |
PrettyPrinter.IPrettyPrintable
Interface for object which supports printing to pretty printer
|
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
kvFormat |
protected int |
kvKeyWidth
Key/value key width
|
protected int |
width
Box with (adapts to contents)
|
protected int |
wrapWidth
Wrap width used when an explicit wrap width is not specified
|
| Constructor and Description |
|---|
PrettyPrinter() |
PrettyPrinter(int width) |
| Modifier and Type | Method and Description |
|---|---|
PrettyPrinter |
add()
Adds a blank line to the output
|
PrettyPrinter |
add(java.util.Map<?,?> map)
Add all values of the specified map to this printer as key/value pairs
|
PrettyPrinter |
add(java.lang.Object object)
Adds the specified object to the output
|
PrettyPrinter |
add(java.lang.Object[] array)
Add elements of the array to the output, one per line
|
PrettyPrinter |
add(java.lang.Object[] array,
java.lang.String format)
Add elements of the array to the output, one per line
|
PrettyPrinter |
add(java.lang.Object object,
int indent)
Adds the specified object to the output
|
PrettyPrinter |
add(PrettyPrinter.IPrettyPrintable printable)
Adds a pretty-printable object to the output, the object is responsible
for adding its own representation to this printer
|
PrettyPrinter |
add(java.lang.StackTraceElement[] stackTrace,
int indent)
Print a formatted representation of the specified stack trace with the
specified indent
|
PrettyPrinter |
add(java.lang.String string)
Adds a string line to the output
|
PrettyPrinter |
add(java.lang.String format,
java.lang.Object... args)
Adds a formatted line to the output
|
PrettyPrinter |
add(java.lang.Throwable th)
Print a formatted representation of the specified throwable with the
default indent (4)
|
PrettyPrinter |
add(java.lang.Throwable th,
int indent)
Print a formatted representation of the specified throwable with the
specified indent
|
PrettyPrinter |
addIndexed(java.lang.Object[] array)
Add elements of the array to the output, one per line, with array indices
|
PrettyPrinter |
addWithIndices(java.util.Collection<?> c)
Add elements of the collection to the output, one per line, with indices
|
PrettyPrinter |
addWrapped(int width,
java.lang.String format,
java.lang.Object... args)
Adds a formatted line to the output, and attempts to wrap the line
content to the specified width
|
PrettyPrinter |
addWrapped(java.lang.String format,
java.lang.Object... args)
Adds a formatted line to the output, and attempts to wrap the line
content to the current wrap width
|
PrettyPrinter |
centre()
Centre the last line added
|
static void |
dumpStack()
Convenience method, alternative to using Thread.dumpStack which
prints to stderr in pretty-printed format.
|
PrettyPrinter |
hr()
Adds a horizontal rule to the output
|
PrettyPrinter |
hr(char ruleChar)
Adds a horizontal rule of the specified char to the output
|
PrettyPrinter |
kv(java.lang.String key,
java.lang.Object value)
Add a key/value pair to the output
|
PrettyPrinter |
kv(java.lang.String key,
java.lang.String format,
java.lang.Object... args)
Add a formatted key/value pair to the output
|
PrettyPrinter |
kvWidth(int width)
Set the minimum key display width
|
PrettyPrinter |
log(org.apache.logging.log4j.Logger logger)
Write this printer to the specified logger at
Level.INFO |
PrettyPrinter |
log(org.apache.logging.log4j.Logger logger,
org.apache.logging.log4j.Level level)
Write this printer to the specified logger
|
PrettyPrinter |
print()
Print this printer to stderr
|
PrettyPrinter |
print(java.io.PrintStream stream)
Print this printer to the specified output
|
static void |
print(java.lang.Throwable th)
Convenience methods, pretty-prints the specified throwable to stderr
|
PrettyPrinter |
spacing(int spacing)
Set the column spacing for the current table.
|
PrettyPrinter |
table()
Begin a new table with no header and adaptive column widths
|
PrettyPrinter |
table(java.lang.Object... format)
Begin a new table with the specified format.
|
PrettyPrinter |
table(java.lang.String... titles)
Begin a new table with the specified headers and adaptive column widths
|
PrettyPrinter |
th()
Print the current table header.
|
PrettyPrinter |
tr(java.lang.Object... args)
Print a table row with the specified values.
|
PrettyPrinter |
trace()
Outputs this printer to stderr and to a logger decorated with the calling
class name with level
Level.DEBUG |
PrettyPrinter |
trace(org.apache.logging.log4j.Level level)
Outputs this printer to stderr and to a logger decorated with the calling
class name at the specified level
|
PrettyPrinter |
trace(org.apache.logging.log4j.Logger logger)
Outputs this printer to stderr and to the supplied logger with level
Level.DEBUG |
PrettyPrinter |
trace(org.apache.logging.log4j.Logger logger,
org.apache.logging.log4j.Level level)
Outputs this printer to stderr and to the supplied logger with the
specified level
|
PrettyPrinter |
trace(java.io.PrintStream stream)
Outputs this printer to the specified stream and to a logger decorated
with the calling class name with level
Level.DEBUG |
PrettyPrinter |
trace(java.io.PrintStream stream,
org.apache.logging.log4j.Level level)
Outputs this printer to the specified stream and to a logger decorated
with the calling class name with the specified level
|
PrettyPrinter |
trace(java.io.PrintStream stream,
org.apache.logging.log4j.Logger logger)
Outputs this printer to the specified stream and to the supplied logger
with level
Level.DEBUG |
PrettyPrinter |
trace(java.io.PrintStream stream,
org.apache.logging.log4j.Logger logger,
org.apache.logging.log4j.Level level)
Outputs this printer to the specified stream and to the supplied logger
with at the specified level
|
PrettyPrinter |
trace(java.io.PrintStream stream,
java.lang.String logger)
Outputs this printer to the specified stream and to a logger with the
specified name with level
Level.DEBUG |
PrettyPrinter |
trace(java.io.PrintStream stream,
java.lang.String logger,
org.apache.logging.log4j.Level level)
Outputs this printer to the specified stream and to a logger with the
specified name at the specified level
|
PrettyPrinter |
trace(java.lang.String logger)
Outputs this printer to stderr and to a logger decorated with specified
name with level
Level.DEBUG |
PrettyPrinter |
trace(java.lang.String logger,
org.apache.logging.log4j.Level level)
Outputs this printer to stderr and to a logger decorated with specified
name with the specified level
|
int |
wrapTo()
Get the current wrap width
|
PrettyPrinter |
wrapTo(int wrapWidth)
Set the wrap width (default 80 columns)
|
protected int width
protected int wrapWidth
protected int kvKeyWidth
protected java.lang.String kvFormat
public PrettyPrinter()
public PrettyPrinter(int width)
public PrettyPrinter wrapTo(int wrapWidth)
wrapWidth - new width (in characters) to wrap topublic int wrapTo()
public PrettyPrinter table()
public PrettyPrinter table(java.lang.String... titles)
titles - Column titlespublic PrettyPrinter table(java.lang.Object... format)
Strings defining column titles,
Integers defining column widths, and PrettyPrinter.Alignments defining
column alignments. Widths and alignment specifiers should follow the
relevant column title. Specify a negative value to specify the
maximum width for a column (values will be truncated).
For example, to specify a table with two columns of width 10:
printer.table("Column 1", 10, "Column 2", 10);
A table with a column 30 characters wide and a right-aligned column 20 characters wide:
printer.table("Column 1", 30, "Column 2", 20, Alignment.RIGHT);
format - format string, see descriptionpublic PrettyPrinter spacing(int spacing)
spacing - Column spacing in characterspublic PrettyPrinter th()
public PrettyPrinter tr(java.lang.Object... args)
args - column valuespublic PrettyPrinter add()
public PrettyPrinter add(java.lang.String string)
string - format stringpublic PrettyPrinter add(java.lang.String format, java.lang.Object... args)
format - format stringargs - argumentspublic PrettyPrinter add(java.lang.Object[] array)
array - Array of objects to printpublic PrettyPrinter add(java.lang.Object[] array, java.lang.String format)
array - Array of objects to printformat - Format for each rowpublic PrettyPrinter addIndexed(java.lang.Object[] array)
array - Array of objects to printpublic PrettyPrinter addWithIndices(java.util.Collection<?> c)
c - Collection of objects to printpublic PrettyPrinter add(PrettyPrinter.IPrettyPrintable printable)
printable - object to addpublic PrettyPrinter add(java.lang.Throwable th)
th - Throwable to printpublic PrettyPrinter add(java.lang.Throwable th, int indent)
th - Throwable to printindent - Indent size for stacktrace linespublic PrettyPrinter add(java.lang.StackTraceElement[] stackTrace, int indent)
stackTrace - stack trace to printindent - Indent size for stacktrace linespublic PrettyPrinter add(java.lang.Object object)
object - object to addpublic PrettyPrinter add(java.lang.Object object, int indent)
object - object to addindent - indent amountpublic PrettyPrinter addWrapped(java.lang.String format, java.lang.Object... args)
format - format stringargs - argumentspublic PrettyPrinter addWrapped(int width, java.lang.String format, java.lang.Object... args)
width - wrap width to use for this contentformat - format stringargs - argumentspublic PrettyPrinter kv(java.lang.String key, java.lang.String format, java.lang.Object... args)
key - Keyformat - Value formatargs - Value argspublic PrettyPrinter kv(java.lang.String key, java.lang.Object value)
key - Keyvalue - Valuepublic PrettyPrinter kvWidth(int width)
width - width to setpublic PrettyPrinter add(java.util.Map<?,?> map)
map - Map with entries to addpublic PrettyPrinter hr()
public PrettyPrinter hr(char ruleChar)
ruleChar - character to use for the horizontal rulepublic PrettyPrinter centre()
public PrettyPrinter trace()
Level.DEBUGpublic PrettyPrinter trace(org.apache.logging.log4j.Level level)
level - Log level to write messagespublic PrettyPrinter trace(java.lang.String logger)
Level.DEBUGlogger - Logger name to write topublic PrettyPrinter trace(java.lang.String logger, org.apache.logging.log4j.Level level)
logger - Logger name to write tolevel - Log level to write messagespublic PrettyPrinter trace(org.apache.logging.log4j.Logger logger)
Level.DEBUGlogger - Logger to write topublic PrettyPrinter trace(org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level)
logger - Logger to write tolevel - Log level to write messagespublic PrettyPrinter trace(java.io.PrintStream stream)
Level.DEBUGstream - Output stream to print topublic PrettyPrinter trace(java.io.PrintStream stream, org.apache.logging.log4j.Level level)
stream - Output stream to print tolevel - Log level to write messagespublic PrettyPrinter trace(java.io.PrintStream stream, java.lang.String logger)
Level.DEBUGstream - Output stream to print tologger - Logger name to write topublic PrettyPrinter trace(java.io.PrintStream stream, java.lang.String logger, org.apache.logging.log4j.Level level)
stream - Output stream to print tologger - Logger name to write tolevel - Log level to write messagespublic PrettyPrinter trace(java.io.PrintStream stream, org.apache.logging.log4j.Logger logger)
Level.DEBUGstream - Output stream to print tologger - Logger to write topublic PrettyPrinter trace(java.io.PrintStream stream, org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level)
stream - Output stream to print tologger - Logger to write tolevel - Log level to write messagespublic PrettyPrinter print()
public PrettyPrinter print(java.io.PrintStream stream)
stream - stream to print topublic PrettyPrinter log(org.apache.logging.log4j.Logger logger)
Level.INFOlogger - logger to log topublic PrettyPrinter log(org.apache.logging.log4j.Logger logger, org.apache.logging.log4j.Level level)
logger - logger to log tolevel - log levelpublic static void dumpStack()
public static void print(java.lang.Throwable th)
th - Throwable to log