-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log4j writes certain errors to System.out instead of System.err #1484
Comments
The particular warning you are having is most probably due to an incorrect repackaging of Log4j libraries. The Log4j API is a multi-release library, which contains both a version for Java 8 and Java 9+. If you are using Maven Shade plugin use a configuration like in this answer. Regarding you general remark I agree: we shouldn't ever log errors to |
Thank you for that swift reply! With respect to Log4J, my setup includes dependencies <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- Log4j 1.x bridge API -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j.version}</version>
</dependency> and the only log4j libraries I see in use are log4j-1.2-api-2.20.0.jar, log4j-api-2.20.0.jar, and log4j-core-2.20.0.jar. StackLocator can be found in log4j-api-2.20.0.jar. So I guess I cannot really do without it. I will look for some workaround via writing to intermediate local files - so that this is not a blocker for me. |
The "workaround" is to prevent the "WARNING: As I mentioned earlier this is a problem due to the multi-release nature of
|
Thank you. Now I get it. Yes, could be the classloader. |
I wanted to point out that this is particularly problematic if stdout is used for structured communication with an external system. I spent several hours trying to figure out why a change to some logging statements silently breaks a VS Code extension that communicates over stdout using JSON-RPC and this warning turned out to be the cause. EDIT: In my case this was especially hard to discover since the the communication with VS Code over stdout is not logged anywhere, so running the extension in VS Code the communication would just stop working with no relevant errors logged anywhere at all. |
It would be nice if these warnings could be printed to System.err instead so future developers that happen to encounter this issue don't waste time like I did. |
@hblohm, thanks so much for the report, much appreciated! 🙇 Landed a fix replacing |
When using log4j (tried 2.17.0 and 2.20.0) it initializes StackLocator that writes a warning to System.out when not finding sun.reflect.Reflection.getCallerClass - which is true for Java versions >= 9 I believe.
This pretty much invalidates the use of log4j in a java command line that produces binary output that gets stream for further processing. While text output could possibly be suitably filtered, for binary output that is really unusable.
It would be great, if that output could be dropped or at least sent to System.err (like regular log output).
Any workaround would be greatly appreciated!
Thanks,
Henning
The text was updated successfully, but these errors were encountered: