Class SyslogFormatter


  • public class SyslogFormatter
    extends Formatter
    Format LogRecord as a RFC5424-compliant syslog message. Fields of syslog message are:
    • priority (facility * 8 + priority)
    • version (constant "1" for now)
    • timestamp (format derived from RFC3339, we use LogRecord's timestamp)
    • hostname (InetAddress.getLocalHost().getHostName() with AM_SERVER_HOST system property as a default)
    • app-name (device or application id, we use the constant "OpenAM" value)
    • proc-id (change of this value indicates discontinuity in logs and groups records from the same process, we use hash code of the SyslogFormatter class)
    • msg id (type of message, LogConstants.MESSAGE_ID from info map or - (nil-value))
    • structured data (keys and values from info map, expressed as one SD-ELEMENT with "logRecord@36733" as SD-ID. 36733 is IANA enterpriseId of Forgerock AS)
    • log message.
    As the structured data field is capable of expressing all the key-value pairs from info map, we include all keys except those that are listed in allFields configuration option and not in selectedFields. If iplanet-am-logging-syslog-add-unlisted-fields is not checked, only fields in allFields are included. NB: Current syslog daemons (both rsyslog and syslog-ng) need additional configuration to allow logging via UDP (or TCP) and to log structured data.
    • Constructor Detail

      • SyslogFormatter

        public SyslogFormatter()
        Initialize a new formatter. Reads and caches constant fields to use in log messages and initializes collections for field-filtering.
    • Method Detail

      • format

        public String format​(LogRecord record)
        Format a LogRecord as a RFC5424 structured syslog message. Most of interesting bits are expressed as key-value pairs in structured data element with id logRecord@36733.
        Specified by:
        format in class Formatter
        Parameters:
        record - A standard LogRecord to be formatted.
        Returns:
        Formatted string, suitable to be sent as a syslog message.