gnodet commented on code in PR #13832:
URL: https://github.com/apache/maven/pull/13832#discussion_r4548403012


##########
impl/maven-logging/src/main/java/org/apache/maven/logging/impl/DefaultLogger.java:
##########
@@ -0,0 +1,419 @@
+/*
+ * 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.maven.logging.impl;
+
+import java.lang.StackWalker.StackFrame;
+import java.time.Instant;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Supplier;
+
+import org.apache.maven.api.MonotonicClock;
+import org.apache.maven.api.logging.LogEvent;
+import org.apache.maven.api.logging.LogEventBuilder;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.LogSink;
+import org.apache.maven.api.logging.Logger;
+import org.apache.maven.api.logging.LoggerManager;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Default implementation of both {@link Logger} (new fluent API)
+ * and the deprecated {@link org.apache.maven.api.plugin.Log} (backward 
compatibility).
+ * <p>
+ * Builds fully-structured {@link LogEvent} objects — including {@code 
projectId},
+ * {@code mojoId}, timestamp, and sequence number — and dispatches them to the
+ * current {@link LogSink} obtained from {@link LoggerManager#get()}.
+ * Level checks and sink lookup both go through the {@code LoggerManager},
+ * so the sink can be changed at runtime.
+ *
+ * @since 4.2.0
+ */
+@SuppressWarnings("deprecation")
+public class DefaultLogger implements Logger, org.apache.maven.api.plugin.Log {
+
+    private static final StackWalker WALKER = StackWalker.getInstance();
+    private static final String THIS_CLASS = DefaultLogger.class.getName();
+    private static final String BUILDER_CLASS = 
DefaultLogEventBuilder.class.getName();
+
+    private static final AtomicLong SEQUENCE = new AtomicLong();
+
+    private final String name;
+    private final String projectId;
+    private final String mojoId;
+
+    public DefaultLogger(String name) {
+        this(name, null, null);
+    }
+
+    public DefaultLogger(String name, String projectId, String mojoId) {
+        this.name = requireNonNull(name, "name");
+        this.projectId = projectId;
+        this.mojoId = mojoId;
+    }
+
+    // ---- org.apache.maven.api.logging.Logger ----
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    private boolean isLevelEnabled(LogLevel level) {
+        return LoggerManager.get().isLevelEnabled(name, level);
+    }
+
+    @Override
+    public boolean isEnabled(LogLevel level) {
+        return isLevelEnabled(level);
+    }
+
+    @Override
+    public LogEventBuilder atTrace() {
+        return isLevelEnabled(LogLevel.TRACE)
+                ? new DefaultLogEventBuilder(this, LogLevel.TRACE)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atDebug() {
+        return isLevelEnabled(LogLevel.DEBUG)
+                ? new DefaultLogEventBuilder(this, LogLevel.DEBUG)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atInfo() {
+        return isLevelEnabled(LogLevel.INFO)
+                ? new DefaultLogEventBuilder(this, LogLevel.INFO)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atWarn() {
+        return isLevelEnabled(LogLevel.WARN)
+                ? new DefaultLogEventBuilder(this, LogLevel.WARN)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atError() {
+        return isLevelEnabled(LogLevel.ERROR)
+                ? new DefaultLogEventBuilder(this, LogLevel.ERROR)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder at(LogLevel level) {
+        return isLevelEnabled(level) ? new DefaultLogEventBuilder(this, level) 
: NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public DefaultLogger child(String childName) {
+        requireNonNull(childName, "childName");
+        return new DefaultLogger(name + "." + childName, projectId, mojoId);
+    }
+
+    // ---- Internal dispatch ----
+
+    void doLog(LogLevel level, String message, Throwable throwable) {
+        doLog(level, message, null, null, null, throwable, null, null);
+    }
+
+    @SuppressWarnings("deprecation") // Thread.getId()
+    void doLog(
+            LogLevel level,
+            String message,
+            String messageTemplate,
+            Object[] messageArgs,
+            Map<String, Object> keyValues,
+            Throwable throwable) {
+        doLog(level, message, messageTemplate, messageArgs, keyValues, 
throwable, null, null);
+    }
+
+    @SuppressWarnings({"deprecation", "checkstyle:ParameterNumber"}) // 
Thread.getId()
+    void doLog(
+            LogLevel level,
+            String message,
+            String messageTemplate,
+            Object[] messageArgs,
+            Map<String, Object> keyValues,
+            Throwable throwable,
+            String projectIdOverride,
+            String mojoIdOverride) {
+        LoggerManager mgr = LoggerManager.get();
+        LogSink sink = mgr.getLogSink();
+        if (sink == null) {
+            return;
+        }
+
+        Instant timestamp = MonotonicClock.now();
+        long seq = SEQUENCE.getAndIncrement();
+
+        String sourceClass = null;
+        String sourceMethod = null;
+        long threadId = -1;
+        String threadName = null;
+
+        if (sink.needsMetadata()) {
+            sourceClass = name;
+            sourceMethod = resolveCallerMethod();
+            threadId = Thread.currentThread().getId();

Review Comment:
   Acknowledged — `Thread.currentThread().getId()` is used with 
`@SuppressWarnings("deprecation")` and a TODO comment: `// TODO: replace with 
threadId() when baseline ≥ JDK 19`. The project baseline is JDK 17, so 
`threadId()` is not available yet.



##########
impl/maven-logging/src/main/java/org/apache/maven/logging/impl/DefaultLogger.java:
##########
@@ -0,0 +1,419 @@
+/*
+ * 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.maven.logging.impl;
+
+import java.lang.StackWalker.StackFrame;
+import java.time.Instant;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Supplier;
+
+import org.apache.maven.api.MonotonicClock;
+import org.apache.maven.api.logging.LogEvent;
+import org.apache.maven.api.logging.LogEventBuilder;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.LogSink;
+import org.apache.maven.api.logging.Logger;
+import org.apache.maven.api.logging.LoggerManager;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Default implementation of both {@link Logger} (new fluent API)
+ * and the deprecated {@link org.apache.maven.api.plugin.Log} (backward 
compatibility).
+ * <p>
+ * Builds fully-structured {@link LogEvent} objects — including {@code 
projectId},
+ * {@code mojoId}, timestamp, and sequence number — and dispatches them to the
+ * current {@link LogSink} obtained from {@link LoggerManager#get()}.
+ * Level checks and sink lookup both go through the {@code LoggerManager},
+ * so the sink can be changed at runtime.
+ *
+ * @since 4.2.0
+ */
+@SuppressWarnings("deprecation")
+public class DefaultLogger implements Logger, org.apache.maven.api.plugin.Log {
+
+    private static final StackWalker WALKER = StackWalker.getInstance();
+    private static final String THIS_CLASS = DefaultLogger.class.getName();
+    private static final String BUILDER_CLASS = 
DefaultLogEventBuilder.class.getName();
+
+    private static final AtomicLong SEQUENCE = new AtomicLong();
+
+    private final String name;
+    private final String projectId;
+    private final String mojoId;
+
+    public DefaultLogger(String name) {
+        this(name, null, null);
+    }
+
+    public DefaultLogger(String name, String projectId, String mojoId) {
+        this.name = requireNonNull(name, "name");
+        this.projectId = projectId;
+        this.mojoId = mojoId;
+    }
+
+    // ---- org.apache.maven.api.logging.Logger ----
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    private boolean isLevelEnabled(LogLevel level) {
+        return LoggerManager.get().isLevelEnabled(name, level);
+    }
+
+    @Override
+    public boolean isEnabled(LogLevel level) {
+        return isLevelEnabled(level);
+    }
+
+    @Override
+    public LogEventBuilder atTrace() {
+        return isLevelEnabled(LogLevel.TRACE)
+                ? new DefaultLogEventBuilder(this, LogLevel.TRACE)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atDebug() {
+        return isLevelEnabled(LogLevel.DEBUG)
+                ? new DefaultLogEventBuilder(this, LogLevel.DEBUG)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atInfo() {
+        return isLevelEnabled(LogLevel.INFO)
+                ? new DefaultLogEventBuilder(this, LogLevel.INFO)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atWarn() {
+        return isLevelEnabled(LogLevel.WARN)
+                ? new DefaultLogEventBuilder(this, LogLevel.WARN)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder atError() {
+        return isLevelEnabled(LogLevel.ERROR)
+                ? new DefaultLogEventBuilder(this, LogLevel.ERROR)
+                : NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public LogEventBuilder at(LogLevel level) {
+        return isLevelEnabled(level) ? new DefaultLogEventBuilder(this, level) 
: NopLogEventBuilder.INSTANCE;
+    }
+
+    @Override
+    public DefaultLogger child(String childName) {
+        requireNonNull(childName, "childName");
+        return new DefaultLogger(name + "." + childName, projectId, mojoId);
+    }
+
+    // ---- Internal dispatch ----
+
+    void doLog(LogLevel level, String message, Throwable throwable) {
+        doLog(level, message, null, null, null, throwable, null, null);
+    }
+
+    @SuppressWarnings("deprecation") // Thread.getId()
+    void doLog(
+            LogLevel level,
+            String message,
+            String messageTemplate,
+            Object[] messageArgs,
+            Map<String, Object> keyValues,
+            Throwable throwable) {
+        doLog(level, message, messageTemplate, messageArgs, keyValues, 
throwable, null, null);
+    }
+
+    @SuppressWarnings({"deprecation", "checkstyle:ParameterNumber"}) // 
Thread.getId()
+    void doLog(
+            LogLevel level,
+            String message,
+            String messageTemplate,
+            Object[] messageArgs,
+            Map<String, Object> keyValues,
+            Throwable throwable,
+            String projectIdOverride,
+            String mojoIdOverride) {
+        LoggerManager mgr = LoggerManager.get();
+        LogSink sink = mgr.getLogSink();
+        if (sink == null) {
+            return;
+        }
+
+        Instant timestamp = MonotonicClock.now();
+        long seq = SEQUENCE.getAndIncrement();
+
+        String sourceClass = null;
+        String sourceMethod = null;
+        long threadId = -1;
+        String threadName = null;
+
+        if (sink.needsMetadata()) {
+            sourceClass = name;
+            sourceMethod = resolveCallerMethod();
+            threadId = Thread.currentThread().getId();

Review Comment:
   Acknowledged — already annotated with `@SuppressWarnings("deprecation")` and 
a TODO: `// TODO: replace with threadId() when baseline ≥ JDK 19`. JDK 17 
baseline does not have `threadId()`.



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