// Path: src/main/java/de/siegmar/logbackgelf/mappers/CallerDataFieldMapper.java
// public class CallerDataFieldMapper implements GelfFieldMapper<Object> {
// 
//     @Override
//     public void mapField(final ILoggingEvent event, final BiConsumer<String, Object> valueHandler) {
//         Optional.ofNullable(event.getCallerData())
//             .filter(s -> s.length > 0)
//             .map(s -> s[0])
//             .ifPresent(first -> {
//                 valueHandler.accept("source_file_name", first.getFileName());
//                 valueHandler.accept("source_method_name", first.getMethodName());
//                 valueHandler.accept("source_class_name", first.getClassName());
//                 valueHandler.accept("source_line_number", first.getLineNumber());
//             });
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/MarkerFieldMapper.java
// public class MarkerFieldMapper extends AbstractFixedNameFieldMapper<String> {
// 
//     public MarkerFieldMapper(final String fieldName) {
//         super(fieldName);
//     }
// 
//     @Override
//     protected Optional<String> getValue(final ILoggingEvent event) {
//         return Optional.ofNullable(event.getMarker())
//             .map(MarkerFieldMapper::buildMarkerStr);
//     }
// 
//     private static String buildMarkerStr(final Marker marker) {
//         if (!marker.hasReferences()) {
//             return marker.getName();
//         }
// 
//         final StringBuilder sb = new StringBuilder(marker.getName());
// 
//         final Iterator<Marker> it = marker.iterator();
//         do {
//             sb.append(", ").append(it.next().getName());
//         } while (it.hasNext());
// 
//         return sb.toString();
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/MdcDataFieldMapper.java
// public class MdcDataFieldMapper implements GelfFieldMapper<String> {
// 
//     @Override
//     public void mapField(final ILoggingEvent event, final BiConsumer<String, String> valueHandler) {
//         Optional.ofNullable(event.getMDCPropertyMap())
//             .ifPresent(p -> p.forEach(valueHandler));
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/RootExceptionDataFieldMapper.java
// public class RootExceptionDataFieldMapper implements GelfFieldMapper<Object> {
// 
//     @Override
//     public void mapField(final ILoggingEvent event, final BiConsumer<String, Object> valueHandler) {
//         Optional.ofNullable(getRootException(event.getThrowableProxy()))
//             .ifPresent(rootException -> {
//                 valueHandler.accept("root_cause_class_name", rootException.getClassName());
//                 valueHandler.accept("root_cause_message", rootException.getMessage());
//             });
//     }
// 
//     private IThrowableProxy getRootException(final IThrowableProxy throwableProxy) {
//         if (throwableProxy == null) {
//             return null;
//         }
// 
//         IThrowableProxy rootCause = throwableProxy;
//         while (rootCause.getCause() != null) {
//             rootCause = rootCause.getCause();
//         }
// 
//         return rootCause;
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/SimpleFieldMapper.java
// public class SimpleFieldMapper<T> extends AbstractFixedNameFieldMapper<T> {
// 
//     private final Function<ILoggingEvent, T> valueGetter;
// 
//     public SimpleFieldMapper(final String fieldName, final Function<ILoggingEvent, T> valueGetter) {
//         super(fieldName);
//         this.valueGetter = valueGetter;
//     }
// 
//     @Override
//     protected Optional<T> getValue(final ILoggingEvent event) {
//         return Optional.ofNullable(valueGetter.apply(event));
//     }
// 
// }


import java.math.BigDecimal;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.util.LevelToSyslogSeverity;
import ch.qos.logback.core.encoder.EncoderBase;
import de.siegmar.logbackgelf.mappers.CallerDataFieldMapper;
import de.siegmar.logbackgelf.mappers.MarkerFieldMapper;
import de.siegmar.logbackgelf.mappers.MdcDataFieldMapper;
import de.siegmar.logbackgelf.mappers.RootExceptionDataFieldMapper;
import de.siegmar.logbackgelf.mappers.SimpleFieldMapper;
        patternLayout.setPattern(pattern);
        patternLayout.start();
        return patternLayout;
    }

    private void addBuiltInFieldMappers() {
        builtInFieldMappers.add(new SimpleFieldMapper<>(loggerNameKey, ILoggingEvent::getLoggerName));
        builtInFieldMappers.add(new SimpleFieldMapper<>(threadNameKey, ILoggingEvent::getThreadName));

        if (includeLevelName) {
            builtInFieldMappers.add(new SimpleFieldMapper<>(levelNameKey, event -> event.getLevel().toString()));
        }

        if (includeRawMessage) {
            builtInFieldMappers.add(new SimpleFieldMapper<>("raw_message", ILoggingEvent::getMessage));
        }

        if (includeCallerData) {
            builtInFieldMappers.add(new CallerDataFieldMapper());
        }

        if (includeRootCauseData) {
            builtInFieldMappers.add(new RootExceptionDataFieldMapper());
        }

        if (includeMarker) {
            builtInFieldMappers.add(new MarkerFieldMapper("marker"));
        }

        if (includeMdcData) {
// Path: src/main/java/de/siegmar/logbackgelf/mappers/CallerDataFieldMapper.java
// public class CallerDataFieldMapper implements GelfFieldMapper<Object> {
// 
//     @Override
//     public void mapField(final ILoggingEvent event, final BiConsumer<String, Object> valueHandler) {
//         Optional.ofNullable(event.getCallerData())
//             .filter(s -> s.length > 0)
//             .map(s -> s[0])
//             .ifPresent(first -> {
//                 valueHandler.accept("source_file_name", first.getFileName());
//                 valueHandler.accept("source_method_name", first.getMethodName());
//                 valueHandler.accept("source_class_name", first.getClassName());
//                 valueHandler.accept("source_line_number", first.getLineNumber());
//             });
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/MarkerFieldMapper.java
// public class MarkerFieldMapper extends AbstractFixedNameFieldMapper<String> {
// 
//     public MarkerFieldMapper(final String fieldName) {
//         super(fieldName);
//     }
// 
//     @Override
//     protected Optional<String> getValue(final ILoggingEvent event) {
//         return Optional.ofNullable(event.getMarker())
//             .map(MarkerFieldMapper::buildMarkerStr);
//     }
// 
//     private static String buildMarkerStr(final Marker marker) {
//         if (!marker.hasReferences()) {
//             return marker.getName();
//         }
// 
//         final StringBuilder sb = new StringBuilder(marker.getName());
// 
//         final Iterator<Marker> it = marker.iterator();
//         do {
//             sb.append(", ").append(it.next().getName());
//         } while (it.hasNext());
// 
//         return sb.toString();
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/MdcDataFieldMapper.java
// public class MdcDataFieldMapper implements GelfFieldMapper<String> {
// 
//     @Override
//     public void mapField(final ILoggingEvent event, final BiConsumer<String, String> valueHandler) {
//         Optional.ofNullable(event.getMDCPropertyMap())
//             .ifPresent(p -> p.forEach(valueHandler));
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/RootExceptionDataFieldMapper.java
// public class RootExceptionDataFieldMapper implements GelfFieldMapper<Object> {
// 
//     @Override
//     public void mapField(final ILoggingEvent event, final BiConsumer<String, Object> valueHandler) {
//         Optional.ofNullable(getRootException(event.getThrowableProxy()))
//             .ifPresent(rootException -> {
//                 valueHandler.accept("root_cause_class_name", rootException.getClassName());
//                 valueHandler.accept("root_cause_message", rootException.getMessage());
//             });
//     }
// 
//     private IThrowableProxy getRootException(final IThrowableProxy throwableProxy) {
//         if (throwableProxy == null) {
//             return null;
//         }
// 
//         IThrowableProxy rootCause = throwableProxy;
//         while (rootCause.getCause() != null) {
//             rootCause = rootCause.getCause();
//         }
// 
//         return rootCause;
//     }
// 
// }
// 
// Path: src/main/java/de/siegmar/logbackgelf/mappers/SimpleFieldMapper.java
// public class SimpleFieldMapper<T> extends AbstractFixedNameFieldMapper<T> {
// 
//     private final Function<ILoggingEvent, T> valueGetter;
// 
//     public SimpleFieldMapper(final String fieldName, final Function<ILoggingEvent, T> valueGetter) {
//         super(fieldName);
//         this.valueGetter = valueGetter;
//     }
// 
//     @Override
//     protected Optional<T> getValue(final ILoggingEvent event) {
//         return Optional.ofNullable(valueGetter.apply(event));
//     }
// 
// }


// Path: src/main/java/de/siegmar/logbackgelf/GelfEncoder.java
import java.math.BigDecimal;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.util.LevelToSyslogSeverity;
import ch.qos.logback.core.encoder.EncoderBase;
import de.siegmar.logbackgelf.mappers.CallerDataFieldMapper;
import de.siegmar.logbackgelf.mappers.MarkerFieldMapper;
import de.siegmar.logbackgelf.mappers.MdcDataFieldMapper;
import de.siegmar.logbackgelf.mappers.RootExceptionDataFieldMapper;
import de.siegmar.logbackgelf.mappers.SimpleFieldMapper;

        patternLayout.setPattern(pattern);
        patternLayout.start();
        return patternLayout;
    }

    private void addBuiltInFieldMappers() {
        builtInFieldMappers.add(new SimpleFieldMapper<>(loggerNameKey, ILoggingEvent::getLoggerName));
        builtInFieldMappers.add(new SimpleFieldMapper<>(threadNameKey, ILoggingEvent::getThreadName));

        if (includeLevelName) {
            builtInFieldMappers.add(new SimpleFieldMapper<>(levelNameKey, event -> event.getLevel().toString()));
        }

        if (includeRawMessage) {
            builtInFieldMappers.add(new SimpleFieldMapper<>("raw_message", ILoggingEvent::getMessage));
        }

        if (includeCallerData) {
            builtInFieldMappers.add(new CallerDataFieldMapper());
        }

        if (includeRootCauseData) {
            builtInFieldMappers.add(new RootExceptionDataFieldMapper());
        }

        if (includeMarker) {
            builtInFieldMappers.add(new MarkerFieldMapper("marker"));
        }

        if (includeMdcData) {
            builtInFieldMappers.add(new MdcDataFieldMapper());