Class FormattedLoggerImpl<T>

  • Type Parameters:
    T - The type of the Record instances managed by the Logger.
    All Implemented Interfaces:
    org.refcodes.component.Destroyable, FormattedLogger<T>, org.refcodes.logger.Logger<T>, org.refcodes.mixin.ErrorPrintStreamAccessor, org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamBuilder<FormattedLogger<T>>, org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamMutator, org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamProperty, org.refcodes.mixin.RowWidthAccessor, org.refcodes.mixin.RowWidthAccessor.RowWidthBuilder<FormattedLogger<?>>, org.refcodes.mixin.RowWidthAccessor.RowWidthMutator, org.refcodes.mixin.RowWidthAccessor.RowWidthProperty, org.refcodes.mixin.StandardPrintStreamAccessor, org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamBuilder<FormattedLogger<T>>, org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamMutator, org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamProperty, org.refcodes.textual.TableStyleAccessor, org.refcodes.textual.TableStyleAccessor.TableStyleBuilder<FormattedLogger<?>>, org.refcodes.textual.TableStyleAccessor.TableStyleMutator, org.refcodes.textual.TableStyleAccessor.TableStyleProperty
    Direct Known Subclasses:
    ConsoleLoggerImpl

    public class FormattedLoggerImpl<T>
    extends java.lang.Object
    implements org.refcodes.component.Destroyable, FormattedLogger<T>
    The FormattedLoggerImpl implements the Logger interface for providing logging functionality with extended pimped console output (via System.out and (via sub-classing also System.err).

    The FormattedLoggerImpl 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 FormattedLogger.withRowWidth(int) method in order to programmatically set the console's row width.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FormattedLoggerImpl.OutputPrintStream
      The Enum OutputPrintStream.
      • Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable

        org.refcodes.component.Destroyable.DestroyAutomaton
      • Nested 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.ErrorPrintStreamProperty
      • Nested 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.RowWidthProperty
      • Nested 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.StandardPrintStreamProperty
      • Nested 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
    • Constructor Summary

      Constructors 
      Constructor Description
      FormattedLoggerImpl​(org.refcodes.tabular.FormattedHeader<T> aHeader)
      Initially enables or disables ANSI escape sequences as of detection of terminal's ANSI support.
    • Field Detail

      • _header

        protected org.refcodes.tabular.FormattedHeader<T> _header
      • _tableBuilder

        protected org.refcodes.textual.TableBuilder _tableBuilder
      • _stdStream

        protected java.io.PrintStream _stdStream
      • _errStream

        protected java.io.PrintStream _errStream
      • _rowWidth

        protected int _rowWidth
      • _tableStyle

        protected org.refcodes.textual.TableStyle _tableStyle
      • _hasLeftBorder

        protected boolean _hasLeftBorder
      • _hasRightBorder

        protected boolean _hasRightBorder
    • Constructor Detail

      • FormattedLoggerImpl

        public FormattedLoggerImpl​(org.refcodes.tabular.FormattedHeader<T> aHeader)
        Initially enables or disables ANSI escape sequences as of detection of terminal's ANSI support. You can overrule this setting by calling setEscapeCodes(boolean). See also SystemUtility.isAnsiTerminal().
        Parameters:
        aHeader - the header
    • Method Detail

      • log

        public void log​(org.refcodes.tabular.Record<? extends T> aRecord)
                 throws org.refcodes.logger.IllegalRecordRuntimeException,
                        org.refcodes.logger.UnexpectedLogRuntimeException
        Specified by:
        log in interface org.refcodes.logger.Logger<T>
        Throws:
        org.refcodes.logger.IllegalRecordRuntimeException
        org.refcodes.logger.UnexpectedLogRuntimeException
      • getStandardPrintStream

        public java.io.PrintStream getStandardPrintStream()
        Specified by:
        getStandardPrintStream in interface org.refcodes.mixin.StandardPrintStreamAccessor
      • setStandardPrintStream

        public void setStandardPrintStream​(java.io.PrintStream aOutStream)
        Specified by:
        setStandardPrintStream in interface org.refcodes.mixin.StandardPrintStreamAccessor.StandardPrintStreamMutator
      • getErrorPrintStream

        public java.io.PrintStream getErrorPrintStream()
        Specified by:
        getErrorPrintStream in interface org.refcodes.mixin.ErrorPrintStreamAccessor
      • setErrorPrintStream

        public void setErrorPrintStream​(java.io.PrintStream aErrStream)
        Specified by:
        setErrorPrintStream in interface org.refcodes.mixin.ErrorPrintStreamAccessor.ErrorPrintStreamMutator
      • getTableStyle

        public org.refcodes.textual.TableStyle getTableStyle()
        Specified by:
        getTableStyle in interface org.refcodes.textual.TableStyleAccessor
      • setTableStyle

        public void setTableStyle​(org.refcodes.textual.TableStyle aTableStyle)
        Specified by:
        setTableStyle in interface org.refcodes.textual.TableStyleAccessor.TableStyleMutator
      • setLoggerStyle

        public void setLoggerStyle​(java.lang.String aTableStyleName)
        As the underlying configuration framework used by the RuntimeLoggerSingleton cannot convert a String to an enum, we got to provide such a method ourselves. When configuring programmatically use TableStyleAccessor.TableStyleMutator.setTableStyle(TableStyle), when using the "runtimelogger-config.xml" use the property "loggerStyle" for this method to be invoked. Valid arguments are as of the TableStyle enumeration:
        • SINGLE
        • DOUBLE
        • DOUBLE_SINGLE
        • SINGLE_DOUBLE
        • SINGLE_DASHED
        • ASCII
        • BLANK
        • SINGLE_BLANK
        • ASCII_BLANK
        Specified by:
        setLoggerStyle in interface FormattedLogger<T>
        Parameters:
        aTableStyleName - The style to use for the logger.
      • setEscapeCodes

        public void setEscapeCodes​(boolean isEscCodesEnabled)
        Sets the escape codes.
        Specified by:
        setEscapeCodes in interface FormattedLogger<T>
        Parameters:
        isEscCodesEnabled - the new escape codes
      • hasLeftBorder

        public boolean hasLeftBorder()
        Checks for left border.
        Specified by:
        hasLeftBorder in interface FormattedLogger<T>
        Returns:
        true, if successful
      • setLeftBorder

        public void setLeftBorder​(boolean hasLeftBorder)
        Sets the left border.
        Specified by:
        setLeftBorder in interface FormattedLogger<T>
        Parameters:
        hasLeftBorder - the new left border
      • hasRightBorder

        public boolean hasRightBorder()
        Checks for right border.
        Specified by:
        hasRightBorder in interface FormattedLogger<T>
        Returns:
        true, if successful
      • setRightBorder

        public void setRightBorder​(boolean hasRightBorder)
        Sets the right border.
        Specified by:
        setRightBorder in interface FormattedLogger<T>
        Parameters:
        hasRightBorder - the new right border
      • getRowWidth

        public int getRowWidth()
        Specified by:
        getRowWidth in interface org.refcodes.mixin.RowWidthAccessor
      • setRowWidth

        public void setRowWidth​(int aRowWidth)
        Specified by:
        setRowWidth in interface org.refcodes.mixin.RowWidthAccessor.RowWidthMutator
      • hasEscapeCodes

        public boolean hasEscapeCodes()
        Checks for escape codes.
        Specified by:
        hasEscapeCodes in interface FormattedLogger<T>
        Returns:
        true, if successful
      • destroy

        public void destroy()
        Specified by:
        destroy in interface org.refcodes.component.Destroyable
      • init

        protected void init()
        Inits the logger.
      • printTail

        protected void printTail()
        Hook for using the right logger for printing the tail. Overwritten by sub-classes.
      • toPreConfiguredTableBuilder

        protected org.refcodes.textual.TableBuilder toPreConfiguredTableBuilder​(org.refcodes.tabular.FormattedHeader<?> aHeader,
                                                                                FormattedLoggerImpl.OutputPrintStream aOutputPrintStream)
        Creates a pre-configured TableBuilder, can be used by sub-classes in case them require additional TableBuilder instances.
        Parameters:
        aHeader - the header
        aOutputPrintStream - the output print stream
        Returns:
        A pre-configured TableBuilder (as of the attributes state of the FormattedLoggerImpl).
      • 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 provided Header unsing the provided TableBuilder.
        Parameters:
        aRecord - The record to log.
        aHeader - The Header with which to determine the visibility of the Record's elements.
        aTableBuilder - The TableBuilder to use for printing.
        Throws:
        java.lang.ClassCastException - the class cast exception