javaloggingjavafxgtkjava.util.logging

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


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") : 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?


Solution

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

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

    Setting out or err, does not work

    IoBuilder is from:

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