Updated the logging system to the more flexible, robust and performant log4j.
This commit is contained in:
parent
94134800da
commit
715eac8487
|
@ -5,5 +5,5 @@ out
|
|||
.idea/
|
||||
freerouting.iml
|
||||
tmp
|
||||
|
||||
/logs/
|
||||
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<launch4jConfig>
|
||||
<dontWrapJar>false</dontWrapJar>
|
||||
<headerType>eu.mihosoft.freerouting.gui</headerType>
|
||||
<jar>F:\stuff\freerouting.freerouting\build\FreeRouting.jar</jar>
|
||||
<jar>.\build\libs\FreeRouting.jar</jar>
|
||||
<outfile>FreeRouting.exe</outfile>
|
||||
<errTitle></errTitle>
|
||||
<cmdLine></cmdLine>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package eu.mihosoft.freerouting;
|
||||
|
||||
public class FreeRouting {
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Integer, Instant> perfData = new HashMap<Integer, Instant>();
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="filename">logs/freerouter.log</Property>
|
||||
</Properties>
|
||||
<ThresholdFilter level="trace"/>
|
||||
|
||||
<Appenders>
|
||||
<File name="File" fileName="${filename}" bufferSize="1">
|
||||
<PatternLayout>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</pattern>
|
||||
</PatternLayout>
|
||||
</File>
|
||||
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="TRACE">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="File"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
Loading…
Reference in New Issue