Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// /////////////////////////////////////////////////////////////////////////////
// REFCODES.ORG
// =============================================================================
// This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
// under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
// licenses:
// =============================================================================
// GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
// together with the GPL linking exception applied; as being applied by the GNU
// Classpath ("http://www.gnu.org/software/classpath/license.html")
// =============================================================================
// Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
// =============================================================================
// Please contact the copyright holding author(s) of the software artifacts in
// question for licensing issues not being covered by the above listed licenses,
// also regarding commercial licensing models or regarding the compatibility
// with other open source licenses.
// /////////////////////////////////////////////////////////////////////////////
package org.refcodes.logger.alt.console.impls;
import static org.fusesource.jansi.Ansi.*;
import java.io.PrintStream;
import org.fusesource.jansi.Ansi.Color;
import org.fusesource.jansi.AnsiConsole;
import org.refcodes.component.Destroyable;
import org.refcodes.data.RuntimeConsts;
import org.refcodes.logger.IllegalRecordRuntimeException;
import org.refcodes.logger.LogPriority;
import org.refcodes.logger.Logger;
import org.refcodes.logger.LoggerField;
import org.refcodes.logger.RuntimeLogger;
import org.refcodes.logger.UnexpectedLogRuntimeException;
import org.refcodes.logger.alt.console.ConsoleLogger;
import org.refcodes.logger.impls.RuntimeLoggerHeaderImpl;
import org.refcodes.runtime.CommandLineInterpreter;
import org.refcodes.runtime.OperatingSystem;
import org.refcodes.runtime.SystemUtility;
import org.refcodes.tabular.ColumnMismatchException;
import org.refcodes.tabular.Header;
import org.refcodes.tabular.HeaderMismatchException;
import org.refcodes.tabular.PrintStackTrace;
import org.refcodes.tabular.Record;
import org.refcodes.tabular.Row;
import org.refcodes.textual.SplitTextMode;
import org.refcodes.textual.MoreTextMode;
import org.refcodes.textual.TableBuilder;
import org.refcodes.textual.TableStyle;
import org.refcodes.textual.HorizAlignTextMode;
import org.refcodes.textual.ColumnWidthMetrics;
import org.refcodes.textual.ColumnWidthType;
import org.refcodes.textual.impls.TableBuilderImpl;
import org.refcodes.textual.impls.HorizAlignTextBuilderImpl;
import org.refcodes.textual.impls.ColumnWidthMetricsImpl;
/**
* The {@link ConsoleLoggerImpl} implements the {@link Logger} interface for
* providing logging functionality for extended pimped console output (via
* {@link System#out} and {@link System#err} to be used by {@link RuntimeLogger}
* implementations.
*
* ATTENTION: As the table layout for the generated log lines makes only sense
* when all {@link ConsoleLoggerImpl} instances print out their output according
* to the last state of a previous output (from another instance of the
* {@link ConsoleLoggerImpl}), the "bean" attributes refer actually to static
* member variables: Their values are valid for all instances of this class!
*
* Still the setters and getters are of "instance" scope (not static) to enable
* the builder-pattern to be applied.
*
* The {@link ConsoleLoggerImpl} by default uses the
* {@link SystemUtility#getConsoleWidth()} method, which determines the width in
* characters of the system's console in use. 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
* {@link SystemUtility#SYS_PROP_CONSOLE_WIDTH}.
*
* You can also use the {@link #setRowWidth(int)} or {@link #withRowWidth(int)}
* method in order to programmatically set the console's row width.
*
* @param The type of the {@link Record} instances managed by the
* {@link Logger}.
*/
public class ConsoleLoggerImpl implements Destroyable, ConsoleLogger {
// /////////////////////////////////////////////////////////////////////////
// ENUM:
// /////////////////////////////////////////////////////////////////////////
private enum TableLayout {
NONE, MSG, EXC
}
// /////////////////////////////////////////////////////////////////////////
// CONSTANTS:
// /////////////////////////////////////////////////////////////////////////
private static final int HIGH_RES = 1;
private static final int LOW_RES = 0;
private static final int INDEX_LINE_NUMBER = 0;
private static final int INDEX_EXCEPTION = 7;
// @formatter:off
private static final ColumnWidthMetrics[] A_WIDTH_LINE_NUMBER = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 7, ColumnWidthType.ABSOLUTE), new ColumnWidthMetricsImpl( 10, ColumnWidthType.ABSOLUTE) };
private static final ColumnWidthMetrics[] B_WIDTH_DATE = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 19, ColumnWidthType.ABSOLUTE), new ColumnWidthMetricsImpl( 19, ColumnWidthType.ABSOLUTE) };
private static final ColumnWidthMetrics[] C_WIDTH_PRIORITY = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 7, ColumnWidthType.ABSOLUTE), new ColumnWidthMetricsImpl( 7, ColumnWidthType.ABSOLUTE) };
private static final ColumnWidthMetrics[] D_WIDTH_THREAD = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 2, ColumnWidthType.RELATIVE), new ColumnWidthMetricsImpl( 15, ColumnWidthType.ABSOLUTE) };
private static final ColumnWidthMetrics[] E_WIDTH_CLASS = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 4, ColumnWidthType.RELATIVE), new ColumnWidthMetricsImpl( 1, ColumnWidthType.RELATIVE) };
private static final ColumnWidthMetrics[] F_WIDTH_METHOD = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 3, ColumnWidthType.RELATIVE), new ColumnWidthMetricsImpl( 45, ColumnWidthType.ABSOLUTE) };
private static final ColumnWidthMetrics[] G_WIDTH_MESSAGE = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 7, ColumnWidthType.RELATIVE), new ColumnWidthMetricsImpl( 2, ColumnWidthType.RELATIVE) };
private static final ColumnWidthMetrics[] Z_WIDTH_EXCEPTION = new ColumnWidthMetrics[] { new ColumnWidthMetricsImpl( 1, ColumnWidthType.RELATIVE), new ColumnWidthMetricsImpl( 1, ColumnWidthType.RELATIVE) };
// @formatter:on
private static final String ANSI_LINE_NUMBER = ansi().fg( Color.MAGENTA ).bg( Color.DEFAULT ).toString();
private static final String ANSI_DATE = ansi().fg( Color.WHITE ).toString();
private static final String ANSI_THREAD = ansi().fgBright( Color.WHITE ).bg( Color.BLACK ).toString();
private static final String ANSI_MESSAGE = ansi().fg( Color.DEFAULT ).bg( Color.DEFAULT ).toString();
private static final String ANSI_EXCEPTION = ansi().fgBright( Color.RED ).toString();
private static final String ANSI_CLASS = ansi().fg( Color.DEFAULT ).bg( Color.DEFAULT ).toString();
private static final String ANSI_METHOD = ansi().bold().fg( Color.BLUE ).toString();
private static final String ANSI_PRIORITY_WARN = ansi().bold().fg( Color.RED ).toString();
private static final String ANSI_PRIORITY_INFO = ansi().bold().fg( Color.GREEN ).toString();
private static final String ANSI_PRIORITY_PANIC = ansi().bold().fgBright( Color.WHITE ).bgBright( Color.RED ).toString();
private static final String ANSI_PRIORITY_ERROR = ansi().bold().fgBright( Color.RED ).toString();
private static final String ANSI_PRIORITY_DEBUG = ansi().bold().fgBright( Color.YELLOW ).bgBright( Color.BLUE ).toString();
private static final String ANSI_PRIORITY_TRACE = ansi().bold().fg( Color.WHITE ).toString();
// @formatter:off
private static String[] ANSI_PRIORITIES = new String[] {
ANSI_PRIORITY_TRACE,
ANSI_PRIORITY_DEBUG,
ANSI_PRIORITY_INFO,
ANSI_PRIORITY_INFO,
ANSI_PRIORITY_WARN,
ANSI_PRIORITY_ERROR,
ANSI_PRIORITY_ERROR,
ANSI_PRIORITY_ERROR,
ANSI_PRIORITY_PANIC
};
// @formatter:on
// /////////////////////////////////////////////////////////////////////////
// VARIABLES:
// /////////////////////////////////////////////////////////////////////////
private Header