<html><body><div dir="ltr">
Hi Piotr,</div><div dir="ltr"><br></div><div dir="ltr">Thank you for so thoroughly evaluating the state of logging in Nashorn. Judging from your OSS involvement, you definitely have the right expertise to know what the good practices are for libraries’ integration with modern logging. I’d welcome contributions that improve the current situation. By “welcome” I mean I can promise to treat them with good-faith intent of acceptance subject to discussion and review, of course :-) Hope your OCA came through!</div><div dir="ltr"><br></div><div dir="ltr">Attila.</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On 27 Oct 2024 at 12:29:55, Piotr P. Karwasz <<a href="mailto:piotr@mailing.copernik.eu">piotr@mailing.copernik.eu</a>> wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" type="cite">
<div>
<div>
Hi all,<br><br>As reported by one of our users[1], there are some issues concerning the <br>compatibility of Nashorn with alternative `java.util.logging` <br>implementations. While we can implement a workaround in Log4j, I believe <br>that a proper solution requires the collaboration of both projects.<br><br>As you are probably aware the standalone `jjs` application provides a <br>`-log` option[2] that allows users to modify the logging configuration <br>of the Nashorn Shell. There are however some issues with this code:<br><br>1. The code is contained in `nashorn-core`, so it will affect all <br>applications, even those that use Nashorn as a library. I strongly <br>believe that application developers should be in full control of the <br>logging configuration, without having libraries modify that <br>configuration behind their back.<br><br>2. The code relies on the usage of the `Logger.setLevel()`, <br>`Logger.addHandler()` and `Logger.setUseParentHandler()` JUL methods. <br>These methods have no equivalents in pure logging APIs such as Log4j API <br>and SLF4J and are no-ops. For users of the JUL-to-Log4j API bridge this <br>means that the `-log` option will be ignored.<br><br>3. The code relies on the usage of the `Logger.getLevel()` method to <br>find the **effective** level of a logger. Similarly to the setter <br>methods, pure logging APIs do not provide a way to find out if a level <br>configuration was explicitly provided by the user or it was inherited <br>from the parent logger. While we can fix the coherence between <br>`setLevel()` and `getLevel()` (see [4]), this looks more like a <br>workaround to me and Nashorn should probably replace `Logger.getLevel()` <br>with `Logger.isLoggable()` (the latter will always provide the effective <br>level).<br><br>4. Nashorn uses a logger wrapper (`DebugLogger`), which makes all the <br>location information in the logs point to the `DebugLogger` class itself.<br><br>I can certainly provide help in solving these issues, but before <br>creating some PRs, I would like to know what the Nashorn team thinks <br>about changes to the logging code and what directions would be <br>acceptable for the team.<br><br>Piotr<br><br>[1] <a href="https://github.com/apache/logging-log4j2/issues/3119">https://github.com/apache/logging-log4j2/issues/3119</a><br><br>[2] <br><a href="https://github.com/openjdk/nashorn/blob/2eb88e4024023ee8e9baacb7736f914e3aa68aa4/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/runtime/options/Options.java#L541">https://github.com/openjdk/nashorn/blob/2eb88e4024023ee8e9baacb7736f914e3aa68aa4/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/runtime/options/Options.java#L541</a><br><br>[3] <br><a href="https://github.com/openjdk/nashorn/blob/main/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/runtime/logging/DebugLogger.java">https://github.com/openjdk/nashorn/blob/main/src/org.openjdk.nashorn/share/classes/org/openjdk/nashorn/internal/runtime/logging/DebugLogger.java</a><br><br>[4] <a href="https://github.com/apache/logging-log4j2/pull/3125">https://github.com/apache/logging-log4j2/pull/3125</a><br><br>
</div>
</div>
</blockquote>
</div></body></html>