コード例 #1
0
  private Map<String, FieldFormatter> createFieldFormatters(
      final LoggerFields[] loggerFields, final Configuration config) {
    final Map<String, FieldFormatter> sdIdMap = new HashMap<String, FieldFormatter>();

    if (loggerFields != null) {
      for (final LoggerFields lField : loggerFields) {
        final StructuredDataId key = lField.getSdId() == null ? mdcSdId : lField.getSdId();
        final Map<String, List<PatternFormatter>> sdParams =
            new HashMap<String, List<PatternFormatter>>();
        final Map<String, String> fields = lField.getMap();
        if (!fields.isEmpty()) {
          final PatternParser fieldParser = createPatternParser(config, null);

          for (final Map.Entry<String, String> entry : fields.entrySet()) {
            final List<PatternFormatter> formatters =
                fieldParser.parse(entry.getValue(), false, false);
            sdParams.put(entry.getKey(), formatters);
          }
          final FieldFormatter fieldFormatter =
              new FieldFormatter(sdParams, lField.getDiscardIfAllFieldsAreEmpty());
          sdIdMap.put(key.toString(), fieldFormatter);
        }
      }
    }
    return sdIdMap.size() > 0 ? sdIdMap : null;
  }
コード例 #2
0
  private Rfc5424Layout(
      final Configuration config,
      final Facility facility,
      final String id,
      final int ein,
      final boolean includeMDC,
      final boolean includeNL,
      final String escapeNL,
      final String mdcId,
      final String mdcPrefix,
      final String eventPrefix,
      final String appName,
      final String messageId,
      final String excludes,
      final String includes,
      final String required,
      final Charset charset,
      final String exceptionPattern,
      final boolean useTLSMessageFormat,
      final LoggerFields[] loggerFields) {
    super(charset);
    final PatternParser exceptionParser =
        createPatternParser(config, ThrowablePatternConverter.class);
    exceptionFormatters =
        exceptionPattern == null ? null : exceptionParser.parse(exceptionPattern, false, false);
    this.facility = facility;
    this.defaultId = id == null ? DEFAULT_ID : id;
    this.enterpriseNumber = ein;
    this.includeMdc = includeMDC;
    this.includeNewLine = includeNL;
    this.escapeNewLine = escapeNL == null ? null : Matcher.quoteReplacement(escapeNL);
    this.mdcId = mdcId;
    this.mdcSdId = new StructuredDataId(mdcId, enterpriseNumber, null, null);
    this.mdcPrefix = mdcPrefix;
    this.eventPrefix = eventPrefix;
    this.appName = appName;
    this.messageId = messageId;
    this.useTlsMessageFormat = useTLSMessageFormat;
    this.localHostName = NetUtils.getLocalHostname();
    ListChecker c = null;
    if (excludes != null) {
      final String[] array = excludes.split(Patterns.COMMA_SEPARATOR);
      if (array.length > 0) {
        c = new ExcludeChecker();
        mdcExcludes = new ArrayList<String>(array.length);
        for (final String str : array) {
          mdcExcludes.add(str.trim());
        }
      } else {
        mdcExcludes = null;
      }
    } else {
      mdcExcludes = null;
    }
    if (includes != null) {
      final String[] array = includes.split(Patterns.COMMA_SEPARATOR);
      if (array.length > 0) {
        c = new IncludeChecker();
        mdcIncludes = new ArrayList<String>(array.length);
        for (final String str : array) {
          mdcIncludes.add(str.trim());
        }
      } else {
        mdcIncludes = null;
      }
    } else {
      mdcIncludes = null;
    }
    if (required != null) {
      final String[] array = required.split(Patterns.COMMA_SEPARATOR);
      if (array.length > 0) {
        mdcRequired = new ArrayList<String>(array.length);
        for (final String str : array) {
          mdcRequired.add(str.trim());
        }
      } else {
        mdcRequired = null;
      }

    } else {
      mdcRequired = null;
    }
    this.checker = c != null ? c : noopChecker;
    final String name = config == null ? null : config.getName();
    configName = name != null && name.length() > 0 ? name : null;
    this.fieldFormatters = createFieldFormatters(loggerFields, config);
  }