5

I am using JavaFx with native packaging. What is the best way to log the System console output to file? Is it possible to use sl4j-simple? Could you please give example?

Freelander
  • 129
  • 1
  • 2
  • 6

1 Answers1

3

The simplest way is probably to use the java.util.logging framework and route it's output to a file by following: How to get java Logger output to file by default. Then you don't need to bother with packaging any extra dependencies for logging frameworks. If you do this, you have to use the java.util.logging api, which is slightly awkward compared to slf4j, but it's still workable.

You could certainly use slf4j as your interface instead, but you will need to package extra jar files with your application to accomplish that. If you know maven, then perhaps the easiest way package the libraries would be to build your project using the javafx maven plugin with appropriate dependencies placed in your project pom for the slf4j logging libraries you would like to use.

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Thanks for reply. I added slf4j-log4j depemdency but have a strange result. All output is in the log file, including DEBUG. But exceptions are not included into log file. – Freelander Feb 05 '13 at 09:47
  • 1
    Here is my lof4j.properties log4j.rootLogger=DEBUG, file # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=logs/log.log log4j.appender.file.MaxFileSize=1MB log4j.appender.file.MaxBackupIndex=1 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n – Freelander Feb 05 '13 at 09:48
  • Here is log output from Idea...2013-02-05 20:42:02 DEBUG JdbcTemplate:635 - Executing prepared SQL query 2013-02-05 20:42:02 DEBUG JdbcTemplate:570 - Executing prepared SQL statement [SELECT phoneme FROM word WHERE VALUE = ? AND phoneme IS NOT NULL] 2013-02-05 20:42:02 DEBUG DataSourceUtils:110 - Fetching JDBC Connection from DataSource java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1440) – Freelander Feb 05 '13 at 09:49