com.h3c.util

## Class LogFormatter

- java.lang.Object
- - java.util.logging.Formatter
  - - com.h3c.util.LogFormatter

-     public class LogFormatter
      extends Formatter

  Formats the JDK log message into the following form:

      2010-04-30 12:52:36:363 PDT INFO [main:1 TestLogFormatter.testPlainString] This is a test msg.

  The formatter catches all formatting exceptions and converts the exception to a log message dumping the exception string, format string, and arguments.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `LogFormatter()` Default constructor.
    `protected` | `LogFormatter(String headerFmt, int fmtBuffSize, boolean isHeaderLineSep)` Constructor that does the real work.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `format(LogRecord record)` This is called by JDK logging for format the log record.
    `static String` | `prepareCurlyBraceStringForLogging(String toFormat)` Format the provided string so that it can be logged without generating an IllegalArgumentException as a result of its inherent curly braces.

    - ### Methods inherited from class java.util.logging.Formatter

      `formatMessage, getHead, getTail`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LogFormatter

          public LogFormatter()

      Default constructor.

    - #### LogFormatter

          protected LogFormatter(String headerFmt,
                      int fmtBuffSize,
                      boolean isHeaderLineSep)

      Constructor that does the real work.
      Parameters:
        `headerFmt` - header format string
        `fmtBuffSize` - string buffer size (multiple line formatters will want to increase this)
        `isHeaderLineSep` - if true, a line separator will be appended after the header

  - ### Method Detail

    - #### prepareCurlyBraceStringForLogging

          public static String prepareCurlyBraceStringForLogging(String toFormat)

      Format the provided string so that it can be logged without generating an IllegalArgumentException as a result of its inherent curly braces. Replaces curly braces ("{}") with square brackets ("[]").
      Parameters:
        `toFormat` - String to be formatted
      Returns:
        formatted result

    - #### format

          public String format(LogRecord record)

      This is called by JDK logging for format the log record. The method is synchronized to follow the pattern of the `SimpleFormatter` which allows the sharing of the buffer.
      Specified by:
        `format` in class `Formatter`
      See Also:
        `Formatter.format(java.util.logging.LogRecord)`

Copyright © 2014. All Rights Reserved.