[I] JdbcAppender using buffersize property, mysql jdbc driver and ColumnConfig's clob property with true occurs java.io.IOException : Stream closed (logging-log4j2)

2024-10-27 Thread via GitHub


minseo300 opened a new issue, #3127:
URL: https://github.com/apache/logging-log4j2/issues/3127

   ## Description
   
   JdbcAppender using buffersize property, mysql jdbc driver and ColumnConfig's 
isClob property with true occurs  java.io.IOException : Stream closed.
   
   It doesn't occure when I configure JdbcAppender using bufferSize property, 
mysql jdbc driver and ColumnConfig's isClob property with false.
   And it doesn't occure when I configure JdbcAppender using mysql jdbc driver 
and ColumnConfig's isClob property with true.
   Also it doesn't occure when I configure JdbcAppender using the other jdbc 
driver(oracle, postgresql), bufferSize property and ColumnConfig's isClob 
property with true.
   
   As I analyzed it, when I configure JdbcAppender using buffer size property 
and ColumnConfig's isClob property with true, then 
JdbcDatabaseManager.writeInternal() set StringReader instance to 
PreparedStatement using setClob() api.
   
   Then, If current buffer size doesn't reach limit, call statement.addBatch() 
and if current buffer size reach to limit of buffer then call 
statement.executeUpdate().
   
   Close the StringReader object at the end, whether the buffer is full or not 
in "finally" block.
   
   I think there's a problem.
   
   ClientPreparedStatement(from mysql driver) uses StringReader instance passed 
by argument(The other driver like oracle makes new StringReader instance and 
use it, so they doesn't share instance).
   
   So, If JdbcDatabaseAppender close StringReader in finally block, 
StringReader is closed before statement.executeUpdate() then IOException : 
Stream is close exception is ocurred.
   
   I wondering is there any reason that Log4j2 JdbcDatabaseManager close 
StringReader in finally block, or this is just bug.
   
   log4j2.xml
   ```
   
   
   
   
   10
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   ```
   
   ## Configuration
   
   **Version: 2.17.1
   
   **Operating system: any
   
   **JDK: 1.8
   
   ## Logs
   
   ```
   "C:\Program Files\Java\java-1.8.0-openjdk-1.8\bin\java.exe" 
-Dvisualvm.id=1582776983231300 -XX:TieredStopAtLevel=1 -noverify 
-Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote 
-Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain 
-Dspring.application.admin.enabled=true 
"-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:C:\Program 
Files\JetBrains\IntelliJ IDEA 2023.1\lib\idea_rt.jar=59652:C:\Program 
Files\JetBrains\IntelliJ IDEA 2023.1\bin" -Dfile.encoding=UTF-8 -classpath 
"C:\Program Files\Java\java-1.8.0-openjdk-1.8\jre\lib\charsets.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\access-bridge-64.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\cldrdata.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\dnsns.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\jaccess.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\localedata.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\nashor
 n.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\sunec.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\sunjce_provider.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\sunmscapi.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\sunpkcs11.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\ext\zipfs.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\jce.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\jfr.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\jsse.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\management-agent.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\resources.jar;C:\Program 
Files\Java\java-1.8.0-openjdk-1.8\jre\lib\rt.jar;C:\Users\Tmax\Desktop\tt\target\classes;C:\Users\Tmax\.m2\repository\org\springframework\boot\spring-boot-starter\2.4.5\spring-boot-starter-2.4.5.jar;C:\Users\Tmax\.m2\repository\org\springframework\boot\spring-boot\2.4.5\spring-boot-2.4.5.jar;C
 
:\Users\Tmax\.m2\repository\org\springframework\spring-context\5.3.6\spring-context-5.3.6.jar;C:\Users\Tmax\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.4.5\spring-boot-autoconfigure-2.4.5.jar;C:\Users\Tmax\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\Tmax\.m2\repository\org\springframework\spring-core\5.3.6\spring-core-5.3.6.jar;C:\Users\Tmax\.m2\repository\org\springframework\spring-jcl\5.3.6\spring-jcl-5.3.6.jar;C:\Users\Tmax\.m2\repository\org\yaml\snakeyaml\1.27\snakeyaml-1.27.jar;C:\Users\Tmax\.m2\repository\org\projectlombok\lombok\1.18.30\lombok-1.18.30.jar;C:\Users\Tmax\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.4.5\spring-boot-starter-web-2.4.5.jar;C:\Users\Tmax\.m2\repository\or

Re: [PR] Bump actions/setup-java from 4.4.0 to 4.5.0 [logging-log4j-samples]

2024-10-27 Thread via GitHub


github-actions[bot] merged PR #211:
URL: https://github.com/apache/logging-log4j-samples/pull/211


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] Appender may caused deadlock on AsyncLoggerDisruptor (logging-log4j2)

2024-10-27 Thread via GitHub


github-actions[bot] commented on issue #2893:
URL: 
https://github.com/apache/logging-log4j2/issues/2893#issuecomment-2440353238

   This issue is stale because it has been waiting for your feedback for more 
than 60 days. The Apache Logging Services community values every submitted 
issue, but without additional information from you, we are unable to provide a 
solution to your problem.
   Please comment on this issue or it will be closed in 7 days.


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Simplify the Class interface in the next ABI [logging-log4cxx]

2024-10-27 Thread via GitHub


swebb2066 merged PR #421:
URL: https://github.com/apache/logging-log4cxx/pull/421


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[PR] Emulate effects of `j.u.l.Logger.setLevel` (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz opened a new pull request, #3125:
URL: https://github.com/apache/logging-log4j2/pull/3125

   Some libraries rely on `j.u.l.Logger.getLevel` returning the value that was 
set using `j.u.l.Logger.setLevel`.
   
   This PR changes #2353 so that:
   
   - By default, the **effective** configuration of the logging backend is not 
modified by `log4j-jul`.
   - Calling `setLevel` modifies the return value of `getLevel`. Both these 
methods should **not** be used in user code, because the **effective** level of 
a logger should be checked with `j.u.l.isLoggable` instead. Therefore, I don't 
see any potential problems with these modifications.
   
   Closes #3119
   
   


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Corrected incorrect tag to in XInclude logger example (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz commented on PR #3124:
URL: https://github.com/apache/logging-log4j2/pull/3124#issuecomment-2440031590

   @sugandhitushar,
   
   The corrected [corrected 
example](https://logging.apache.org/log4j/2.x/manual/configuration.html#xinclude)
 is online, Thanks!


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Rewrite date & time formatting (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz commented on code in PR #3121:
URL: https://github.com/apache/logging-log4j2/pull/3121#discussion_r1818174843


##
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolver.java:
##
@@ -18,13 +18,12 @@
 
 import java.util.Locale;
 import java.util.TimeZone;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.time.Instant;
-import org.apache.logging.log4j.core.time.MutableInstant;
+import org.apache.logging.log4j.core.util.internal.instant.InstantFormatter;
+import 
org.apache.logging.log4j.core.util.internal.instant.InstantNumberFormatter;
+import 
org.apache.logging.log4j.core.util.internal.instant.InstantPatternFormatter;

Review Comment:
   IIRC, when the subject of `exports ... to` came out on `dev@logging` (or 
maybe the PMC meeting) the consensus was that we should either export a package 
to all users or don't export it at all.
   
   As I stated above, we only need to put `InstantFormatter` in an exportable 
package. If the package has `spi` in it, users will know that it only should be 
used by Log4j Plugin implementors.



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Rewrite date & time formatting (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz commented on code in PR #3121:
URL: https://github.com/apache/logging-log4j2/pull/3121#discussion_r1818175071


##
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolver.java:
##
@@ -331,119 +273,48 @@ private static EventResolver createEpochResolver(final 
TemplateResolverConfig co
 throw new IllegalArgumentException("invalid epoch configuration: " + 
config);
 }
 
-private static final class EpochResolutionRecord {
-
-private static final int MAX_LONG_LENGTH =
-String.valueOf(Long.MAX_VALUE).length();
-
-private final MutableInstant instant = new MutableInstant();
-
-private final char[] resolution =
-new char[ /* integral: */MAX_LONG_LENGTH + /* dot: */ 1 + /* 
fractional: */ MAX_LONG_LENGTH];
-
-private int resolutionLength;
-
-private EpochResolutionRecord() {
-instant.initFromEpochSecond(-1, 0);
-}
-}
-
-private abstract static class EpochResolver implements EventResolver {
-
-private final Lock lock = new ReentrantLock();
-
-private final EpochResolutionRecord resolutionRecord = new 
EpochResolutionRecord();
-
-@Override
-public void resolve(final LogEvent logEvent, final JsonWriter 
jsonWriter) {
-lock.lock();
-try {
-unsynchronizedResolve(logEvent, jsonWriter);
-} finally {
-lock.unlock();
-}
-}
-
-private void unsynchronizedResolve(final LogEvent logEvent, final 
JsonWriter jsonWriter) {
-final Instant logEventInstant = logEvent.getInstant();
-if (logEventInstant.equals(resolutionRecord.instant)) {
-jsonWriter.writeRawString(resolutionRecord.resolution, 0, 
resolutionRecord.resolutionLength);
-} else {
-resolutionRecord.instant.initFrom(logEventInstant);
-final StringBuilder stringBuilder = 
jsonWriter.getStringBuilder();
-final int startIndex = stringBuilder.length();
-resolve(logEventInstant, jsonWriter);
-resolutionRecord.resolutionLength = stringBuilder.length() - 
startIndex;
-stringBuilder.getChars(startIndex, stringBuilder.length(), 
resolutionRecord.resolution, 0);
-}
-}
-
-abstract void resolve(Instant logEventInstant, JsonWriter jsonWriter);
-}
-
-private static final EventResolver EPOCH_NANOS_RESOLVER = new 
EpochResolver() {
-@Override
-void resolve(final Instant logEventInstant, final JsonWriter 
jsonWriter) {
-final long nanos = epochNanos(logEventInstant);
-jsonWriter.writeNumber(nanos);
-}
+private static final EventResolver EPOCH_NANOS_RESOLVER = (logEvent, 
jsonWriter) -> {
+final StringBuilder buffer = jsonWriter.getStringBuilder();
+final Instant instant = logEvent.getInstant();
+InstantNumberFormatter.EPOCH_NANOS.formatTo(buffer, instant);

Review Comment:
   Is this behavioral change intentional? The type of the field is changed from 
Number to String.



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Fix %xEx Performance regression (logging-log4j2)

2024-10-27 Thread via GitHub


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


##
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowableExtendedStackTraceRenderer.java:
##
@@ -105,12 +107,8 @@ private static Map 
createClassResourceInfoByName(
 // But we need the associated `Class` to extract its resource 
information, i.e., JAR file and version.
 // We are capturing the current stack to find suitable class 
loaders.
 // We will use this as a bootstrap to go from a class name in a 
stack trace to a `Class`.
-final Map classResourceInfoByName =
-StackLocatorUtil.getCurrentStackTrace().stream()
-.collect(Collectors.toMap(
-Class::getName,
-clazz -> new ClassResourceInfo(clazz, 
true),
-(classResourceInfo1, classResourceInfo2) 
-> classResourceInfo1));
+final Deque> rootStackTrace = 
StackLocatorUtil.getCurrentStackTrace();

Review Comment:
   I really don't like this deque hack – I know you borrowed it from the 
earlier version, hence not your fault. It makes things pretty difficult to wrap 
one's mind around it. I will spend more time on this sometime tomorrow to see 
if we can do something else...



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Rewrite date & time formatting (logging-log4j2)

2024-10-27 Thread via GitHub


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


##
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/InstantFormatter.java:
##
@@ -37,7 +37,10 @@
  * Note that {@link FixedDateFormat} and {@link FastDateFormat} only support
  * millisecond precision. If the pattern asks for a higher precision,
  * {@link DateTimeFormatter} will be employed, which is significantly slower.
+ * 
+ * @deprecated Starting with version {@code 2.25.0}, this class is planned to 
be removed in the next major release.
  */
+@Deprecated
 public final class InstantFormatter {

Review Comment:
   I deliberately do not want to. JTL's formatter was internal, it should not 
have been used. But there were no encapsulation mechanisms back then to enforce 
this. Users who are not comfortable with the current instant formatting should 
either submit a feature request or roll out their own instant formatters. But I 
am not willing to make ours public. (I will comment about JPMS/OSGi visibility 
in another conversation.)



##
log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternDynamicFormatter.java:
##
@@ -0,0 +1,807 @@
+/*
+ * 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.instant;
+
+import static java.util.Objects.requireNonNull;
+
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAccessor;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import org.apache.logging.log4j.core.time.Instant;
+import org.apache.logging.log4j.core.time.MutableInstant;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * An {@link InstantPatternFormatter} that uses {@link DateTimeFormatter} 
under the hood.
+ * The pattern is analyzed and parts that require a precision lower than or 
equal to {@value InstantPatternDynamicFormatter#PRECISION_THRESHOLD} are 
precomputed, cached, and updated once every {@value 
InstantPatternDynamicFormatter#PRECISION_THRESHOLD}.
+ * The rest is computed dynamically.
+ * 
+ * For instance, given the pattern {@code -MM-dd'T'HH:mm:ss.SSSX}, the 
generated formatter will
+ * 
+ * 
+ * Sequence the pattern and assign a time precision to each part (e.g., 
{@code MM} is of month precision)
+ * Precompute and cache the output for parts that are of precision lower 
than or equal to {@value InstantPatternDynamicFormatter#PRECISION_THRESHOLD} 
(i.e., {@code -MM-dd'T'HH:mm:} and {@code X}) and cache it
+ * Upon a formatting request, combine the cached outputs with the dynamic 
parts (i.e., {@code ss.SSS})
+ * 
+ *
+ * @since 2.25.0
+ */
+public final class InstantPatternDynamicFormatter implements 
InstantPatternFormatter {
+
+static final ChronoUnit PRECISION_THRESHOLD = ChronoUnit.MINUTES;
+
+private final AtomicReference 
timestampedFormatterRef;
+
+InstantPatternDynamicFormatter(final String pattern, final Locale locale, 
final TimeZone timeZone) {
+final TimestampedFormatter timestampedFormatter = 
createTimestampedFormatter(pattern, locale, timeZone, null);
+this.timestampedFormatterRef = new 
AtomicReference<>(timestampedFormatter);
+}
+
+@Override
+public String getPattern() {
+return timestampedFormatterRef.get().formatter.getPattern();
+}
+
+@Override
+public Locale getLocale() {
+return timestampedFormatterRef.get().formatter.getLocale();
+}
+
+@Override
+public TimeZone getTimeZone() {
+return timestampedFormatterRef.get().formatter.getTimeZone();
+}
+
+@Override
+public ChronoUnit getPrecision() {
+return timestampedFormatterRef.get().formatter.getPrecision();
+}
+
+@Override
+public void formatTo(final StringBuilder buffer, final Instant instant) {
+requireNonNull(buffer, "buffer"

Re: [PR] Rewrite date & time formatting (logging-log4j2)

2024-10-27 Thread via GitHub


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


##
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java:
##
@@ -16,38 +16,50 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
+import static java.util.Objects.requireNonNull;
+
+import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.Locale;
-import java.util.Objects;
 import java.util.TimeZone;
-import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.time.FastDateFormat;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.time.Instant;
 import org.apache.logging.log4j.core.time.MutableInstant;
-import org.apache.logging.log4j.core.util.Constants;
-import org.apache.logging.log4j.core.util.datetime.FastDateFormat;
 import org.apache.logging.log4j.core.util.datetime.FixedDateFormat;
-import org.apache.logging.log4j.core.util.datetime.FixedDateFormat.FixedFormat;
+import org.apache.logging.log4j.core.util.internal.instant.InstantFormatter;
+import 
org.apache.logging.log4j.core.util.internal.instant.InstantNumberFormatter;
+import 
org.apache.logging.log4j.core.util.internal.instant.InstantPatternFormatter;
 import org.apache.logging.log4j.util.PerformanceSensitive;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
 
 /**
  * Converts and formats the event's date in a StringBuilder.
  */
+@SuppressWarnings("deprecation")
 @Plugin(name = "DatePatternConverter", category = PatternConverter.CATEGORY)
 @ConverterKeys({"d", "date"})
 @PerformanceSensitive("allocation")
+@NullMarked
 public final class DatePatternConverter extends LogEventPatternConverter 
implements ArrayPatternConverter {
 
-private abstract static class Formatter {
-long previousTime; // for ThreadLocal caching mode
-int nanos;
+private static final String CLASS_NAME = 
DatePatternConverter.class.getSimpleName();
+
+private static final String DEFAULT_PATTERN = "-MM-dd HH:mm:ss,SSS";
 
-abstract String format(final Instant instant);
+private abstract static class Formatter {
 
-abstract void formatToBuffer(final Instant instant, StringBuilder 
destination);
+final F delegate;
+
+private Formatter(final F delegate) {
+this.delegate = delegate;
+}

Review Comment:
   Good catch! Removed in ff4f6882b618ed65bb547d4bcb3c46a1eb4f810e.



##
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolver.java:
##
@@ -18,13 +18,12 @@
 
 import java.util.Locale;
 import java.util.TimeZone;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.time.Instant;
-import org.apache.logging.log4j.core.time.MutableInstant;
+import org.apache.logging.log4j.core.util.internal.instant.InstantFormatter;
+import 
org.apache.logging.log4j.core.util.internal.instant.InstantNumberFormatter;
+import 
org.apache.logging.log4j.core.util.internal.instant.InstantPatternFormatter;

Review Comment:
   > OSGi needs the package to be exported to anyone.
   
   Isn't there any other way for OSGi? (Yes, I don't want to open up the new 
package & classes.)



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [I] log4j-jul adapter makes code throws NPEs (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz commented on issue #3119:
URL: 
https://github.com/apache/logging-log4j2/issues/3119#issuecomment-2439980246

   @simmel,
   
   Nice catch! Thank you for debugging it this far!
   
   From my perspective the issue is caused by an initialization problem of the 
[`MethodHandleFactory`](https://github.com/openjdk/nashorn/blob/main/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java)
 class:
   
   - The initialization of the `MethodHandleFactory` starts by creating an 
instance of the nested 
[`StandardMethodHandleFunctionality`](https://github.com/openjdk/nashorn/blob/2eb88e4024023ee8e9baacb7736f914e3aa68aa4/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/lookup/MethodHandleFactory.java#L319)
 class.
   - The `StandardMethodHandleFunctionality` instance uses static fields and 
methods of the yet-to-be-initialized `MethodHandleFactory` class.
   - The usage of these methods and fields is only protected by 
`DebugLogger.DISABLED_LOGGER.isEnabled()` being `false`.
   - If you use `log4j-jul`, that method will return `true` and a lot of NPEs 
will follow.
   
   In https://github.com/openjdk/nashorn/pull/19 I proposed a more fool-proof 
way to check if the `MethodHandleFactory` methods can be used.
   
   In the meantime we can add a workaround to Log4j (see 
https://github.com/apache/logging-log4j2/pull/3125) that will guarantee that 
the (ineffective) `getLevel()` and `setLevel()` methods return coherent 
results. This should fix your immediate problem.
   
   **PS**: I think that both the above mentioned PRs are just workarounds for a 
bigger problem: Nashorn tries to modify the logging configuration of your 
application. I have started a [thread on 
`nashorn-dev@openjdk`](https://mail.openjdk.org/pipermail/nashorn-dev/2024-October/007687.html)
 to see if the Nashorn team would be willing to modify that behavior.


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Emulate effects of `j.u.l.Logger.setLevel` (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz commented on PR #3125:
URL: https://github.com/apache/logging-log4j2/pull/3125#issuecomment-2439983713

   Anticipating other similar problems with the `j.u.l.Logger` methods, what do 
you think about implementing in term of "WARN + super" also the: `setFilter`, 
`addHandler`, `removeHandler`, `setUseParentHandler`? We can still keep the 
current implementation for `setParent` (throwing).
   
   The 
[`setResourceBundle`](https://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html#setResourceBundle-java.util.ResourceBundle-)
 method, on the other hand, should probably be implemented differently: after 
it is called, we need to replace the message factory used by the JUL bridge 
with one the uses the specified bundle.


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Corrected incorrect tag to in XInclude logger example (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz merged PR #3124:
URL: https://github.com/apache/logging-log4j2/pull/3124


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Corrected incorrect tag to in XInclude logger example (logging-log4j2)

2024-10-27 Thread via GitHub


github-actions[bot] commented on PR #3124:
URL: https://github.com/apache/logging-log4j2/pull/3124#issuecomment-2439990166

   
   
   
   
   Job
   Requested goals
   Build Tool Version
   Build Outcome
   Build Scan®
   
   
   build-macos-latest
   clean install
   3.9.8
   :white_check_mark:
   https://ge.apache.org/s/ctiahveftltku"; 
rel="nofollow">https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle";
 alt="Build Scan PUBLISHED" />
   
   
   build-ubuntu-latest
   clean install
   3.9.8
   :white_check_mark:
   https://ge.apache.org/s/jtljoewvg7klc"; 
rel="nofollow">https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle";
 alt="Build Scan PUBLISHED" />
   
   
   build-windows-latest
   clean install
   3.9.8
   :white_check_mark:
   https://ge.apache.org/s/4ozjrlti3l3rw"; 
rel="nofollow">https://img.shields.io/badge/Build%20Scan%C2%AE-PUBLISHED-06A0CE?logo=Gradle";
 alt="Build Scan PUBLISHED" />
   
   
   
   
   ## Generated by gradle/develocity-actions
   


-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Rewrite date & time formatting (logging-log4j2)

2024-10-27 Thread via GitHub


ppkarwasz commented on code in PR #3121:
URL: https://github.com/apache/logging-log4j2/pull/3121#discussion_r1818179034


##
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolver.java:
##
@@ -331,119 +273,48 @@ private static EventResolver createEpochResolver(final 
TemplateResolverConfig co
 throw new IllegalArgumentException("invalid epoch configuration: " + 
config);
 }
 
-private static final class EpochResolutionRecord {
-
-private static final int MAX_LONG_LENGTH =
-String.valueOf(Long.MAX_VALUE).length();
-
-private final MutableInstant instant = new MutableInstant();
-
-private final char[] resolution =
-new char[ /* integral: */MAX_LONG_LENGTH + /* dot: */ 1 + /* 
fractional: */ MAX_LONG_LENGTH];
-
-private int resolutionLength;
-
-private EpochResolutionRecord() {
-instant.initFromEpochSecond(-1, 0);
-}
-}
-
-private abstract static class EpochResolver implements EventResolver {
-
-private final Lock lock = new ReentrantLock();
-
-private final EpochResolutionRecord resolutionRecord = new 
EpochResolutionRecord();
-
-@Override
-public void resolve(final LogEvent logEvent, final JsonWriter 
jsonWriter) {
-lock.lock();
-try {
-unsynchronizedResolve(logEvent, jsonWriter);
-} finally {
-lock.unlock();
-}
-}
-
-private void unsynchronizedResolve(final LogEvent logEvent, final 
JsonWriter jsonWriter) {
-final Instant logEventInstant = logEvent.getInstant();
-if (logEventInstant.equals(resolutionRecord.instant)) {
-jsonWriter.writeRawString(resolutionRecord.resolution, 0, 
resolutionRecord.resolutionLength);
-} else {
-resolutionRecord.instant.initFrom(logEventInstant);
-final StringBuilder stringBuilder = 
jsonWriter.getStringBuilder();
-final int startIndex = stringBuilder.length();
-resolve(logEventInstant, jsonWriter);
-resolutionRecord.resolutionLength = stringBuilder.length() - 
startIndex;
-stringBuilder.getChars(startIndex, stringBuilder.length(), 
resolutionRecord.resolution, 0);
-}
-}
-
-abstract void resolve(Instant logEventInstant, JsonWriter jsonWriter);
-}
-
-private static final EventResolver EPOCH_NANOS_RESOLVER = new 
EpochResolver() {
-@Override
-void resolve(final Instant logEventInstant, final JsonWriter 
jsonWriter) {
-final long nanos = epochNanos(logEventInstant);
-jsonWriter.writeNumber(nanos);
-}
+private static final EventResolver EPOCH_NANOS_RESOLVER = (logEvent, 
jsonWriter) -> {
+final StringBuilder buffer = jsonWriter.getStringBuilder();
+final Instant instant = logEvent.getInstant();
+InstantNumberFormatter.EPOCH_NANOS.formatTo(buffer, instant);

Review Comment:
   Ah, so you are writing a **raw** string to JSON? I didn't know this was 
possible.



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Rewrite date & time formatting (logging-log4j2)

2024-10-27 Thread via GitHub


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


##
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolver.java:
##
@@ -331,119 +273,48 @@ private static EventResolver createEpochResolver(final 
TemplateResolverConfig co
 throw new IllegalArgumentException("invalid epoch configuration: " + 
config);
 }
 
-private static final class EpochResolutionRecord {
-
-private static final int MAX_LONG_LENGTH =
-String.valueOf(Long.MAX_VALUE).length();
-
-private final MutableInstant instant = new MutableInstant();
-
-private final char[] resolution =
-new char[ /* integral: */MAX_LONG_LENGTH + /* dot: */ 1 + /* 
fractional: */ MAX_LONG_LENGTH];
-
-private int resolutionLength;
-
-private EpochResolutionRecord() {
-instant.initFromEpochSecond(-1, 0);
-}
-}
-
-private abstract static class EpochResolver implements EventResolver {
-
-private final Lock lock = new ReentrantLock();
-
-private final EpochResolutionRecord resolutionRecord = new 
EpochResolutionRecord();
-
-@Override
-public void resolve(final LogEvent logEvent, final JsonWriter 
jsonWriter) {
-lock.lock();
-try {
-unsynchronizedResolve(logEvent, jsonWriter);
-} finally {
-lock.unlock();
-}
-}
-
-private void unsynchronizedResolve(final LogEvent logEvent, final 
JsonWriter jsonWriter) {
-final Instant logEventInstant = logEvent.getInstant();
-if (logEventInstant.equals(resolutionRecord.instant)) {
-jsonWriter.writeRawString(resolutionRecord.resolution, 0, 
resolutionRecord.resolutionLength);
-} else {
-resolutionRecord.instant.initFrom(logEventInstant);
-final StringBuilder stringBuilder = 
jsonWriter.getStringBuilder();
-final int startIndex = stringBuilder.length();
-resolve(logEventInstant, jsonWriter);
-resolutionRecord.resolutionLength = stringBuilder.length() - 
startIndex;
-stringBuilder.getChars(startIndex, stringBuilder.length(), 
resolutionRecord.resolution, 0);
-}
-}
-
-abstract void resolve(Instant logEventInstant, JsonWriter jsonWriter);
-}
-
-private static final EventResolver EPOCH_NANOS_RESOLVER = new 
EpochResolver() {
-@Override
-void resolve(final Instant logEventInstant, final JsonWriter 
jsonWriter) {
-final long nanos = epochNanos(logEventInstant);
-jsonWriter.writeNumber(nanos);
-}
+private static final EventResolver EPOCH_NANOS_RESOLVER = (logEvent, 
jsonWriter) -> {
+final StringBuilder buffer = jsonWriter.getStringBuilder();
+final Instant instant = logEvent.getInstant();
+InstantNumberFormatter.EPOCH_NANOS.formatTo(buffer, instant);

Review Comment:
   The output is still a number, though this time directly written to the SB. 
Am I missing something?



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] Fix %xEx Performance regression (logging-log4j2)

2024-10-27 Thread via GitHub


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


##
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ClassResourceInfo.java:
##


Review Comment:
   Could you instead keep the old version but replace `private final String 
text` with `private final Lazy textRef` such that
   
   * in ctor[0], use `Lazy.value("~[?:?]")`
   * in ctor[2], use `Lazy.lazy(() -> getText())`



-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org