All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.hcp.cf.log4j2.converter.ContextPropsConverter Maven / Gradle / Ivy

There is a newer version: 3.8.4
Show newest version
package com.sap.hcp.cf.log4j2.converter;

import java.util.Arrays;

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.pattern.ConverterKeys;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;

import com.sap.hcp.cf.logging.common.converter.DefaultPropertiesConverter;

/**
 * A simple {@link LogEventPatternConverter} implementation that converts
 * key/value pairs from the {@link org.slf4j.MDC}. These key/value pairs are
 * embedded in the JSON message, i.e. the appear as fields at the top-level JSON
 * object.
 * 

* There are two exceptions to this: *

    *
  1. The predefined keys from * {@link com.sap.hcp.cf.logging.common.Fields}
  2. *
  3. The list of key names that have been passed in as options.
  4. *
* */ @Plugin(name = "ContextPropsConverter", category = "Converter") @ConverterKeys({ "ctxp" }) public class ContextPropsConverter extends LogEventPatternConverter { public static final String WORD = "ctxp"; private final DefaultPropertiesConverter converter = new DefaultPropertiesConverter(); public ContextPropsConverter(String[] options) { super(WORD, WORD); if (options != null) { converter.setExclusions(Arrays.asList(options)); } } public static ContextPropsConverter newInstance(final String[] options) { return new ContextPropsConverter(options); } @Override public void format(LogEvent event, StringBuilder toAppendTo) { converter.convert(event.getContextMap(), toAppendTo); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy