Maven 4 defines a new interface, `org.apache.maven.api.plugin.Log`, with
the usual debug(…), info(…), warn(…) and error(…) methods in it. Should
we replace that by `java.lang.System.Logger`? (now possible with Java
17) The latter is also an interface, so we have the same flexibility for
customization. The only drawback I could see is that codes such as
`logger.info("something")` would become
`logger.log(System.Logger.Level.INFO, "something")`, which is more
tedious to write. However, this inconvenience may actually be a good
thing (see below).
We could keep the Maven `Log` interface as a wrapper around
`System.Logger` for convenience. However, some logging implementations
such as `java.util.logging` use Java reflection for detecting the caller
class and method. If we keep the Maven `Log` as a convenience instead of
direct use of `System.Logger`, I suspect that some logging systems will
think that all logs always come from `org.apache.maven.api.plugin.Log`.
This automatic detection is the reason why I propose a complete replacement.
The current logger is used by Maven like below:
getLog().info("-------------------------------------------------------------");
getLog().error("COMPILATION ERROR : ");
getLog().info("-------------------------------------------------------------");
getLog().info(something);
getLog().info("-------------------------------------------------------------");
For most logging systems, the above is 5 log records, while actually
there is only 1 log record and the rest is formatting. The fact that
System.Logger is more verbose to use may encourage a better pattern like
below, which results in a single log record:
getLog().log(System.Logger.Level.ERROR,
"""
-------------------------------------------------------------
COMPILATION ERROR :
-------------------------------------------------------------
"""
+ something +
"""
-------------------------------------------------------------
""");
The previous code snippet was mixing info(…) and error(…) maybe for
coloration. But I see that Maven 4 has a MessageBuilder interface for
this task, so the log record could be rewritten again like below:
MessageBuilder mb = messageBuilderFactory.builder()
.info("-------------------------------------------------------------").newLine()
.error("COMPILATION ERROR : ").newLine()
.info("-------------------------------------------------------------").newLine()
.info(something).newLine()
.info("-------------------------------------------------------------").newLine();
getLog().log(System.Logger.Level.ERROR, md.build());
Any opinion?
Martin