[Schmitzm-commits] r2323 - in trunk/schmitzm-core/src/main/java/de/schmitzm: lang swing
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Wed Jun 5 14:40:06 CEST 2013
Author: mojays
Date: 2013-06-05 14:40:06 +0200 (Wed, 05 Jun 2013)
New Revision: 2323
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingWorker.java
Log:
LangUtil: initializeDefaultLogger(.) sets log level even if there are appenders
SwingUtil: createChangeLog4JLevelJMenu(.) retrieves parent frame
SwingWorker: log error message in LOGGER
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2013-05-31 22:21:31 UTC (rev 2322)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2013-06-05 12:40:06 UTC (rev 2323)
@@ -2169,8 +2169,8 @@
}
/**
- * Initializes the {@link Logger} (root logger) with a default {@link ConsoleAppender}. This method does nothing
- * when the root logger already contains an appender, so it does not matter when this method is called twice or
+ * Initializes the {@link Logger} (root logger) with a default {@link ConsoleAppender}. This method only resets the
+ * log level when the root logger already contains an appender, so it does not matter when this method is called twice or
* more.
*
* @param logLevel
@@ -2179,17 +2179,17 @@
* pattern for the console output (if {@code null} a default pattern "%r\t%p\t%c\t%m%n" is used)
*/
public static void initializeDefaultLogger(Level logLevel, String logPattern) {
- if (Logger.getRootLogger().getAllAppenders().hasMoreElements())
- return;
+ if (logPattern == null)
+ logPattern = "%d{ISO8601}\t%p\t%c\t%m%n";
+ if (logLevel == null)
+ logLevel = Level.DEBUG;
+ Logger.getRootLogger().setLevel(logLevel);
- if (logPattern == null)
- logPattern = "%d{ISO8601}\t%p\t%c\t%m%n";
- if (logLevel == null)
- logLevel = Level.DEBUG;
- Layout appenderLayout = new PatternLayout(logPattern);
- Appender appender = new ConsoleAppender(appenderLayout, "System.out");
- Logger.getRootLogger().addAppender(appender);
- Logger.getRootLogger().setLevel(logLevel);
+ if (Logger.getRootLogger().getAllAppenders().hasMoreElements())
+ return;
+ Layout appenderLayout = new PatternLayout(logPattern);
+ Appender appender = new ConsoleAppender(appenderLayout, "System.out");
+ Logger.getRootLogger().addAppender(appender);
}
/**
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2013-05-31 22:21:31 UTC (rev 2322)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2013-06-05 12:40:06 UTC (rev 2323)
@@ -2440,12 +2440,22 @@
}
/**
+ * Create a {@link JMenu} that allows to switch the Log-Level of the root
+ * logger.
+ */
+ public static JMenu createChangeLog4JLevelJMenu() {
+ return createChangeLog4JLevelJMenu(null);
+ }
+
+ /**
* Create a {@link JMenu} that allows to switch the Log-Level of the root
* logger.
+ * @param parent parent frame to show error dialog relatively to and to disable
+ * during opening of log file
*/
- public static JMenu createChangeLog4JLevelJMenu() {
+ public static JMenu createChangeLog4JLevelJMenu(final Frame parent) {
- JMenu logMenu = new JMenu(R("Menu.Logging"));
+ final JMenu logMenu = new JMenu(R("Menu.Logging"));
final Logger rootLogger = Logger.getRootLogger();
@@ -2472,11 +2482,15 @@
@Override
public void actionPerformed(ActionEvent e) {
try {
+ SwingUtil.setWaitCursor(parent);
Desktop.getDesktop().browse(
IOUtil.fileToURL(logFile)
.toURI());
+ SwingUtil.resetCursor(parent);
} catch (Exception e1) {
- ExceptionDialog.show(e1);
+ ExceptionDialog.show(parent,e1);
+ } finally {
+ SwingUtil.resetCursor(parent);
}
}
});
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingWorker.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingWorker.java 2013-05-31 22:21:31 UTC (rev 2322)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingWorker.java 2013-06-05 12:40:06 UTC (rev 2323)
@@ -34,6 +34,9 @@
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
+import org.apache.log4j.Logger;
+
+import de.schmitzm.lang.LangUtil;
import de.schmitzm.lang.WorkingThread;
/**
@@ -49,6 +52,8 @@
* @version 1.0
*/
public class SwingWorker extends WorkingThread {
+ protected static Logger LOGGER = LangUtil.createLogger(SwingWorker.class);
+
/** Speichert den Arbeitsablauf fuer den Thread. */
protected Work work = null;
/** Speichert den Dialog, der waehrend der Arbeit des SwingWorkers angezeigt wird. */
@@ -274,6 +279,7 @@
if ( err instanceof InterruptedException ||
err instanceof ThreadDeath )
return;
+ LangUtil.logDebugError(LOGGER, err);
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
More information about the Schmitzm-commits
mailing list