如何使用Java FX关闭CSS Logging?

时间:2021-10-05 17:03:22

I'm building my first app in Java FX. (java.runtime.version=1.8.0_71-b15) Coding in Eclipse Java EE IDE for Web Developers. Version: Mars.2 Release (4.5.2) Build id: 20160218-0600

我正在使用Java FX构建我的第一个应用程序。 (java.runtime.version = 1.8.0_71-b15)用于Web开发人员的Eclipse Java EE IDE中的编码。版本:Mars.2 Release(4.5.2)Build id:20160218-0600

When I tied in my CSS file, my console started flooding with error messages like these:

当我绑定我的CSS文件时,我的控制台开始充斥着如下错误消息:

Feb 14, 2018 4:13:25 PM javafx.scene.CssStyleHelper calculateValue
WARNING: Could not resolve '-fx-text-base-color' while resolving lookups for '-fx-text-fill' from rule '*.button' in stylesheet jar:file:/Z:/Java/jdk1.8.0_71/jre/lib/ext/jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
Feb 14, 2018 4:13:25 PM javafx.scene.CssStyleHelper calculateValue
WARNING: Could not resolve '-fx-shadow-highlight-color' while resolving lookups for '-fx-background-color' from rule '*.button' in stylesheet jar:file:/Z:/Java/jdk1.8.0_71/jre/lib/ext/jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss

This is known bug, which apparently can't be fixed in Java 8 and hopefully will be fixed in Java 9. In the meantime, the best advice that people online seem to offer is to turn off the CSS logging. Here's that very advice from this site (https://bitbucket.org/controlsfx/controlsfx/issues/373/css-warnings-using-propertysheet-control):

这是已知的错误,显然无法在Java 8中修复,希望将在Java 9中修复。与此同时,人们在线提供的最佳建议是关闭CSS日志记录。以下是本网站的建议(https://bitbucket.org/controlsfx/controlsfx/issues/373/css-warnings-using-propertysheet-control):

I don't know that there is much that can be done - it looks like more of a general purpose JavaFX issue than something ControlsFX related. The visuals do not seem to be impacted, so one option is to simply turn off CSS logging, as such:

我不知道可以做多少事情 - 它看起来像是一个通用的JavaFX问题,而不是与ControlsFX相关的问题。视觉效果似乎没有受到影响,因此一种选择是简单地关闭CSS日志记录,如下所示:

com.sun.javafx.Logging.getCSSLogger().setLevel(Level.OFF);

(The issue was also discussed on SO here: Java error on CSS, and elsewhere here: https://community.oracle.com/thread/2496427?tstart=0 but I'm not having any success zeroing in on an actual solution. The only practical advice I can find is from that first post, essentially saying, "Turn off CSS Logging with this command":

(这里也讨论了这个问题:CSS上的Java错误,以及其他地方:https://community.oracle.com/thread/2496427?tstart = 0但是我没有成功归零实际的解决方案我能找到的唯一实用建议来自第一篇文章,主要是说“用这个命令关闭CSS Logging”:

com.sun.javafx.Logging.getCSSLogger().setLevel(Level.OFF);

I'm fine with turning off the logging, my question is... how do I use this command? The poster who put up this advice just left the command, didn't say where to put it or anything. He (or she) is speaking in a shorthand I am not following.

关闭日志记录我很好,我的问题是......我该如何使用这个命令?提出这个建议的海报刚刚离开了命令,没有说出把它放在哪里或什么的。他(或她)用速记讲话我不跟随。

Does anyone know where to apply this command? In the CSS file? Or in the actual Java code itself? If so, would "com.sun.javafx.Logging" be... the project path? Or is this a setting in Eclipse?

有谁知道在哪里应用这个命令?在CSS文件中?或者在实际的Java代码本身?如果是这样,“com.sun.javafx.Logging”会是......项目路径吗?或者这是Eclipse中的一个设置?

Many thanks, -RAO

非常感谢,-RAO

1 个解决方案

#1


2  

In Java 8u144, the package for the internal JavaFX logging utility is com.sun.javafx.util, not com.sun.javafx, so you would need to call:

在Java 8u144中,内部JavaFX日志记录实用程序的包是com.sun.javafx.util,而不是com.sun.javafx,因此您需要调用:

com.sun.javafx.util.Logging.getCSSLogger()
    .setLevel(sun.util.logging.PlatformLogger.Level.OFF); 

at least for that version.

至少对于那个版本。

In that sample call, I fully qualified the Level class because, otherwise, it could be ambiguous as it differs from the standard java.util.logging.Level.

在该示例调用中,我完全限定了Level类,否则,它可能是不明确的,因为它与标准java.util.logging.Level不同。

For Java 9 this isn't going to work, and you would receive the compiler error:

对于Java 9,这不起作用,您将收到编译器错误:

Error:(20, 23) java: package com.sun.javafx.util is not visible (package com.sun.javafx.util is declared in module javafx.graphics, which does not export it to the unnamed module).

With Java 9, maybe you could define your own LogFinder that handles the platform logging for the "javafx.css" logger (which is the text string of the logger name which you find when you look into the JavaFX source code), by ignoring messages sent to it.

使用Java 9,也许您可​​以定义自己的LogFinder来处理“javafx.css”记录器的平台日志记录(通过忽略消息,当您查看JavaFX源代码时,它是您找到的记录器名称的文本字符串)送到它。

There might be some easier way to do it using a logging.properties file that will work across most Java versions, but I'm not familiar enough with the platform logging system to know if that would work.

使用可以在大多数Java版本中运行的logging.properties文件可能有一些更简单的方法,但我对平台日志记录系统不太熟悉,知道这是否有效。

Yeah, it's all weirdly complicated . . .

是的,这一切都非常复杂。 。 。

#1


2  

In Java 8u144, the package for the internal JavaFX logging utility is com.sun.javafx.util, not com.sun.javafx, so you would need to call:

在Java 8u144中,内部JavaFX日志记录实用程序的包是com.sun.javafx.util,而不是com.sun.javafx,因此您需要调用:

com.sun.javafx.util.Logging.getCSSLogger()
    .setLevel(sun.util.logging.PlatformLogger.Level.OFF); 

at least for that version.

至少对于那个版本。

In that sample call, I fully qualified the Level class because, otherwise, it could be ambiguous as it differs from the standard java.util.logging.Level.

在该示例调用中,我完全限定了Level类,否则,它可能是不明确的,因为它与标准java.util.logging.Level不同。

For Java 9 this isn't going to work, and you would receive the compiler error:

对于Java 9,这不起作用,您将收到编译器错误:

Error:(20, 23) java: package com.sun.javafx.util is not visible (package com.sun.javafx.util is declared in module javafx.graphics, which does not export it to the unnamed module).

With Java 9, maybe you could define your own LogFinder that handles the platform logging for the "javafx.css" logger (which is the text string of the logger name which you find when you look into the JavaFX source code), by ignoring messages sent to it.

使用Java 9,也许您可​​以定义自己的LogFinder来处理“javafx.css”记录器的平台日志记录(通过忽略消息,当您查看JavaFX源代码时,它是您找到的记录器名称的文本字符串)送到它。

There might be some easier way to do it using a logging.properties file that will work across most Java versions, but I'm not familiar enough with the platform logging system to know if that would work.

使用可以在大多数Java版本中运行的logging.properties文件可能有一些更简单的方法,但我对平台日志记录系统不太熟悉,知道这是否有效。

Yeah, it's all weirdly complicated . . .

是的,这一切都非常复杂。 。 。