0

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?

Wortig
  • 963
  • 2
  • 11
  • 37
  • 1
    It is probably gtk or JavaFX native code, not Java which is logging this error (my opinion). – jewelsea May 29 '23 at 19:40
  • JavaFX typically uses `System.err` directly for low-level logging. In other contexts, I believe it uses its own logger class that wraps a [`java.lang.System.Logger`](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/System.Logger.html) (at least in the more recent versions). But that's assuming this warning/error was printed by Java code and not native code. – Slaw May 29 '23 at 19:40
  • @jewelsea Probably these messages are produced only on Linux distros, which use gtk. If it is native code, there is no chance by sending these messages to my log4j2, right? – Wortig May 29 '23 at 19:45
  • 1
    I don’t know why you want to do that. You can redirect system out and err streams elsewhere if you need to. Either in the shell command that runs your app or [in java](https://stackoverflow.com/questions/3228427/redirect-system-out-println) (though the java redirect may not work for messages written by native code). – jewelsea May 29 '23 at 20:20
  • @jewelsea Because i want to log these messages to my log4j2 file as i am elsewhere doing in my code. Its cool that is is possible. However i am afraid its native. – Wortig May 30 '23 at 17:28

1 Answers1

1

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>
Wortig
  • 963
  • 2
  • 11
  • 37