首页 > 解决方案 > Totally disabling java net ssl debug logging

问题描述

I've found tons of documentation on how to enable javax.net.debug for SSL, TLS and similar, but even in the reference documentation I've not found how to totally disable it overriding programmatically a previous setting.

My exact problem is that in a Tomcat instance another application performs the following instruction:

System.setProperty("javax.net.debug","all");

and this causes the catalina.out file to rise his dimension quickly and unwanted.

I've already tried to overwrite it from my Java code with the same instruciton, with "none", "off" and "false" values but with no result, still logging a plenty of TLS stuff.

For example in my application I've added this instruction:

System.setProperty("javax.net.debug","none");

but still I'm getting full log.

标签: javadebuggingssllogging

解决方案


问题是tomcat应用程序正在覆盖你从命令行给出的任何值,如果没有办法控制这段代码在做什么,你就不能真正从命令行参数覆盖它。虽然安全管理器能够阻止设置属性,但它只能通过抛出异常来做到这一点,这可能会导致比它解决的问题更多的问题。

在这种情况下,您唯一的选择是在其他代码设置值之后,自己从代码中设置值。

如果是,则需要在 Debug 类的静态静态初始化程序运行之前javax.net.debug将选项设置为其最终值,也就是在第一条消息出现之前。这可以通过任何不用作某些选项的值来禁用(空字符串,或者不应该禁用它)。如果稍后设置,它将没有任何效果,事后无法将其关闭(除了做一些糟糕的反射黑客来访问该类的内部,这只能在 java 8 和更早版本中使用)sun.*


推荐阅读