gnodet-bot commented on code in PR #14066:
URL: https://github.com/apache/maven/pull/14066#discussion_r4615849011


##########
api/maven-api-log/src/main/java/org/apache/maven/api/logging/package-info.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+/**
+ * Maven unified logging API — a first-class, SLF4J-free logging facade for
+ * plugins and extensions.
+ *
+ * <h2>Core types</h2>
+ * <dl>
+ *   <dt>{@link org.apache.maven.api.logging.Logger}</dt>
+ *   <dd>The primary logging interface injected by the container. Supports a 
fluent builder
+ *   API ({@code atInfo()...log(...)}) as well as SLF4J-style convenience 
methods
+ *   ({@code info(...)}, {@code warn(...)}, etc.).</dd>
+ *
+ *   <dt>{@link org.apache.maven.api.logging.LogEventBuilder}</dt>
+ *   <dd>Fluent builder for a single log event, obtained from {@code 
Logger.atLevel()}.

Review Comment:
   Doc typo: `Logger.atLevel()` does not exist. The actual method is 
`Logger.at(LogLevel)`. Should be `{@code Logger.at(LogLevel)}`.



##########
api/maven-api-log/pom.xml:
##########
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven</groupId>
+    <artifactId>maven-api</artifactId>
+    <version>4.0.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>maven-api-log</artifactId>
+  <name>Maven 4 API :: Logging</name>
+  <description>Maven 4 API - Unified Logging API (Logger, LogEventBuilder, 
LogLevel).</description>
+
+  <properties>
+    <javaModuleName>org.apache.maven.api.logging</javaModuleName>

Review Comment:
   The module declares 
`<javaModuleName>org.apache.maven.api.logging</javaModuleName>` here, but no 
`module-info.java` is included in the diff. All 11 sibling `maven-api-*` 
modules have one — this module needs one too.



##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLog.java:
##########
@@ -21,225 +21,173 @@
 import java.util.function.Supplier;
 
 import org.apache.maven.api.plugin.Log;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static java.util.Objects.requireNonNull;
 
+/**
+ * Default {@link Log} implementation that delegates to {@link DefaultLogger}.
+ *
+ * @deprecated {@link Log} is deprecated; use {@link 
org.apache.maven.api.logging.Logger} and
+ *             {@link DefaultLogger} instead.
+ */
+@Deprecated(since = "4.0.0", forRemoval = true)
 public class DefaultLog implements Log {
-    private final Logger logger;
+    private final DefaultLogger delegate;
 
-    public DefaultLog(Logger logger) {
-        this.logger = requireNonNull(logger);
+    public DefaultLog(org.slf4j.Logger logger) {
+        this.delegate = new DefaultLogger(logger);
     }
 
     @Override
     public boolean isTraceEnabled() {
-        return logger.isTraceEnabled();
+        return delegate.isTraceEnabled();
     }
 
     @Override
     public void trace(CharSequence content) {
-        if (isTraceEnabled()) {
-            logger.trace(toString(content));
-        }
+        delegate.trace(content != null ? content.toString() : null);

Review Comment:
   Null-safety regression: the old `toString(content)` helper returned `""` for 
null input. Now this passes `null` to `DefaultLogger.trace(@Nonnull String)`, 
violating the `@Nonnull` contract. Change to `content != null ? 
content.toString() : ""`.



##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLogger.java:
##########
@@ -0,0 +1,354 @@
+/*
+ * 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.internal.impl;
+
+import java.util.function.Supplier;
+
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.logging.LogEventBuilder;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.spi.LoggingEventBuilder;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Default {@link Logger} implementation backed by an SLF4J {@link 
org.slf4j.Logger}.
+ */
+public class DefaultLogger implements Logger {
+    private static final LogEventBuilder NOP_BUILDER = new 
NopLogEventBuilder();
+
+    private final org.slf4j.Logger logger;
+
+    public DefaultLogger(org.slf4j.Logger logger) {
+        this.logger = requireNonNull(logger, "logger cannot be null");
+    }
+
+    @Override
+    @Nonnull
+    public String name() {
+        return logger.getName();
+    }
+
+    @Override
+    public boolean isEnabled(@Nonnull LogLevel level) {
+        requireNonNull(level, "level cannot be null");
+        return switch (level) {
+            case TRACE -> logger.isTraceEnabled();
+            case DEBUG -> logger.isDebugEnabled();
+            case INFO -> logger.isInfoEnabled();
+            case WARN -> logger.isWarnEnabled();
+            case ERROR -> logger.isErrorEnabled();
+        };
+    }
+
+    @Override
+    @Nonnull
+    public LogEventBuilder atTrace() {
+        return at(LogLevel.TRACE);
+    }
+
+    @Override
+    @Nonnull
+    public LogEventBuilder atDebug() {
+        return at(LogLevel.DEBUG);
+    }
+
+    @Override
+    @Nonnull
+    public LogEventBuilder atInfo() {
+        return at(LogLevel.INFO);
+    }
+
+    @Override
+    @Nonnull
+    public LogEventBuilder atWarn() {
+        return at(LogLevel.WARN);
+    }
+
+    @Override
+    @Nonnull
+    public LogEventBuilder atError() {
+        return at(LogLevel.ERROR);
+    }
+
+    @Override
+    @Nonnull
+    public LogEventBuilder at(@Nonnull LogLevel level) {
+        if (!isEnabled(level)) {
+            return NOP_BUILDER;
+        }
+        return new DefaultLogEventBuilder(logger, level);
+    }
+
+    @Override
+    @Nonnull
+    public Logger child(@Nonnull String name) {
+        requireNonNull(name, "name cannot be null");
+        if (name.isEmpty()) {
+            throw new IllegalArgumentException("child logger name cannot be 
empty");
+        }
+        String parentName = logger.getName();
+        String childName = parentName.isEmpty() ? name : parentName + "." + 
name;
+        return new DefaultLogger(LoggerFactory.getLogger(childName));
+    }
+
+    private static final class NopLogEventBuilder implements LogEventBuilder {
+        @Override
+        @Nonnull
+        public LogEventBuilder withKeyValue(@Nonnull String key, String value) 
{
+            return this;
+        }
+
+        @Override
+        @Nonnull
+        public LogEventBuilder withKeyValue(@Nonnull String key, long value) {
+            return this;
+        }
+
+        @Override
+        @Nonnull
+        public LogEventBuilder withKeyValue(@Nonnull String key, boolean 
value) {
+            return this;
+        }
+
+        @Override
+        @Nonnull
+        public LogEventBuilder withThrowable(Throwable t) {
+            return this;
+        }
+
+        @Override
+        @Nonnull
+        public LogEventBuilder withProjectId(String projectId) {

Review Comment:
   `withProjectId` and `withMojoId` are silent no-ops here (and in 
`DefaultLogEventBuilder`). The interface Javadoc says "Overrides the 
project/build identifier" with no hint that implementations may discard the 
value. Add a note that enrichment is best-effort / implementation-defined.



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