英文:
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());
设置out
或err
不起作用。
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("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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论