gnodet-bot commented on code in PR #13695:
URL: https://github.com/apache/maven/pull/13695#discussion_r4365730857
##########
impl/maven-testing/src/main/java/org/apache/maven/testing/plugin/MojoExtension.java:
##########
@@ -528,8 +526,9 @@ private MojoExecution createMojoExecution() {
@Provides
@Singleton
@Priority(-10)
- private Log createLog() {
- return new DefaultLog(LoggerFactory.getLogger("anonymous"));
+ private Logger createLogger() {
Review Comment:
🟠**`LoggerManager.get()` can return `null` — missing null guard.**
`Holder.instance` is `null` until `DefaultLoggerManager` is constructed. If
`createLogger()` is invoked by the DI container before any
`DefaultLoggerManager` is initialized (e.g. in a unit test that doesn't
bootstrap the full logging stack), `mgr.getLogger("anonymous")` will throw a
`NullPointerException`. Add a null guard:
```suggestion
LoggerManager mgr = LoggerManager.get();
if (mgr == null) {
throw new IllegalStateException("LoggerManager not
initialized — DefaultLoggerManager must be constructed before MojoExtension");
}
```
##########
api/maven-api-log/src/main/java/org/apache/maven/api/logging/LoggerManager.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.api.logging;
+
+import org.apache.maven.api.annotations.Experimental;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.annotations.Nullable;
+
+/**
+ * Central entry point for Maven's logging system.
+ * <p>
+ * Provides access to loggers, the active {@link LogSink}, level configuration,
+ * and severity tracking for {@code --fail-on-severity}. A single instance is
+ * registered at startup via {@link #set(LoggerManager)} and accessed
statically
+ * via {@link #get()}.
+ *
+ * @since 4.1.0
+ */
+@Experimental
+public interface LoggerManager {
+
+ /**
+ * Returns a {@link Logger} instance for the given name.
+ */
+ @Nonnull
+ Logger getLogger(@Nonnull String name);
+
+ /**
+ * Returns a {@link Logger} instance for the given class.
+ */
+ @Nonnull
+ default Logger getLogger(@Nonnull Class<?> clazz) {
+ return getLogger(clazz.getName());
+ }
+
+ /**
+ * Returns the active log sink, or {@code null} if none is installed.
+ */
+ @Nullable
+ LogSink getLogSink();
+
+ /**
+ * Installs or removes the active log sink.
+ */
+ void setLogSink(@Nullable LogSink sink);
+
+ /**
+ * Returns whether logging at {@code level} is enabled for the named
logger.
+ */
+ boolean isLevelEnabled(@Nonnull String loggerName, @Nonnull LogLevel
level);
+
+ /**
+ * Sets the root logger level (typically from {@code -X}, {@code -q} CLI
flags).
+ * Takes effect after {@link #reconfigure()}.
+ */
+ void setRootLoggerLevel(@Nonnull LogLevel level);
Review Comment:
🟠**Stale Javadoc: `setRootLoggerLevel()` no longer requires a separate
`reconfigure()` call.**
The `DefaultLoggerManager` implementation now calls `reconfigure()` inside
`setRootLoggerLevel()`, making the documented contract obsolete. The interface
Javadoc still says "Takes effect after `reconfigure()`" — callers who read only
the API doc will call `reconfigure()` unnecessarily (harmless but misleading).
```suggestion
* Sets the root logger level (typically from {@code -X}, {@code -q} CLI
flags).
* The new level takes effect immediately.
```
--
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]