micronaut-core icon indicating copy to clipboard operation
micronaut-core copied to clipboard

Move from SLF4j to Java 9+ System.Logger and provide binding for logback out of the box

Open graemerocher opened this issue 2 years ago • 7 comments

Feature description

Since Java 9 SLF4J is no longer necessary and we should move logging to System.Logger

Ref https://www.baeldung.com/java-9-logging-api

This eliminates the need for an additional dependency

graemerocher avatar Mar 10 '22 09:03 graemerocher

I don't think this is a good idea. The System.Logger is pretty limited. Also see the JEP:

It is not a goal to define a general-purpose interface for logging. The service interface contains only the minimal set of methods that the JDK needs for its own usage.

Also, since System.Logger does not provide an implementation on its own, we would still need logback, which requires slf4j anyway.

yawkat avatar Mar 10 '22 09:03 yawkat

Yeah it is just here for consideration, it is pretty obvious at runtime slf4j and logback would still be needed, but if that could be made an optional dependency it means less is needed.

The question is do we need any of the features of these libraries in Micronaut Core.

It is clear that certain features (MDC comes to mind) are required for production level applications

graemerocher avatar Mar 10 '22 09:03 graemerocher

We could also make our own logging adapter at that point

yawkat avatar Mar 10 '22 10:03 yawkat

FYI:

Some comments about System.Logger by Stuart Marks on Twitter: https://mobile.twitter.com/stuartmarks/status/1254819581585047552

It's mainly for the JDK itself, but it can also be used by anything that doesn't want to add a dependency for a logging facade.

The primary consumer is the JDK, but it’s public so anyone can use it. It seems useful for libraries that want to minimize dependencies.

That said, if one can live within the limitations of System.Logger, it's public, so it's fine for anyone to use.

rbygrave avatar Apr 14 '22 02:04 rbygrave

Also, since System.Logger does not provide an implementation on its own

Just for reference, that's not quite correct. System.Logger defaults to JUL as a backend. But granted, JUL is very limited in its capabilities.

sschuberth avatar Nov 15 '22 16:11 sschuberth

I wonder which are such cool features in other logging frameworks not available in JUL and used in micronaut... Log4J vulnerability CVE-2021-45046 teaches to keep logging simple

stefanofornari avatar Apr 13 '24 06:04 stefanofornari

@stefanofornari slf4j is a facade that allows users to pick their own logging framework. This is much more difficult with JUL. We do not want to force people to use JUL over other, more capable frameworks like logback.

yawkat avatar Apr 15 '24 05:04 yawkat