Tabnine Logo
MonolineFormatter
Code IndexAdd Tabnine to your IDE (free)

How to use
MonolineFormatter
in
org.apache.sis.util.logging

Best Java code snippets using org.apache.sis.util.logging.MonolineFormatter (Showing top 19 results out of 315)

origin: apache/sis

/**
 * Installs Apache SIS monoline formatter for easier identification of Apache SIS log messages among Maven outputs.
 * We perform this installation only for {@code *TestSuite}, not for individual {@code *Test}. Consequently this is
 * typically enabled when building a whole module with Maven but not when debugging an individual class.
 *
 * @since 1.0
 */
@BeforeClass
public static void configureLogging() {
  MonolineFormatter f = MonolineFormatter.install();
  f.setHeader(null);
  f.setTimeFormat(null);
  f.setSourceFormat("class.method");
}
origin: org.apache.sis.core/sis-utility

/**
 * Resets the colors to the default values. This method does not check if <cite>ANSI escape codes</cite>
 * are supported or not - this check must be done by the caller.
 */
private void resetLevelColors() {
  final SortedMap<Level,X364> colors = colors();
  colors.clear();
  colors.put(Level.ALL,     X364.BACKGROUND_GRAY);
  colors.put(Level.CONFIG,  X364.BACKGROUND_BLUE);
  colors.put(Level.INFO,    X364.BACKGROUND_GREEN);
  colors.put(Level.WARNING, X364.BACKGROUND_YELLOW);
  colors.put(Level.SEVERE,  X364.BACKGROUND_RED);
  colors.put(PerformanceLevel.PERFORMANCE, X364.BACKGROUND_CYAN);
}
origin: org.apache.sis.core/sis-utility

/**
 * Installs a {@code MonolineFormatter} for the root logger, or returns the existing instance if any.
 * This method performs the following choices:
 *
 * <ul>
 *   <li>If a {@link ConsoleHandler} is associated to the root logger, then:
 *     <ul>
 *       <li>If that handler already uses a {@code MonolineFormatter}, then the existing formatter is returned.</li>
 *       <li>Otherwise the {@code ConsoleHandler} formatter is replaced by a new {@code MonolineFormatter} instance,
 *           and that new instance is returned. We perform this replacement in order to avoid sending twice the same
 *           records to the console.</li>
 *     </ul></li>
 *   <li>Otherwise a new {@code ConsoleHandler} using a new {@code MonolineFormatter} is created and added to the
 *       root logger.</li>
 * </ul>
 *
 * <div class="note"><b>Implementation note:</b>
 * The current implementation does not check for duplicated {@code ConsoleHandler} instances,
 * and does not check if any child logger has a {@code ConsoleHandler}.</div>
 *
 * @return the new or existing {@code MonolineFormatter}. The formatter output can be configured
 *         using the {@link #setTimeFormat(String)} and {@link #setSourceFormat(String)} methods.
 * @throws SecurityException if this method does not have the permission to install the formatter.
 */
@Configuration
public static MonolineFormatter install()  throws SecurityException {
  return install(Logging.getLogger(""), null);
}
origin: apache/sis

levelWidth = levelWidth((handler != null) ? handler.getLevel() : null);
  timeFormat(manager.getProperty(classname + ".time"));
} catch (IllegalArgumentException exception) {
  Logging.configurationException(Logging.getLogger(Modules.UTILITIES), MonolineFormatter.class, "<init>", exception);
  sourceFormat(manager.getProperty(classname + ".source"));
} catch (IllegalArgumentException exception) {
  Logging.configurationException(Logging.getLogger(Modules.UTILITIES), MonolineFormatter.class, "<init>", exception);
  resetLevelColors();
origin: org.apache.sis.core/sis-utility

if (SHOW_LEVEL) {
  if (colors) {
    levelColor = colorAt(level);
    levelReset = X364.BACKGROUND_DEFAULT.sequence();
String message = formatMessage(record);
int length = 0;
if (message != null) {
      exception.printStackTrace(printer);
    } else {
      printAbridged(exception, writer, record.getLoggerName(),
          record.getSourceClassName(), record.getSourceMethodName());
origin: apache/sis

/**
 * Formats the given expected string to a format matching the current locale setting.
 * The given string shall use tabulation before each line of the message.
 */
private static String localize(final Level level, final String expected) {
  final String levelToReplace = level.getName();
  final String levelLocalized = level.getLocalizedName();
  assertTrue(expected, expected.startsWith(levelToReplace));
  final int margin = MonolineFormatter.levelWidth(null);
  final StringBuilder buffer = new StringBuilder(expected.length() + 40)
      .append(levelLocalized)
      .append(CharSequences.spaces(margin - levelLocalized.length()))
      .append(expected, levelToReplace.length() + 1, expected.length());      // +1 is for skipping '\t'.
  final String spaces = MonolineFormatter.CONTINUATION_MARK
            + CharSequences.spaces(margin - 1).toString();
  int positionOfLast = -1;
  for (int i=margin; (i=buffer.indexOf("\n\t", i)) >= 0; i += margin) {
    buffer.replace(positionOfLast = ++i, i+1, spaces);                          // Replace only tabulation, leave new line.
  }
  if (positionOfLast >= 0) {
    buffer.setCharAt(positionOfLast, MonolineFormatter.CONTINUATION_END);
  }
  return buffer.toString();
}
origin: apache/sis

/**
 * Tests formatting of a multi-line message.
 */
@Test
@DependsOnMethod("testlevelWidth")
public void testMultilines() {
  final LogRecord record = new LogRecord(Level.INFO, "First line\n  Indented line\nLast line\n");
  final String formatted = formatter.format(record);
  assertMultilinesEquals(localize(Level.INFO,
      "INFO\t First line\n" +
        "\t   Indented line\n" +
        "\t Last line\n"), formatted);
}
origin: apache/sis

    monoline = (MonolineFormatter) formatter;
  } else {
    monoline = new MonolineFormatter(handler);
    handler.setFormatter(monoline);
monoline = new MonolineFormatter(handler);
handler.setFormatter(monoline);
logger.addHandler(handler);
origin: apache/sis

/**
 * Installs a {@code MonolineFormatter} for the root logger, or returns the existing instance if any.
 * This method performs the following choices:
 *
 * <ul>
 *   <li>If a {@link ConsoleHandler} is associated to the root logger, then:
 *     <ul>
 *       <li>If that handler already uses a {@code MonolineFormatter}, then the existing formatter is returned.</li>
 *       <li>Otherwise the {@code ConsoleHandler} formatter is replaced by a new {@code MonolineFormatter} instance,
 *           and that new instance is returned. We perform this replacement in order to avoid sending twice the same
 *           records to the console.</li>
 *     </ul></li>
 *   <li>Otherwise a new {@code ConsoleHandler} using a new {@code MonolineFormatter} is created and added to the
 *       root logger.</li>
 * </ul>
 *
 * <div class="note"><b>Implementation note:</b>
 * The current implementation does not check for duplicated {@code ConsoleHandler} instances,
 * and does not check if any child logger has a {@code ConsoleHandler}.</div>
 *
 * @return the new or existing {@code MonolineFormatter}. The formatter output can be configured
 *         using the {@link #setTimeFormat(String)} and {@link #setSourceFormat(String)} methods.
 * @throws SecurityException if this method does not have the permission to install the formatter.
 */
@Configuration
public static MonolineFormatter install() throws SecurityException {
  return install(Logging.getLogger(""), null);
}
origin: org.apache.sis.core/sis-utility

levelWidth = levelWidth((handler != null) ? handler.getLevel() : null);
  timeFormat(manager.getProperty(classname + ".time"));
} catch (IllegalArgumentException exception) {
  Logging.configurationException(Logging.getLogger(Modules.UTILITIES), MonolineFormatter.class, "<init>", exception);
  sourceFormat(manager.getProperty(classname + ".source"));
} catch (IllegalArgumentException exception) {
  Logging.configurationException(Logging.getLogger(Modules.UTILITIES), MonolineFormatter.class, "<init>", exception);
  resetLevelColors();
origin: apache/sis

if (SHOW_LEVEL) {
  if (colors) {
    levelColor = colorAt(level);
    levelReset = X364.BACKGROUND_DEFAULT.sequence();
String message = formatMessage(record);
int length = 0;
if (message != null) {
      exception.printStackTrace(printer);
    } else {
      printAbridged(exception, writer, record.getLoggerName(),
          record.getSourceClassName(), record.getSourceMethodName());
origin: apache/sis

/**
 * Tests {@link MonolineFormatter#levelWidth(Level)}.
 */
@Test
public void testlevelWidth() {
  final String severe = Level.SEVERE.getLocalizedName();
  assertEquals(severe, severe.length(), MonolineFormatter.levelWidth(Level.SEVERE));
  final String warning = Level.WARNING.getLocalizedName();
  assertEquals(warning, StrictMath.max(severe.length(), warning.length()),
      MonolineFormatter.levelWidth(Level.WARNING));
}
origin: apache/sis

  /**
   * Tests formatting a log record which contains an exception.
   */
  @Test
  @DependsOnMethod("testlevelWidth")
  public void testException() {
    final LogRecord record = new LogRecord(Level.WARNING, "An exception occured.");
    final Exception exception = new Exception();
    exception.setStackTrace(new StackTraceElement[] {
      new StackTraceElement("org.apache.sis.NonExistent", "foo",  "NonExistent.java", 10),
      new StackTraceElement("org.junit.WhoKnows",         "main", "WhoKnows.java",    20)
    });
    record.setThrown(exception);
    String formatted = formatter.format(record);
    assertMultilinesEquals(localize(Level.WARNING,
        "WARNING\t An exception occured.\n" +
            "\t Caused by: java.lang.Exception\n" +
            "\t     at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n" +
            "\t     at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted);
    /*
     * Remove the message and try again.
     */
    record.setMessage(null);
    formatted = formatter.format(record);
    assertMultilinesEquals(localize(Level.WARNING,
        "WARNING\t java.lang.Exception\n" +
            "\t     at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n" +
            "\t     at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted);
  }
}
origin: org.apache.sis.core/sis-utility

    monoline = (MonolineFormatter) formatter;
  } else {
    monoline = new MonolineFormatter(handler);
    handler.setFormatter(monoline);
monoline = new MonolineFormatter(handler);
handler.setFormatter(monoline);
logger.addHandler(handler);
origin: apache/sis

MonolineFormatter.install();
origin: apache/sis

/**
 * Resets the colors to the default values. This method does not check if <cite>ANSI escape codes</cite>
 * are supported or not - this check must be done by the caller.
 */
private void resetLevelColors() {
  final SortedMap<Level,X364> colors = colors();
  colors.clear();
  colors.put(Level.ALL,     X364.BACKGROUND_GRAY);
  colors.put(Level.CONFIG,  X364.BACKGROUND_BLUE);
  colors.put(Level.INFO,    X364.BACKGROUND_GREEN);
  colors.put(Level.WARNING, X364.BACKGROUND_YELLOW);
  colors.put(Level.SEVERE,  X364.BACKGROUND_RED);
  colors.put(PerformanceLevel.PERFORMANCE, X364.BACKGROUND_CYAN);
}
origin: Geomatys/geotoolkit

if ("server".equalsIgnoreCase(get(properties, "platform", "desktop"))) {
} else {
  MonolineFormatter.install();
origin: org.apache.sis.core/sis-utility

if (color != null) {
  final X364 code = X364.forColorName(color).background();
  changed = (colors().put(level, code) != code);
} else if (colors != null) {
  changed = (colors.remove(level) != null);
origin: apache/sis

if (color != null) {
  final X364 code = X364.forColorName(color).background();
  changed = (colors().put(level, code) != code);
} else if (colors != null) {
  changed = (colors.remove(level) != null);
org.apache.sis.util.loggingMonolineFormatter

Javadoc

A formatter writing log messages on a single line. Compared to the JDK SimpleFormatter, this formatter uses only one line per message instead of two. For example messages formatted by MonolineFormatter may look like:
00:01CONFIG [MyApplication] Read configuration from “my-application/setup.xml”.
00:03INFO [EPSGFactory] Connected to the EPSG database version 9.1 on Derby 10.14.
00:12WARNING [DefaultTemporalExtent] This operation requires the “sis-temporal” module.
By default, MonolineFormatter shows only the level and the message. One or two additional fields can be inserted between the level and the message if the #setTimeFormat(String) or #setSourceFormat(String) methods are invoked with o non-null argument. Examples:
  • setTimeFormat("HH:mm:ss") for formatting the time like 00:00:04", as time elapsed since the MonolineFormatter creation time.
  • setSourceFormat("logger:long") for formatting the full logger name (e.g. "org.apache.sis.storage.netcdf").
  • setSourceFormat("class:short") for formatting the short class name, without package (e.g. "NetcdfStore").
Configuration from logging.properties
The format can also be set from the jre/lib/logging.properties file. For example, user can cut and paste the following properties into logging.properties: textSee #setTimeFormat(String) and #setSourceFormat(String) for more information about the above time and source properties. Encoding and logging level are configured separately, typically on the JDK ConsoleHandler like below: text
Thread safety
The same MonolineFormatter instance can be safely used by many threads without synchronization on the part of the caller. Subclasses should make sure that any overridden methods remain safe to call from multiple threads.

Most used methods

  • install
    Installs a MonolineFormatter for the specified logger, or returns the existing instance if any. This
  • levelWidth
    Returns the length of the widest level name, taking in account only the standard levels equals or gr
  • <init>
    Constructs a default MonolineFormatter.Auto-configuration from the handler Formatters are often ass
  • colorAt
    Gets the color for the given level. If there is no explicit color for the given level, returns the c
  • colors
    Returns the #colors map, creating it if needed.
  • format
    Formats the given log record and return the formatted string. See the class javadoc for information
  • formatMessage
    Returns the localized message from the given log record. First this method gets the LogRecord#getMes
  • more
    Formats the number of stack trace elements that where skipped.
  • printAbridged
    Prints an abridged stack trace. This method is invoked when the record is logged at at low logging l
  • resetLevelColors
    Resets the colors setting to its default value. * If enabled is true, then this method defines a
  • setHeader
    Sets the string to write on the left side of the first line of every log records.
  • setSourceFormat
    Sets the format for displaying the source, or hides the source field. The given format can be any of
  • setHeader,
  • setSourceFormat,
  • setTimeFormat,
  • sourceFormat,
  • timeFormat

Popular in Java

  • Making http post requests using okhttp
  • setScale (BigDecimal)
  • onRequestPermissionsResult (Fragment)
  • setRequestProperty (URLConnection)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • String (java.lang)
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • JList (javax.swing)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Table (org.hibernate.mapping)
    A relational table
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now