Package org.refcodes.logger.alt.console
Class AbstractConsoleLogger<T>
java.lang.Object
org.refcodes.logger.alt.console.AbstractConsoleLogger<T>
- Type Parameters:
T- The type of theRecordinstances managed by theLogger.
- All Implemented Interfaces:
org.refcodes.component.Destroyable,org.refcodes.logger.LogDecorator,org.refcodes.logger.Logger<T>,org.refcodes.mixin.ErrorPrintStreamAccessor,org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamBuilder<AbstractConsoleLogger<T>>,org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamMutator,org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamProperty,org.refcodes.mixin.RowWidthAccessor,org.refcodes.mixin.RowWidthAccessor.RowWidthBuilder<AbstractConsoleLogger<?>>,org.refcodes.mixin.RowWidthAccessor.RowWidthMutator,org.refcodes.mixin.RowWidthAccessor.RowWidthProperty,org.refcodes.mixin.StandardPrintStreamAccessor,org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamBuilder<AbstractConsoleLogger<T>>,org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamMutator,org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamProperty,org.refcodes.textual.TableStyleAccessor,org.refcodes.textual.TableStyleAccessor.TableStyleBuilder<AbstractConsoleLogger<?>>,org.refcodes.textual.TableStyleAccessor.TableStyleMutator,org.refcodes.textual.TableStyleAccessor.TableStyleProperty
- Direct Known Subclasses:
ConsoleLogger
public abstract class AbstractConsoleLogger<T>
extends Object
implements org.refcodes.component.Destroyable, org.refcodes.logger.Logger<T>, org.refcodes.mixin.RowWidthAccessor.RowWidthProperty, org.refcodes.mixin.RowWidthAccessor.RowWidthBuilder<AbstractConsoleLogger<?>>, org.refcodes.textual.TableStyleAccessor.TableStyleProperty, org.refcodes.textual.TableStyleAccessor.TableStyleBuilder<AbstractConsoleLogger<?>>, org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamProperty, org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamBuilder<AbstractConsoleLogger<T>>, org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamProperty, org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamBuilder<AbstractConsoleLogger<T>>
The
AbstractConsoleLogger implements the Logger interface for
providing logging functionality with extended pimped console output (via
System.out and (via sub-classing also System.err).
The AbstractConsoleLogger by default uses the most promising width in
characters of the system's terminal in use by calling the method
SystemUtility.toPreferredTerminalWidth(). In case you pass a
"-Dconsole.width=n" JVM argument, then your width is taken, else the actual
console's width is being tried to be determined. See
SystemProperty.CONSOLE_WIDTH. You can also use the
setRowWidth(int) or withRowWidth(int) method in order to
programmatically set the console's row width.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe Enum OutputPrintStream.Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable
org.refcodes.component.Destroyable.DestroyAutomatonNested classes/interfaces inherited from interface org.refcodes.mixin.ErrorPrintStreamAccessor
org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamBuilder<B extends org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamBuilder<?>>, org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamMutator, org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamPropertyNested classes/interfaces inherited from interface org.refcodes.mixin.RowWidthAccessor
org.refcodes.mixin.RowWidthAccessor.RowWidthBuilder<B extends org.refcodes.mixin.RowWidthAccessor.RowWidthBuilder<?>>, org.refcodes.mixin.RowWidthAccessor.RowWidthMutator, org.refcodes.mixin.RowWidthAccessor.RowWidthPropertyNested classes/interfaces inherited from interface org.refcodes.mixin.StandardPrintStreamAccessor
org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamBuilder<B extends org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamBuilder<?>>, org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamMutator, org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamPropertyNested classes/interfaces inherited from interface org.refcodes.textual.TableStyleAccessor
org.refcodes.textual.TableStyleAccessor.TableStyleBuilder<B extends org.refcodes.textual.TableStyleAccessor.TableStyleBuilder<?>>, org.refcodes.textual.TableStyleAccessor.TableStyleMutator, org.refcodes.textual.TableStyleAccessor.TableStyleProperty -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PrintStreamprotected booleanprotected booleanprotected booleanprotected org.refcodes.tabular.FormattedHeader<T>protected booleanprotected booleanprotected intprotected PrintStreamprotected org.refcodes.textual.TableBuilderprotected org.refcodes.textual.TableStyleprotected StringThe default ANSI Escape-Sequence for the logger's box grid to be used when ANSI Escape-Codes are enabled. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractConsoleLogger(org.refcodes.tabular.FormattedHeader<T> aHeader) Initially enables or disables ANSI escape sequences as of detection of terminal's ANSI support. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()intorg.refcodes.textual.TableStylebooleanChecks for escape codes.booleanChecks for left border.booleanChecks for right border.protected voidinit()Initializes the logger.voidprotected voidlog(org.refcodes.tabular.Record<? extends T> aRecord, org.refcodes.tabular.FormattedHeader<T> aHeader, org.refcodes.textual.TableBuilder aTableBuilder) Prints out a log-line with regard to the providedHeaderunsing the providedTableBuilder.voidvoidvoidvoidsetErrorPrintStream(PrintStream aErrStream) voidsetEscapeCodes(boolean isEscCodesEnabled) Sets the escape codes.voidsetLeftBorder(boolean hasLeftBorder) Sets the left border.voidsetLoggerStyle(String aTableStyleName) As the underlying configuration framework used by theRuntimeLoggerSingletoncannot convert a String to an enum, we got to provide such a method ourselves.voidsetRightBorder(boolean hasRightBorder) Sets the right border.voidsetRowWidth(int aRowWidth) voidsetStandardPrintStream(PrintStream aOutStream) voidConvenience method forsetLoggerStyle(String): As the underlying configuration framework used by theRuntimeLoggerSingletoncannot convert a String to an enum, we got to provide such a method ourselves.voidsetTableStyle(org.refcodes.textual.TableStyle aTableStyle) protected org.refcodes.textual.TableBuildertoPreConfiguredTableBuilder(org.refcodes.tabular.FormattedHeader<?> aHeader, AbstractConsoleLogger.OutputPrintStream aOutputPrintStream) Creates a preconfiguredTableBuilder, can be used by sub-classes in case them require additionalTableBuilderinstances.withErrorPrintStream(PrintStream aErrorPrintStream) withEscapeCodes(boolean isEscCodesEnabled) With escape codes.withLeftBorder(boolean hasLeftBorder) With left border.withRightBorder(boolean hasRightBorder) With right border.withRowWidth(int aRowWidth) withStandardPrintStream(PrintStream aStandardPrintStream) withTableStyle(org.refcodes.textual.TableStyle aTableStyle) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamProperty
letErrorPrintStreamMethods inherited from interface org.refcodes.mixin.RowWidthAccessor.RowWidthProperty
letRowWidthMethods inherited from interface org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamProperty
letStandardPrintStreamMethods inherited from interface org.refcodes.textual.TableStyleAccessor.TableStyleProperty
letTableStyle
-
Field Details
-
DEFAULT_ANSI_BOX_GRID_COLOR
The default ANSI Escape-Sequence for the logger's box grid to be used when ANSI Escape-Codes are enabled. -
_isPrintHead
protected boolean _isPrintHead -
_isPrintSeparator
protected boolean _isPrintSeparator -
_hasLogLines
protected boolean _hasLogLines -
_header
-
_tableBuilder
protected org.refcodes.textual.TableBuilder _tableBuilder -
_stdStream
-
_errStream
-
_rowWidth
protected int _rowWidth -
_tableStyle
protected org.refcodes.textual.TableStyle _tableStyle -
_hasLeftBorder
protected boolean _hasLeftBorder -
_hasRightBorder
protected boolean _hasRightBorder
-
-
Constructor Details
-
AbstractConsoleLogger
Initially enables or disables ANSI escape sequences as of detection of terminal's ANSI support. You can overrule this setting by callingsetEscapeCodes(boolean). See alsoSystemUtility.isAnsiTerminal().- Parameters:
aHeader- the header
-
-
Method Details
-
log
- Specified by:
login interfaceorg.refcodes.logger.Logger<T>
-
getStandardPrintStream
- Specified by:
getStandardPrintStreamin interfaceorg.refcodes.mixin.StandardPrintStreamAccessor
-
setStandardPrintStream
- Specified by:
setStandardPrintStreamin interfaceorg.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamMutator
-
getErrorPrintStream
- Specified by:
getErrorPrintStreamin interfaceorg.refcodes.mixin.ErrorPrintStreamAccessor
-
setErrorPrintStream
- Specified by:
setErrorPrintStreamin interfaceorg.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamMutator
-
setStyle
Convenience method forsetLoggerStyle(String): As the underlying configuration framework used by theRuntimeLoggerSingletoncannot convert a String to an enum, we got to provide such a method ourselves. When configuring programmatically usesetTableStyle(TableStyle), when using the "runtimelogger-config.xml" use the property "loggerStyle" for this method to be invoked. Valid arguments are as of theTableStyleenumeration:- SINGLE_HEADER_SINGLE_BODY
- DOUBLE_SINGLE_HEADER_SINGLE_BODY
- DOUBLE_HEADER_DOUBLE_BODY
- DOUBLE_SINGLE_HEADER_DOUBLE_SINGLE_BODY
- DOUBLE_HEADER_SINGLE_BODY
- DOUBLE_HEADER_DOUBLE_SINGLE_BODY
- DOUBLE_SINGLE_HEADER_SINGLE_DASHED_BODY
- ASCII_HEADER_ASCII_BODY
- BLANK_HEADER_BLANK_BODY
- SINGLE_BLANK_HEADER_SINGLE_BLANK_BODY
- ASCII_BLANK_HEADER_ASCII_BLANK_BODY
- Parameters:
aTableStyle- The style to use for the logger.
-
getTableStyle
public org.refcodes.textual.TableStyle getTableStyle()- Specified by:
getTableStylein interfaceorg.refcodes.textual.TableStyleAccessor
-
setTableStyle
public void setTableStyle(org.refcodes.textual.TableStyle aTableStyle) - Specified by:
setTableStylein interfaceorg.refcodes.textual.TableStyleAccessor.TableStyleMutator
-
setLoggerStyle
As the underlying configuration framework used by theRuntimeLoggerSingletoncannot convert a String to an enum, we got to provide such a method ourselves. When configuring programmatically usesetTableStyle(TableStyle), when using the "runtimelogger-config.xml" use the property "loggerStyle" for this method to be invoked. Valid arguments are as of theTableStyleenumeration:- SINGLE_HEADER_SINGLE_BODY
- DOUBLE_SINGLE_HEADER_SINGLE_BODY
- DOUBLE_HEADER_DOUBLE_BODY
- DOUBLE_SINGLE_HEADER_DOUBLE_SINGLE_BODY
- DOUBLE_HEADER_SINGLE_BODY
- DOUBLE_HEADER_DOUBLE_SINGLE_BODY
- DOUBLE_SINGLE_HEADER_SINGLE_DASHED_BODY
- ASCII_HEADER_ASCII_BODY
- BLANK_HEADER_BLANK_BODY
- SINGLE_BLANK_HEADER_SINGLE_BLANK_BODY
- ASCII_BLANK_HEADER_ASCII_BLANK_BODY
- Parameters:
aTableStyleName- The style to use for the logger.
-
setEscapeCodes
public void setEscapeCodes(boolean isEscCodesEnabled) Sets the escape codes.- Parameters:
isEscCodesEnabled- the new escape codes
-
hasLeftBorder
public boolean hasLeftBorder()Checks for left border.- Returns:
- true, if successful
-
setLeftBorder
public void setLeftBorder(boolean hasLeftBorder) Sets the left border.- Parameters:
hasLeftBorder- the new left border
-
withLeftBorder
With left border.- Parameters:
hasLeftBorder- the has left border- Returns:
- the formatted logger
-
hasRightBorder
public boolean hasRightBorder()Checks for right border.- Returns:
- true, if successful
-
setRightBorder
public void setRightBorder(boolean hasRightBorder) Sets the right border.- Parameters:
hasRightBorder- the new right border
-
withRightBorder
With right border.- Parameters:
hasRightBorder- the has right border- Returns:
- the formatted logger
-
withErrorPrintStream
- Specified by:
withErrorPrintStreamin interfaceorg.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamBuilder<T>
-
withStandardPrintStream
- Specified by:
withStandardPrintStreamin interfaceorg.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamBuilder<T>
-
withTableStyle
- Specified by:
withTableStylein interfaceorg.refcodes.textual.TableStyleAccessor.TableStyleBuilder<T>
-
withRowWidth
- Specified by:
withRowWidthin interfaceorg.refcodes.mixin.RowWidthAccessor.RowWidthBuilder<T>
-
getRowWidth
public int getRowWidth()- Specified by:
getRowWidthin interfaceorg.refcodes.mixin.RowWidthAccessor
-
setRowWidth
public void setRowWidth(int aRowWidth) - Specified by:
setRowWidthin interfaceorg.refcodes.mixin.RowWidthAccessor.RowWidthMutator
-
hasEscapeCodes
public boolean hasEscapeCodes()Checks for escape codes.- Returns:
- true, if successful
-
withEscapeCodes
With escape codes.- Parameters:
isEscCodesEnabled- the is esc codes enabled- Returns:
- the formatted logger
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.refcodes.component.Destroyable
-
init
protected void init()Initializes the logger. -
printSeparator
public void printSeparator()- Specified by:
printSeparatorin interfaceorg.refcodes.logger.LogDecorator
-
printTail
public void printTail()- Specified by:
printTailin interfaceorg.refcodes.logger.LogDecorator
-
printHead
public void printHead()- Specified by:
printHeadin interfaceorg.refcodes.logger.LogDecorator
-
toPreConfiguredTableBuilder
protected org.refcodes.textual.TableBuilder toPreConfiguredTableBuilder(org.refcodes.tabular.FormattedHeader<?> aHeader, AbstractConsoleLogger.OutputPrintStream aOutputPrintStream) Creates a preconfiguredTableBuilder, can be used by sub-classes in case them require additionalTableBuilderinstances.- Parameters:
aHeader- the headeraOutputPrintStream- the output print stream- Returns:
- A preconfigured
TableBuilder(as of the attributes state of theAbstractConsoleLogger).
-
log
protected void log(org.refcodes.tabular.Record<? extends T> aRecord, org.refcodes.tabular.FormattedHeader<T> aHeader, org.refcodes.textual.TableBuilder aTableBuilder) Prints out a log-line with regard to the providedHeaderunsing the providedTableBuilder.- Parameters:
aRecord- The record to log.aHeader- TheHeaderwith which to determine the visibility of theRecord's elements.aTableBuilder- TheTableBuilderto use for printing.- Throws:
ClassCastException- the class cast exception
-