java.util.logging

Class Formatter

  • Direct Known Subclasses:
    SimpleFormatter, XMLFormatter

    public abstract class Formatter
    extends Object
    A Formatter provides support for formatting LogRecords.

    Typically each logging Handler will have a Formatter associated with it. The Formatter takes a LogRecord and converts it to a string.

    Some formatters (such as the XMLFormatter) need to wrap head and tail strings around a set of formatted records. The getHeader and getTail methods can be used to obtain these strings.

    Since:
    1.4
    • Constructor Detail

      • Formatter

        protected Formatter()
        Construct a new formatter.
    • Method Detail

      • format

        public abstract String format(LogRecord record)
        Format the given log record and return the formatted string.

        The resulting formatted String will normally include a localized and formatted version of the LogRecord's message field. It is recommended to use the formatMessage(java.util.logging.LogRecord) convenience method to localize and format the message field.

        Parameters:
        record - the log record to be formatted.
        Returns:
        the formatted log record
      • getHead

        public String getHead(Handler h)
        Return the header string for a set of formatted records.

        This base class returns an empty string, but this may be overridden by subclasses.

        Parameters:
        h - The target handler (can be null)
        Returns:
        header string
      • getTail

        public String getTail(Handler h)
        Return the tail string for a set of formatted records.

        This base class returns an empty string, but this may be overridden by subclasses.

        Parameters:
        h - The target handler (can be null)
        Returns:
        tail string
      • formatMessage

        public String formatMessage(LogRecord record)
        Localize and format the message string from a log record. This method is provided as a convenience for Formatter subclasses to use when they are performing formatting.

        The message string is first localized to a format string using the record's ResourceBundle. (If there is no ResourceBundle, or if the message key is not found, then the key is used as the format string.) The format String uses java.text style formatting.

        • If there are no parameters, no formatter is used.
        • Otherwise, if the string contains "{0" then java.text.MessageFormat is used to format the string.
        • Otherwise no formatting is performed.

        Parameters:
        record - the log record containing the raw message
        Returns:
        a localized and formatted message

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Document créé le 31/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-java/util/logging/formatter.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com, Formatter

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.

Table des matières Haut