vy commented on code in PR #3045:
URL: https://github.com/apache/logging-log4j2/pull/3045#discussion_r1793306440


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePropertyRendererFactory.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.pattern;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import org.apache.logging.log4j.core.impl.ThrowableFormatOptions;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * A factory of {@link ThrowableRenderer} implementations for extracting 
certain properties from a {@link Throwable}.
+ */
+@NullMarked
+class ThrowablePropertyRendererFactory {
+
+    private static final ThrowableRenderer MESSAGE_RENDERER = (buffer, 
throwable, lineSeparator) -> {
+        final String message = throwable.getMessage();
+        buffer.append(message);
+    };
+
+    private static final ThrowableRenderer LOCALIZED_MESSAGE_RENDERER = 
(buffer, throwable, lineSeparator) -> {
+        final String localizedMessage = throwable.getLocalizedMessage();
+        buffer.append(localizedMessage);
+    };
+
+    private static final Function<Throwable, @Nullable StackTraceElement> 
THROWING_METHOD_EXTRACTOR = throwable -> {
+        @Nullable final StackTraceElement[] stackTraceElements = 
throwable.getStackTrace();
+        return (stackTraceElements != null && stackTraceElements.length > 0) ? 
stackTraceElements[0] : null;
+    };
+
+    static final ThrowablePropertyRendererFactory INSTANCE =
+            new ThrowablePropertyRendererFactory(THROWING_METHOD_EXTRACTOR);
+
+    private final Map<String, ThrowableRenderer> rendererByPropertyName;
+
+    ThrowablePropertyRendererFactory(final Function<Throwable, @Nullable 
StackTraceElement> throwingMethodExtractor) {

Review Comment:
   Package-private is more restrictive than `protected` – we shouldn't loosen 
the accessibility without a use case.



-- 
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]

Reply via email to