如何获取JavaFX中的gtk消息记录器?

huangapple go评论63阅读模式
英文:

How to get logger(s) of gtk messages in javafx?

问题

在JavaFX应用程序启动期间,我遇到了这个错误:

(java:16412): Gtk-WARNING **: 21:08:43.058: 主题解析错误:gtk.css:1649:16:' -gtk-icon-size '不是有效的属性名

我不关心这个错误的原因。我想要将gtk消息的日志代理到log4j2,或者配置gtk消息的级别,就像上面的示例一样(另一个gtk消息的示例),因为目前它直接记录在控制台中。

我不知道哪个日志系统记录了这些消息。我假设是java.util.logging。如果是这样,请问记录gtk消息的记录器的名称是什么,这样我就可以通过从java util记录器中删除控制台处理程序(和其他处理程序),然后添加新的处理程序将消息发送到log4j2记录器,如下所示:

private static final Logger GTK_LOGGER = Logger.getLogger(""); // 在这里查找记录器名称

static {
    for (val h : GTK_LOGGER.getHandlers()) {
        GTK_LOGGER.removeHandler(h);
    }
    GTK_LOGGER.setUseParentHandlers(false);
    val handlerProxy = new Handler() {
         @Override
         public void publish(LogRecord record) {
             final Level level = record.getLevel();
             if (level.equals(Level.INFO)) {
                 log.info(record.getMessage(), record.getThrown());
             } else if (level.equals(Level.WARNING)) {
                 log.warn(record.getMessage(), record.getThrown());
             } else if (level.equals(Level.SEVERE)) {
                 log.error(record.getMessage(), record.getThrown());
             } else {
                 log.debug(record.getMessage(), record.getThrown());
             }
         }
    
         @Override
         public void flush() {
    
         }
    
         @Override
         public void close() throws SecurityException {

         }
    };
    GTK_LOGGER.addHandler(handlerProxy);
}

我尝试设置JavaFX记录器("javafx"):https://stackoverflow.com/questions/53158134/javafx-logging-for-java-1-8-0-192,但这个记录器不会记录gtk消息。

最后,如果它们不是使用java.util.logging记录的,有没有可能使用什么系统记录它们?

英文:

During startup of javafx application I get this error:

(java:16412): Gtk-WARNING **: 21:08:43.058: Theme parsing error: gtk.css:1649:16: '-gtk-icon-size' is not a valid property name

I do not care about cause of this error. I would like to proxy logging of gtk messages to log4j2 or configure level of gtk messages like the one above (another example of gtk message), because right now it is logged right into console.

I do not know what logging system is logging these messages. I am assuming java.util.logging. If so, what is the name of the logger(s) that log gtk messages, so I can proxy it to log4j2 by removing console handler (and other handlers) from java util logger and add new handler that sends messages to log4j2 logger like so:

private static final Logger GTK_LOGGER = Logger.getLogger(""); // searching for logger name here

static {
    for (val h : GTK_LOGGER.getHandlers()) {
        GTK_LOGGER.removeHandler(h);
    }
    GTK_LOGGER.setUseParentHandlers(false);
    val handlerProxy = new Handler() {
         @Override
         public void publish(LogRecord record) {
             final Level level = record.getLevel();
             if (level.equals(Level.INFO)) {
                 log.info(record.getMessage(), record.getThrown());
             } else if (level.equals(Level.WARNING)) {
                 log.warn(record.getMessage(), record.getThrown());
             } else if (level.equals(Level.SEVERE)) {
                 log.error(record.getMessage(), record.getThrown());
             } else {
                 log.debug(record.getMessage(), record.getThrown());
             }
         }
    
         @Override
         public void flush() {
    
         }
    
         @Override
         public void close() throws SecurityException {

         }
    };
    GTK_LOGGER.addHandler(handlerProxy);
}

I tried to set javafx logger ("javafx") :
https://stackoverflow.com/questions/53158134/javafx-logging-for-java-1-8-0-192, but this logger does not log gtk messages.

Using Lombok. Lastly, if they are not logged with java.util.logging, by any chance, what system is it logged with?

答案1

得分: 1

以下是翻译好的部分:

这是由本地代码创建的消息,因此无法更改。

System.setOut(IoBuilder.forLogger(LogManager.getLogger("JAVA SYS OUT")).buildPrintStream());
System.setErr(IoBuilder.forLogger(LogManager.getLogger("JAVA SYS ERR")).buildPrintStream());

设置outerr不起作用。

IoBuilder来自:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-iostreams</artifactId>
    <version>2.20.0</version>
</dependency>
英文:

It is not possible since these messages are created by native code.

System.setOut(IoBuilder.forLogger(LogManager.getLogger(&quot;JAVA SYS OUT&quot;)).buildPrintStream());
System.setErr(IoBuilder.forLogger(LogManager.getLogger(&quot;JAVA SYS ERR&quot;)).buildPrintStream());

Setting out or err, does not work

IoBuilder is from:

&lt;dependency&gt;  
    &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
    &lt;artifactId&gt;log4j-iostreams&lt;/artifactId&gt;
    &lt;version&gt;2.20.0&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2023年5月30日 03:26:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76359908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定