[ 
https://issues.apache.org/jira/browse/LOG4J2-3627?focusedWorklogId=924212&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-924212
 ]

ASF GitHub Bot logged work on LOG4J2-3627:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Jul/24 17:01
            Start Date: 02/Jul/24 17:01
    Worklog Time Spent: 10m 
      Work Description: vy commented on code in PR #2691:
URL: https://github.com/apache/logging-log4j2/pull/2691#discussion_r1657060422


##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/StringBuildersTest.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.stream.Stream;
+import org.apache.logging.log4j.core.util.internal.StringBuilders;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+public class StringBuildersTest {
+
+    static Stream<Arguments> testTruncateLines_dataSource() {

Review Comment:
   No, those were the `buffer` content to test.



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/RootThrowablePatternConverter.java:
##########
@@ -68,27 +67,17 @@ public void format(final LogEvent event, final 
StringBuilder toAppendTo) {
                 super.format(event, toAppendTo);
                 return;
             }
-            final String trace = proxy.getCauseStackTraceAsString(
-                    options.getIgnorePackages(), options.getTextRenderer(), 
getSuffix(event), options.getSeparator());
             final int len = toAppendTo.length();
             if (len > 0 && !Character.isWhitespace(toAppendTo.charAt(len - 
1))) {
                 toAppendTo.append(' ');
             }
-            if (!options.allLines() || 
!Strings.LINE_SEPARATOR.equals(options.getSeparator())) {
-                final StringBuilder sb = new StringBuilder();
-                final String[] array = trace.split(Strings.LINE_SEPARATOR);
-                final int limit = options.minLines(array.length) - 1;
-                for (int i = 0; i <= limit; ++i) {
-                    sb.append(array[i]);
-                    if (i < limit) {
-                        sb.append(options.getSeparator());
-                    }
-                }
-                toAppendTo.append(sb.toString());
-
-            } else {
-                toAppendTo.append(trace);
-            }
+            proxy.formatCauseStackTraceTo(
+                    toAppendTo,
+                    options.getIgnorePackages(),
+                    options.getTextRenderer(),
+                    getSuffix(event),
+                    options.getSeparator(),
+                    options.allLines() ? null : options.getLines());

Review Comment:
   @alan0428a, sounds good.



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/StringBuilders.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.util.internal;
+
+/**
+ * StringBuilder helpers
+ */
+public class StringBuilders {
+
+    /**
+     * Truncates the content of the given {@code StringBuilder} to the 
specified maximum number of lines.
+     *
+     * <p>If {@code maxLineCount} is {@code null}, {@link Integer#MAX_VALUE}, 
or if {@code lineSeparator} is empty,
+     * the method returns without making any changes to the {@code 
StringBuilder}.
+     *
+     * @param buffer             the {@code StringBuilder} whose content is to 
be truncated
+     * @param lineSeparator  the line separator used to determine the end of a 
line
+     * @param maxLineCount   the maximum number of lines to retain in the 
{@code StringBuilder};
+     *                       if this value is {@code null} or {@link 
Integer#MAX_VALUE}, no truncation will occur
+     */
+    public static void truncateLines(

Review Comment:
   You're right massage the `if` condition as follows:
   ```
   buffer.length() < delimiter.length() || delimiter.isEmpty() || 
maxOccurrenceCount == Integer.MAX_VALUE
   ```



##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/pattern/ThrowableFilterTest.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.appender.ListAppender;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.core.test.junit.Named;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit tests for {@code throwable} pattern.
+ */
+@LoggerContextSource("log4j-throwable-filter.xml")
+public class ThrowableFilterTest {

Review Comment:
   @alan0428a, please proceed with the `ConfigurationBuilder` approach. I will 
internally talk with @ppkarwasz and if changes are needed, we will carry them 
out ourselves later.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 924212)
    Time Spent: 1h 40m  (was: 1.5h)

> PatternLayout: %xEx{ [ "short" | depth]} not working
> ----------------------------------------------------
>
>                 Key: LOG4J2-3627
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3627
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts
>    Affects Versions: 2.11.0, 2.11.1, 2.11.2, 2.12.0, 2.12.1, 2.13.0, 2.13.1, 
> 2.13.2, 2.14.0, 2.13.3, 2.14.1, 2.15.0, 2.16.0, 2.17.1, 2.17.0, 2.12.3, 
> 2.12.2, 2.18.0, 2.12.4, 2.17.2, 2.19.0
>            Reporter: Thorsten Heit
>            Assignee: Volkan Yazici
>            Priority: Minor
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> According to the documentation the patterns {{{}%xEx{short{}}}} or 
> {{{}%xEx{<num>{}}}} should limit the number of lines of a stack trace that is 
> logged. This doesn't work; instead, the complete stack trace is logged 
> (always!). This is in contrary to the patterns {{%ex}} or {{%rEx}} where this 
> works.
> In commit 9ff63b2e50be754ae394feda2c33d9e64fd0ab3a (2018-01-25) a change was 
> implemented because of LOG4J2-2195 (according to the commit message) that 
> removed the option of limiting the number of lines to output.
> Therefore all versions since 2.11.0 should be affected.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to