// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java
// public enum JsonGenerators {;
// 
//     private static final class DoubleWriterContext {
// 
//         private static final int MAX_BUFFER_LENGTH =
//                 String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length()
//                         + 1;
// 
//         private final StringBuilder builder = new StringBuilder();
// 
//         private char[] buffer = new char[MAX_BUFFER_LENGTH];
// 
//     }
// 
//     private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF =
//             Constants.ENABLE_THREADLOCALS
//                     ? ThreadLocal.withInitial(DoubleWriterContext::new)
//                     : null;
// 
//     public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException {
//         if (fractionalPart < 0) {
//             throw new IllegalArgumentException("negative fraction");
//         } else if (fractionalPart == 0) {
//             jsonGenerator.writeNumber(integralPart);
//         } else if (Constants.ENABLE_THREADLOCALS) {
//             DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get();
//             context.builder.setLength(0);
//             context.builder.append(integralPart);
//             context.builder.append('.');
//             context.builder.append(fractionalPart);
//             int length = context.builder.length();
//             context.builder.getChars(0, length, context.buffer, 0);
//             // jackson-core version >=2.10.2 is required for the following line
//             // to avoid FasterXML/jackson-core#588 bug.
//             jsonGenerator.writeRawValue(context.buffer, 0, length);
//         } else {
//             String formattedNumber = "" + integralPart + '.' + fractionalPart;
//             jsonGenerator.writeNumber(formattedNumber);
//         }
//     }
// 
//     /**
//      * Writes given object, preferably using GC-free writers.
//      */
//     public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException {
// 
//         if (object == null) {
//             jsonGenerator.writeNull();
//             return;
//         }
// 
//         if (object instanceof String) {
//             jsonGenerator.writeString((String) object);
//             return;
//         }
// 
//         if (object instanceof Short) {
//             jsonGenerator.writeNumber((Short) object);
//             return;
//         }
// 
//         if (object instanceof Integer) {
//             jsonGenerator.writeNumber((Integer) object);
//             return;
//         }
// 
//         if (object instanceof Long) {
//             jsonGenerator.writeNumber((Long) object);
//             return;
//         }
// 
//         if (object instanceof BigDecimal) {
//             jsonGenerator.writeNumber((BigDecimal) object);
//             return;
//         }
// 
//         if (object instanceof Float) {
//             jsonGenerator.writeNumber((Float) object);          // Not GC-free!
//             return;
//         }
// 
//         if (object instanceof Double) {
//             jsonGenerator.writeNumber((Double) object);         // Not GC-free!
//             return;
//         }
// 
//         if (object instanceof byte[]) {
//             jsonGenerator.writeBinary((byte[]) object);
//             return;
//         }
// 
//         jsonGenerator.writeObject(object);
// 
//     }
// 
// }


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.vlkan.log4j2.logstash.layout.util.JsonGenerators;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.message.*;
import org.apache.logging.log4j.util.TriConsumer;
import java.io.IOException;

        // Get the formatted message, if there is any.
        if (!jsonSupported) {
            writeObject(message, jsonGenerator);
            return true;
        }

        // Write the formatted JSON.
        String messageJson = multiformatMessage.getFormattedMessage(FORMATS);
        JsonNode jsonNode = readMessageJson(context, messageJson);
        boolean nodeExcluded = isNodeExcluded(jsonNode);
        if (nodeExcluded) {
            jsonGenerator.writeNull();
        } else {
            jsonGenerator.writeTree(jsonNode);
        }
        return true;

    }

    private static void writeMapMessage(JsonGenerator jsonGenerator, MapMessage<?, Object> mapMessage) throws IOException {
        jsonGenerator.writeStartObject();
        mapMessage.forEach(MAP_MESSAGE_ENTRY_WRITER, jsonGenerator);
        jsonGenerator.writeEndObject();
    }

    private static TriConsumer<String, Object, JsonGenerator> MAP_MESSAGE_ENTRY_WRITER =
            (key, value, jsonGenerator) -> {
                try {
                    jsonGenerator.writeFieldName(key);
// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/util/JsonGenerators.java
// public enum JsonGenerators {;
// 
//     private static final class DoubleWriterContext {
// 
//         private static final int MAX_BUFFER_LENGTH =
//                 String.format("%d.%d", Long.MAX_VALUE, Integer.MAX_VALUE).length()
//                         + 1;
// 
//         private final StringBuilder builder = new StringBuilder();
// 
//         private char[] buffer = new char[MAX_BUFFER_LENGTH];
// 
//     }
// 
//     private static final ThreadLocal<DoubleWriterContext> DOUBLE_WRITER_CONTEXT_REF =
//             Constants.ENABLE_THREADLOCALS
//                     ? ThreadLocal.withInitial(DoubleWriterContext::new)
//                     : null;
// 
//     public static void writeDouble(JsonGenerator jsonGenerator, long integralPart, int fractionalPart) throws IOException {
//         if (fractionalPart < 0) {
//             throw new IllegalArgumentException("negative fraction");
//         } else if (fractionalPart == 0) {
//             jsonGenerator.writeNumber(integralPart);
//         } else if (Constants.ENABLE_THREADLOCALS) {
//             DoubleWriterContext context = DOUBLE_WRITER_CONTEXT_REF.get();
//             context.builder.setLength(0);
//             context.builder.append(integralPart);
//             context.builder.append('.');
//             context.builder.append(fractionalPart);
//             int length = context.builder.length();
//             context.builder.getChars(0, length, context.buffer, 0);
//             // jackson-core version >=2.10.2 is required for the following line
//             // to avoid FasterXML/jackson-core#588 bug.
//             jsonGenerator.writeRawValue(context.buffer, 0, length);
//         } else {
//             String formattedNumber = "" + integralPart + '.' + fractionalPart;
//             jsonGenerator.writeNumber(formattedNumber);
//         }
//     }
// 
//     /**
//      * Writes given object, preferably using GC-free writers.
//      */
//     public static void writeObject(JsonGenerator jsonGenerator, Object object) throws IOException {
// 
//         if (object == null) {
//             jsonGenerator.writeNull();
//             return;
//         }
// 
//         if (object instanceof String) {
//             jsonGenerator.writeString((String) object);
//             return;
//         }
// 
//         if (object instanceof Short) {
//             jsonGenerator.writeNumber((Short) object);
//             return;
//         }
// 
//         if (object instanceof Integer) {
//             jsonGenerator.writeNumber((Integer) object);
//             return;
//         }
// 
//         if (object instanceof Long) {
//             jsonGenerator.writeNumber((Long) object);
//             return;
//         }
// 
//         if (object instanceof BigDecimal) {
//             jsonGenerator.writeNumber((BigDecimal) object);
//             return;
//         }
// 
//         if (object instanceof Float) {
//             jsonGenerator.writeNumber((Float) object);          // Not GC-free!
//             return;
//         }
// 
//         if (object instanceof Double) {
//             jsonGenerator.writeNumber((Double) object);         // Not GC-free!
//             return;
//         }
// 
//         if (object instanceof byte[]) {
//             jsonGenerator.writeBinary((byte[]) object);
//             return;
//         }
// 
//         jsonGenerator.writeObject(object);
// 
//     }
// 
// }


// Path: layout/src/main/java/com/vlkan/log4j2/logstash/layout/resolver/MessageResolver.java
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.vlkan.log4j2.logstash.layout.util.JsonGenerators;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.message.*;
import org.apache.logging.log4j.util.TriConsumer;
import java.io.IOException;


        // Get the formatted message, if there is any.
        if (!jsonSupported) {
            writeObject(message, jsonGenerator);
            return true;
        }

        // Write the formatted JSON.
        String messageJson = multiformatMessage.getFormattedMessage(FORMATS);
        JsonNode jsonNode = readMessageJson(context, messageJson);
        boolean nodeExcluded = isNodeExcluded(jsonNode);
        if (nodeExcluded) {
            jsonGenerator.writeNull();
        } else {
            jsonGenerator.writeTree(jsonNode);
        }
        return true;

    }

    private static void writeMapMessage(JsonGenerator jsonGenerator, MapMessage<?, Object> mapMessage) throws IOException {
        jsonGenerator.writeStartObject();
        mapMessage.forEach(MAP_MESSAGE_ENTRY_WRITER, jsonGenerator);
        jsonGenerator.writeEndObject();
    }

    private static TriConsumer<String, Object, JsonGenerator> MAP_MESSAGE_ENTRY_WRITER =
            (key, value, jsonGenerator) -> {
                try {
                    jsonGenerator.writeFieldName(key);
                    JsonGenerators.writeObject(jsonGenerator, value);