diff --git a/.gitignore b/.gitignore index 49b3571..211366b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ out .idea/ freerouting.iml tmp - +/logs/ diff --git a/build.gradle b/build.gradle index d0c8972..0501556 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,9 @@ dependencies { compile group: 'javax.help', name: 'javahelp', version: '2.0.05' // compile files("./lib/eu.mihosoft.freerouting.deps.jh.jar") + + compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.0' + compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.0' } // ext.moduleName = 'eu.mihosoft.freerouting' @@ -172,3 +175,4 @@ task run(type: JavaExec) { // args 'appArg1' // jvmArgs 'arg1' } + diff --git a/launch4j.xml b/launch4j.xml index 24c5a71..4d237df 100644 --- a/launch4j.xml +++ b/launch4j.xml @@ -2,7 +2,7 @@ false eu.mihosoft.freerouting.gui - F:\stuff\freerouting.freerouting\build\FreeRouting.jar + .\build\libs\FreeRouting.jar FreeRouting.exe diff --git a/src/main/java/eu/mihosoft/freerouting/FreeRouting.java b/src/main/java/eu/mihosoft/freerouting/FreeRouting.java new file mode 100644 index 0000000..9fc3f8d --- /dev/null +++ b/src/main/java/eu/mihosoft/freerouting/FreeRouting.java @@ -0,0 +1,4 @@ +package eu.mihosoft.freerouting; + +public class FreeRouting { +} diff --git a/src/main/java/eu/mihosoft/freerouting/autoroute/BatchAutorouter.java b/src/main/java/eu/mihosoft/freerouting/autoroute/BatchAutorouter.java index a726a0c..ad91fd4 100644 --- a/src/main/java/eu/mihosoft/freerouting/autoroute/BatchAutorouter.java +++ b/src/main/java/eu/mihosoft/freerouting/autoroute/BatchAutorouter.java @@ -37,6 +37,7 @@ import eu.mihosoft.freerouting.board.RoutingBoard; import eu.mihosoft.freerouting.interactive.BoardHandling; import eu.mihosoft.freerouting.interactive.InteractiveActionThread; +import eu.mihosoft.freerouting.logger.FRLogger; /** * Handles the sequencing of the batch eu.mihosoft.freerouting.autoroute passes. @@ -126,7 +127,9 @@ public class BatchAutorouter Integer curr_pass_no = hdlg.get_settings().autoroute_settings.get_pass_no(); String start_message = resources.getString("batch_autorouter") + " " + resources.getString("stop_message") + " " + resources.getString("pass") + " " + curr_pass_no.toString() + ": "; hdlg.screen_messages.set_status_message(start_message); + FRLogger.traceEntry("BatchAutorouter.autoroute_pass("+curr_pass_no+")"); still_unrouted_items = autoroute_pass(curr_pass_no, true); + FRLogger.traceExit("BatchAutorouter.autoroute_pass("+curr_pass_no+")"); if (still_unrouted_items && !is_interrupted) { hdlg.get_settings().autoroute_settings.increment_pass_no(); diff --git a/src/main/java/eu/mihosoft/freerouting/board/BasicBoard.java b/src/main/java/eu/mihosoft/freerouting/board/BasicBoard.java index fe1e84f..945ed66 100644 --- a/src/main/java/eu/mihosoft/freerouting/board/BasicBoard.java +++ b/src/main/java/eu/mihosoft/freerouting/board/BasicBoard.java @@ -41,6 +41,7 @@ import eu.mihosoft.freerouting.datastructures.ShapeTree.TreeEntry; import eu.mihosoft.freerouting.library.BoardLibrary; import eu.mihosoft.freerouting.library.Padstack; +import eu.mihosoft.freerouting.logger.FRLogger; import eu.mihosoft.freerouting.rules.BoardRules; import eu.mihosoft.freerouting.boardgraphics.GraphicsContext; import eu.mihosoft.freerouting.boardgraphics.Drawable; @@ -1386,6 +1387,8 @@ public class BasicBoard implements java.io.Serializable */ public void generate_snapshot() { + FRLogger.logger.info("Generating snapshot"); + item_list.generate_snapshot(); components.generate_snapshot(); } diff --git a/src/main/java/eu/mihosoft/freerouting/gui/BoardFrame.java b/src/main/java/eu/mihosoft/freerouting/gui/BoardFrame.java index 3a82d6c..04af7ab 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/BoardFrame.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/BoardFrame.java @@ -308,6 +308,8 @@ public class BoardFrame extends javax.swing.JFrame { return false; } + FRLogger.logger.info("Saving '"+design_file.get_output_file().getName()+"'..."); + java.io.OutputStream output_stream = null; java.io.ObjectOutputStream object_stream = null; try @@ -380,7 +382,7 @@ public class BoardFrame extends javax.swing.JFrame String help_id = "html_files." + p_help_id; javax.help.CSH.setHelpIDString(curr_component, help_id); if (help_broker==null) { - FRLogger.warning("help_broker is null"); + FRLogger.logger.warn("help_broker is null"); return; } help_broker.enableHelpKey(curr_component, help_id, help_set); diff --git a/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuFile.java b/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuFile.java index b182dcc..b737b7f 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuFile.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuFile.java @@ -22,6 +22,8 @@ */ package eu.mihosoft.freerouting.gui; +import eu.mihosoft.freerouting.logger.FRLogger; + /** * Creates the file menu of a eu.mihosoft.freerouting.board frame. * @@ -67,7 +69,6 @@ public class BoardMenuFile extends javax.swing.JMenu save_and_exit_item.setToolTipText(file_menu.resources.getString("save_and_exit_tooltip")); save_and_exit_item.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { if (file_menu.session_file_option) @@ -272,24 +273,25 @@ public class BoardMenuFile extends javax.swing.JMenu { java.io.OutputStream output_stream = null; - java.io.File defaults_file = new java.io.File(board_frame.design_file.get_parent(), BoardFrame.GUI_DEFAULTS_FILE_NAME); - if (defaults_file.exists()) + FRLogger.logger.info("Saving '"+BoardFrame.GUI_DEFAULTS_FILE_NAME+"'..."); + java.io.File defaults_file = new java.io.File(board_frame.design_file.get_parent(), BoardFrame.GUI_DEFAULTS_FILE_NAME); + if (defaults_file.exists()) + { + // Make a backup copy of the old defaulds file. + java.io.File defaults_file_backup = new java.io.File(board_frame.design_file.get_parent(), BoardFrame.GUI_DEFAULTS_FILE_BACKUP_NAME); + if (defaults_file_backup.exists()) { - // Make a backup copy of the old defaulds file. - java.io.File defaults_file_backup = new java.io.File(board_frame.design_file.get_parent(), BoardFrame.GUI_DEFAULTS_FILE_BACKUP_NAME); - if (defaults_file_backup.exists()) - { - defaults_file_backup.delete(); - } - defaults_file.renameTo(defaults_file_backup); - } - try - { - output_stream = new java.io.FileOutputStream(defaults_file); - } catch (Exception e) - { - output_stream = null; + defaults_file_backup.delete(); } + defaults_file.renameTo(defaults_file_backup); + } + try + { + output_stream = new java.io.FileOutputStream(defaults_file); + } catch (Exception e) + { + output_stream = null; + } boolean write_ok; if (output_stream == null) diff --git a/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuHelp.java b/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuHelp.java index 1ac72e5..eb7178d 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuHelp.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/BoardMenuHelp.java @@ -87,7 +87,7 @@ public class BoardMenuHelp extends BoardMenuHelpReduced URL hsURL = getClass().getResource(helpset_name); if (hsURL == null) { - FRLogger.warning("HelpSet " + helpset_name + " not found."); + FRLogger.logger.warn("HelpSet " + helpset_name + " not found."); } else { diff --git a/src/main/java/eu/mihosoft/freerouting/gui/DefaultExceptionHandler.java b/src/main/java/eu/mihosoft/freerouting/gui/DefaultExceptionHandler.java index 98fb617..da69e74 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/DefaultExceptionHandler.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/DefaultExceptionHandler.java @@ -19,7 +19,7 @@ public class DefaultExceptionHandler implements Thread.UncaughtExceptionHandler public static void handleException(Throwable e) { // Here you should have a more robust, permanent record of problems JOptionPane.showMessageDialog(findActiveFrame(), e.toString(), "Exception Occurred", OK_OPTION); - FRLogger.error(e); + FRLogger.logger.error(e); } private static Frame findActiveFrame() { diff --git a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java index 39d2141..12e0ff9 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java @@ -25,6 +25,7 @@ package eu.mihosoft.freerouting.gui; import eu.mihosoft.freerouting.datastructures.FileFilter; import eu.mihosoft.freerouting.designforms.specctra.RulesFile; +import eu.mihosoft.freerouting.logger.FRLogger; /** * File functionality with security restrictions used, when the application is opened with Java Webstart @@ -109,7 +110,7 @@ public class DesignFile result = new java.io.FileInputStream(this.input_file); } catch (Exception e) { - // todo: better error handling... + FRLogger.logger.error(e.getLocalizedMessage(), e); result = null; } @@ -166,6 +167,7 @@ public class DesignFile return; } String new_file_name = new_file.getName(); + FRLogger.logger.info("Saving '"+new_file_name+"'..."); String[] new_name_parts = new_file_name.split("\\."); String found_file_extension = new_name_parts[new_name_parts.length - 1]; if (found_file_extension.compareToIgnoreCase(binary_file_extension) == 0) @@ -214,6 +216,7 @@ public class DesignFile { String output_file_name = design_name + ".ses"; + FRLogger.logger.info("Saving '"+output_file_name+"'..."); java.io.File curr_output_file = new java.io.File(get_parent(), output_file_name); java.io.OutputStream output_stream; try @@ -251,16 +254,17 @@ public class DesignFile String rules_file_name = p_design_name + RULES_FILE_EXTENSION; java.io.OutputStream output_stream; + FRLogger.logger.info("Saving '"+rules_file_name+"'..."); - java.io.File rules_file = new java.io.File(this.get_parent(), rules_file_name); - try - { - output_stream = new java.io.FileOutputStream(rules_file); - } catch (java.io.IOException e) - { - System.out.println("unable to create rules file"); - return false; - } + java.io.File rules_file = new java.io.File(this.get_parent(), rules_file_name); + try + { + output_stream = new java.io.FileOutputStream(rules_file); + } catch (java.io.IOException e) + { + System.out.println("unable to create rules file"); + return false; + } RulesFile.write(p_board_handling, output_stream, p_design_name); return true; @@ -278,6 +282,7 @@ public class DesignFile try { java.io.File rules_file = new java.io.File(p_parent_name, rule_file_name); + FRLogger.logger.info("Opening '"+rule_file_name+"'..."); java.io.InputStream input_stream = new java.io.FileInputStream(rules_file); if (input_stream != null && dsn_file_generated_by_host && WindowMessage.confirm(p_confirm_message)) { @@ -321,6 +326,7 @@ public class DesignFile String[] file_name_parts = design_file_name.split("\\.", 2); String design_name = file_name_parts[0]; String output_file_name = design_name + ".scr"; + FRLogger.logger.info("Saving '"+output_file_name+"'..."); { java.io.File curr_output_file = new java.io.File(get_parent(), output_file_name); diff --git a/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java b/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java index d06b182..2fbfa43 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java @@ -24,8 +24,8 @@ package eu.mihosoft.freerouting.gui; import eu.mihosoft.freerouting.board.TestLevel; -import java.util.logging.Level; -import java.util.logging.Logger; +import eu.mihosoft.freerouting.logger.FRLogger; + import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; @@ -37,26 +37,28 @@ import javax.swing.UnsupportedLookAndFeelException; */ public class MainApplication extends javax.swing.JFrame { - /** * Main function of the Application * @param args */ public static void main(String args[]) { - + FRLogger.traceEntry("MainApplication.main()"); + try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException ex) { - Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex); + FRLogger.logger.error(ex); } catch (InstantiationException ex) { - Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex); + FRLogger.logger.error(ex); } catch (IllegalAccessException ex) { - Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex); + FRLogger.logger.error(ex); } catch (UnsupportedLookAndFeelException ex) { - Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex); + FRLogger.logger.error(ex); } - + + FRLogger.logger.info("Freerouting application is started."); + Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler()); StartupOptions startupOptions = StartupOptions.parse(args); @@ -73,6 +75,8 @@ public class MainApplication extends javax.swing.JFrame { board_option = BoardFrame.Option.SINGLE_FRAME; } + + FRLogger.logger.info("Opening '"+startupOptions.design_file_name+"'..."); DesignFile design_file = DesignFile.get_instance(startupOptions.design_file_name, false); if (design_file == null) { @@ -108,6 +112,8 @@ public class MainApplication extends javax.swing.JFrame { new MainApplication(startupOptions).setVisible(true); } + + FRLogger.traceExit("MainApplication.main()"); } /** @@ -207,13 +213,11 @@ public class MainApplication extends javax.swing.JFrame this.addWindowListener(new WindowStateListener()); pack(); setSize(450,250); - } /** opens a eu.mihosoft.freerouting.board design from a binary file or a specctra dsn file. */ private void open_board_design_action(java.awt.event.ActionEvent evt) { - DesignFile design_file = DesignFile.open_dialog(this.design_dir_name); if (design_file == null) @@ -222,6 +226,8 @@ public class MainApplication extends javax.swing.JFrame return; } + FRLogger.logger.info("Opening '"+design_file.get_name()+"'..."); + BoardFrame.Option option; if (this.is_webstart) { diff --git a/src/main/java/eu/mihosoft/freerouting/interactive/BatchAutorouterThread.java b/src/main/java/eu/mihosoft/freerouting/interactive/BatchAutorouterThread.java index 252525e..2612972 100644 --- a/src/main/java/eu/mihosoft/freerouting/interactive/BatchAutorouterThread.java +++ b/src/main/java/eu/mihosoft/freerouting/interactive/BatchAutorouterThread.java @@ -31,6 +31,7 @@ import eu.mihosoft.freerouting.board.Unit; import eu.mihosoft.freerouting.autoroute.BatchAutorouter; import eu.mihosoft.freerouting.autoroute.BatchFanout; import eu.mihosoft.freerouting.autoroute.BatchOptRoute; +import eu.mihosoft.freerouting.logger.FRLogger; /** * Thread for the batch autorouter. @@ -52,6 +53,8 @@ public class BatchAutorouterThread extends InteractiveActionThread protected void thread_action() { + FRLogger.traceEntry("BatchAutorouterThread.thread_action()"); + try { java.util.ResourceBundle resources = @@ -126,8 +129,10 @@ public class BatchAutorouterThread extends InteractiveActionThread } } catch (Exception e) { - + FRLogger.logger.error(e.getLocalizedMessage(),e); } + + FRLogger.traceExit("BatchAutorouterThread.thread_action()"); } public void draw(java.awt.Graphics p_graphics) diff --git a/src/main/java/eu/mihosoft/freerouting/logger/FRLogger.java b/src/main/java/eu/mihosoft/freerouting/logger/FRLogger.java index 05ec885..f9be437 100644 --- a/src/main/java/eu/mihosoft/freerouting/logger/FRLogger.java +++ b/src/main/java/eu/mihosoft/freerouting/logger/FRLogger.java @@ -1,19 +1,41 @@ package eu.mihosoft.freerouting.logger; -/** - * Andrey Belomutskiy - * 6/28/2014 - */ +import eu.mihosoft.freerouting.FreeRouting; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.ConsoleAppender; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.config.builder.api.*; +import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; + +import java.text.DecimalFormat; +import java.time.Duration; +import java.time.Instant; +import java.util.HashMap; + public class FRLogger { - public static void warning(String message) { - /** - * there is a problem that errors are currently being written to standard console and thus not visible to the - * user - */ - System.out.println(message); + public static Logger logger = LogManager.getLogger(FreeRouting.class); + + private static DecimalFormat performanceFormat = new DecimalFormat("0.00"); + + private static HashMap perfData = new HashMap(); + + public static void traceEntry(String perfId) + { + perfData.put(perfId.hashCode(), java.time.Instant.now()); } - public static void error(Throwable e) { - e.printStackTrace(); + public static void traceExit(String perfId) + { + var timeElapsed = Duration.between(perfData.get(perfId.hashCode()), java.time.Instant.now()).toMillis(); + + perfData.remove(perfId.hashCode()); + if (timeElapsed < 0) { + timeElapsed = 0; + } + logger.trace("Method '" + perfId + "' was performed in " + performanceFormat.format(timeElapsed/1000.0) + " seconds."); } } diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..b9b6b2f --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,26 @@ + + + + logs/freerouter.log + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + \ No newline at end of file