vy commented on code in PR #820:
URL: https://github.com/apache/logging-log4j2/pull/820#discussion_r851233208
##########
log4j-slf4j20-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java:
##########
@@ -16,16 +16,87 @@
*/
package org.apache.logging.slf4j;
+import java.util.ArrayDeque;
+import java.util.Deque;
import java.util.Map;
+import java.util.Objects;
+import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.Strings;
import org.slf4j.spi.MDCAdapter;
/**
*
*/
public class Log4jMDCAdapter implements MDCAdapter {
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final char QUOTE_CHAR = '\"';
+ private static final char ESCAPE_CHAR = '\\';
+ private static final char ARRAY_START = '[';
+ private static final char ARRAY_SEP = ',';
+ private static final char ARRAY_END = ']';
+ private static final String EMPTY_ARRAY = "[]";
+
+ /**
+ * Quotes a string using a simplified JSON quoting mechanism.
+ */
+ static void quoteString(final CharSequence value, final StringBuilder
output) {
Review Comment:
In accordance with my comment below, I would rather move `JsonWriter` from
JTL to core and reuse it here.
##########
log4j-slf4j20-impl/src/main/java/org/apache/logging/slf4j/Log4jMDCAdapter.java:
##########
@@ -16,16 +16,87 @@
*/
package org.apache.logging.slf4j;
+import java.util.ArrayDeque;
+import java.util.Deque;
import java.util.Map;
+import java.util.Objects;
+import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.Strings;
import org.slf4j.spi.MDCAdapter;
/**
*
*/
public class Log4jMDCAdapter implements MDCAdapter {
+ private static final Logger LOGGER = StatusLogger.getLogger();
+
+ private static final char QUOTE_CHAR = '\"';
+ private static final char ESCAPE_CHAR = '\\';
+ private static final char ARRAY_START = '[';
+ private static final char ARRAY_SEP = ',';
+ private static final char ARRAY_END = ']';
+ private static final String EMPTY_ARRAY = "[]";
+
+ /**
+ * Quotes a string using a simplified JSON quoting mechanism.
+ */
+ static void quoteString(final CharSequence value, final StringBuilder
output) {
+ output.append(QUOTE_CHAR);
+ int i = 0;
+ while (i < value.length()) {
+ final char c = value.charAt(i);
+ switch (c) {
+ case ESCAPE_CHAR:
+ case QUOTE_CHAR:
+ output.append(ESCAPE_CHAR);
+ // intentional fall through
+ default:
+ output.append(c);
+ }
+ i++;
+ }
+ output.append(QUOTE_CHAR);
+ }
+
+ /**
+ * Splits a valid and non empty JSON array into a head and tail part.
Unicode
+ * escapes are not supported.
+ */
+ static void splitString(final char[] value, final String[] output) throws
ArrayIndexOutOfBoundsException {
Review Comment:
We have already moved `JsonReader` in `master` from JTL to core. I propose
doing the same for `release-2.x` and using it here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]