diff --git a/build.gradle b/build.gradle index 0d350b7cd7d..7dfd99f8993 100644 --- a/build.gradle +++ b/build.gradle @@ -121,16 +121,18 @@ dependencies { compile 'de.jensd:fontawesomefx-materialdesignfont:1.7.22-4' compile 'org.fxmisc.richtext:richtextfx:0.7-M5' - + // Logging compile 'commons-logging:commons-logging:1.2' + compile 'org.apache.logging.log4j:log4j-jcl:2.8.2' + compile 'org.apache.logging.log4j:log4j-api:2.8.2' + compile 'org.apache.logging.log4j:log4j-core:2.8.2' + compile 'com.jcabi:jcabi-log:0.17.2' + compile 'org.slf4j:slf4j-jcl:1.7.25' // required by jcabi-log to enable logging over jcl compile 'org.jsoup:jsoup:1.10.3' compile 'com.mashape.unirest:unirest-java:1.4.9' compile 'info.debatty:java-string-similarity:0.24' - compile 'org.apache.logging.log4j:log4j-jcl:2.8.2' - compile 'org.apache.logging.log4j:log4j-api:2.8.2' - compile 'org.apache.logging.log4j:log4j-core:2.8.2' compile 'org.xmlunit:xmlunit-core:2.3.0' compile 'org.xmlunit:xmlunit-matchers:2.3.0' diff --git a/docs/adr/0000-use-architectural-decision-records.md b/docs/adr/0000-use-architectural-decision-records.md new file mode 100644 index 00000000000..edfe41f4e43 --- /dev/null +++ b/docs/adr/0000-use-architectural-decision-records.md @@ -0,0 +1,16 @@ +# Use Architectural Decision Records + +We need to record the architectural decisions made on this project. + +## Considered Alternatives + +* No record +* [DecisionRecord](https://github.com/schubmat/DecisionCapture) +* [Michael Nygard's template](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions), maintainable by [adr-tools](https://github.com/npryce/adr-tools) +* [Sustainable Architectural Decisions](https://www.infoq.com/articles/sustainable-architectural-design-decisions) +* [Other templates](https://github.com/joelparkerhenderson/architecture_decision_record) + +## Conclusion + +* *Chosen Alternative: Decision Record* +* That template is lean and fits most the development style diff --git a/docs/adr/0001-use-jcabi-log.md b/docs/adr/0001-use-jcabi-log.md new file mode 100644 index 00000000000..a0ddf4f0bf1 --- /dev/null +++ b/docs/adr/0001-use-jcabi-log.md @@ -0,0 +1,15 @@ +# Use jcabi-log + +We need to reduce startup time of JabRef (https://github.com/JabRef/jabref/issues/2966). +One time consuming aspect is the logging + +## Considered Alternatives + +* [jcabi-log](http://log.jcabi.com/) +* [TinyLog](http://www.tinylog.org/) + +## Conclusion + +* Chosen Alternative: jcabi-log (see https://github.com/JabRef/jabref/pull/3015) +* org.jabref.gui.logging.GuiAppender strongly relies on Apache Log4j2. + TinyLog does not support mirroring log outputs and thus we cannot easily switch to TinyLog. diff --git a/docs/adr/index.md b/docs/adr/index.md new file mode 100644 index 00000000000..bbcf2bf620c --- /dev/null +++ b/docs/adr/index.md @@ -0,0 +1,7 @@ +# Architectural Decision Records + +This lists the architectural decisions for JabRef. + +- [0000-use-architectural-decision-records.md](0000-use-architectural-decision-records) - Use Architectural Decision Records +- [0001-use-jcabi-log.md](0000-use-jcabi-log) - Use [jcabi-log](http://log.jcabi.com/) +- [template.md](template/) - the template diff --git a/docs/adr/template.md b/docs/adr/template.md new file mode 100644 index 00000000000..e473bf5e5c9 --- /dev/null +++ b/docs/adr/template.md @@ -0,0 +1,36 @@ +# + +**UserStory:** + + + +## Considered Alternatives + +* +* +* + +## Conclusion + +* *Chosen Alternative: * +* + +## Comparison (Optional) + +### + +* + +* + +* - + +### + +* + +* + +* - + +### + +* + +* + +* - diff --git a/src/main/java/org/jabref/JabRefException.java b/src/main/java/org/jabref/JabRefException.java index 42eacc77c72..b3c61587dad 100644 --- a/src/main/java/org/jabref/JabRefException.java +++ b/src/main/java/org/jabref/JabRefException.java @@ -1,11 +1,7 @@ package org.jabref; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - public class JabRefException extends Exception { - private static final Log LOGGER = LogFactory.getLog(JabRefException.class); private String localizedMessage; public JabRefException(String message) { @@ -33,7 +29,7 @@ public JabRefException(Throwable cause) { @Override public String getLocalizedMessage() { if (localizedMessage == null) { - LOGGER.debug("No localized message exception message defined. Falling back to getMessage()."); + Logger.debug(this, "No localized message exception message defined. Falling back to getMessage()."); return getMessage(); } else { return localizedMessage; diff --git a/src/main/java/org/jabref/JabRefExecutorService.java b/src/main/java/org/jabref/JabRefExecutorService.java index 3c587eaebe5..44e888183ba 100644 --- a/src/main/java/org/jabref/JabRefExecutorService.java +++ b/src/main/java/org/jabref/JabRefExecutorService.java @@ -9,17 +9,12 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - - /** * Responsible for managing of all threads (except Swing threads) in JabRef */ public class JabRefExecutorService implements Executor { public static final JabRefExecutorService INSTANCE = new JabRefExecutorService(); - private static final Log LOGGER = LogFactory.getLog(JabRefExecutorService.class); private final ExecutorService executorService = Executors.newCachedThreadPool(r -> { Thread thread = new Thread(r); thread.setName("JabRef CachedThreadPool"); @@ -41,7 +36,7 @@ private JabRefExecutorService() { } @Override public void execute(Runnable command) { if (command == null) { - LOGGER.debug("Received null as command for execution"); + Logger.debug(this, "Received null as command for execution"); return; } @@ -50,7 +45,7 @@ public void execute(Runnable command) { public void executeAndWait(Runnable command) { if (command == null) { - LOGGER.debug("Received null as command for execution"); + Logger.debug(this, "Received null as command for execution"); return; } @@ -62,14 +57,14 @@ public void executeAndWait(Runnable command) { } catch (InterruptedException ignored) { // Ignored } catch (ExecutionException e) { - LOGGER.error("Problem executing command", e); + Logger.error(this, "Problem executing command", e); } } } public boolean executeAndWait(Callable command) { if (command == null) { - LOGGER.debug("Received null as command for execution"); + Logger.debug(this, "Received null as command for execution"); return false; } @@ -81,7 +76,7 @@ public boolean executeAndWait(Callable command) { } catch (InterruptedException ignored) { // Ignored } catch (ExecutionException e) { - LOGGER.error("Problem executing command", e); + Logger.error(this, "Problem executing command", e); return false; } } @@ -97,7 +92,7 @@ public void executeInterruptableTask(final Runnable runnable, String taskName) { public void executeInterruptableTaskAndWait(Runnable runnable) { if (runnable == null) { - LOGGER.debug("Received null as command for execution"); + Logger.debug(this, "Received null as command for execution"); return; } @@ -109,7 +104,7 @@ public void executeInterruptableTaskAndWait(Runnable runnable) { } catch (InterruptedException ignored) { // Ignored } catch (ExecutionException e) { - LOGGER.error("Problem executing command", e); + Logger.error(this, "Problem executing command", e); } } } diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index b5674c29c64..adee964f3a7 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -37,11 +37,8 @@ import com.jgoodies.looks.plastic.Plastic3DLookAndFeel; import com.jgoodies.looks.plastic.theme.SkyBluer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class JabRefGUI { - private static final Log LOGGER = LogFactory.getLog(JabRefGUI.class); private static JabRefFrame mainFrame; @@ -96,7 +93,7 @@ private void openWindow() { GUIGlobals.init(); - LOGGER.debug("Initializing frame"); + Logger.debug(this, "Initializing frame"); JabRefGUI.mainFrame = new JabRefFrame(); // Add all bibDatabases databases to the frame: @@ -120,7 +117,7 @@ private void openWindow() { pr.getDatabaseContext().clearDatabaseFile(); // do not open the original file pr.getDatabase().clearSharedDatabaseID(); - LOGGER.error("Connection error", e); + Logger.error(this, "Connection error", e); JOptionPane.showMessageDialog(mainFrame, e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."), Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE); @@ -182,7 +179,7 @@ private void openWindow() { OpenDatabaseAction.performPostOpenActions(panel, pr); } - LOGGER.debug("Finished adding panels"); + Logger.debug(this, "Finished adding panels"); if (!bibDatabases.isEmpty()) { JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus(); @@ -211,7 +208,7 @@ private void openLastEditedDatabases() { Globals.prefs.getImportFormatPreferences()); if (parsedDatabase.isEmpty()) { - LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'"); + Logger.error(this, Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'"); } else { bibDatabases.add(parsedDatabase); } @@ -238,7 +235,7 @@ private void setLookAndFeel() { if (System.getProperty("java.runtime.name").contains("OpenJDK")) { // Metal L&F lookFeel = UIManager.getCrossPlatformLookAndFeelClassName(); - LOGGER.warn( + Logger.warn(this, "There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution."); } else { lookFeel = systemLookFeel; @@ -269,11 +266,11 @@ private void setLookAndFeel() { Localization .lang("Unable to find the requested look and feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE); - LOGGER.warn("Unable to find requested look and feel", e); + Logger.warn(this, "Unable to find requested look and feel", e); } } } catch (Exception e) { - LOGGER.warn("Look and feel could not be set", e); + Logger.warn(this, "Look and feel could not be set", e); } // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms diff --git a/src/main/java/org/jabref/Logger.java b/src/main/java/org/jabref/Logger.java new file mode 100644 index 00000000000..a474a433f07 --- /dev/null +++ b/src/main/java/org/jabref/Logger.java @@ -0,0 +1,141 @@ +package org.jabref; + +import com.google.common.collect.ObjectArrays; + +/** + * Separate class for logging. + * + * We use jcabi-log (see ADR-0001) + * + * We need to add a wrapper around it as developers won't write Logger.debug(this, "msg: %[exception]s", e) for every logged exception + */ +public class Logger { + + /** begin: direct pass-through **/ + + public static void trace(final Object source, final String msg) { + com.jcabi.log.Logger.trace(source, msg); + } + + public static void trace( + final Object source, + final String msg, final Object... args + ) { + com.jcabi.log.Logger.trace(source, msg, args); + } + + public static void debug(final Object source, final String msg) { + com.jcabi.log.Logger.debug(source, msg); + } + + public static void debug( + final Object source, + final String msg, final Object... args + ) { + com.jcabi.log.Logger.debug(source, msg, args); + } + + public static void info(final Object source, final String msg) { + com.jcabi.log.Logger.info(source, msg); + } + + public static void info( + final Object source, + final String msg, final Object... args + ) { + com.jcabi.log.Logger.info(source, msg, args); + } + + public static void warn(final Object source, final String msg) { + com.jcabi.log.Logger.warn(source, msg); + } + + public static void warn( + final Object source, + final String msg, final Object... args + ) { + com.jcabi.log.Logger.warn(source, msg, args); + } + + public static void error(final Object source, final String msg) { + com.jcabi.log.Logger.error(source, msg); + } + + public static void error(final Object source, + final String msg, final Object... args) { + com.jcabi.log.Logger.error(source, msg, args); + } + + /** end of direct pass through **/ + + public static void trace(final Object source, final String msg, Throwable e) { + com.jcabi.log.Logger.trace(source, msg); + } + + public static void trace( + final Object source, + final String msg, final Throwable e, final Object... args + ) { + if (com.jcabi.log.Logger.isTraceEnabled(source)) { + com.jcabi.log.Logger.trace(source, msg + ": %[exception]s", ObjectArrays.concat(args, e)); + } + } + + public static void debug(final Object source, final Throwable e, final String msg) { + com.jcabi.log.Logger.debug(source, msg); + } + + public static void debug( + final Object source, + final String msg, final Throwable e, final Object... args + ) { + if (com.jcabi.log.Logger.isDebugEnabled(source)) { + com.jcabi.log.Logger.debug(source, msg + ": %[exception]s", ObjectArrays.concat(args, e)); + } + } + + public static void info(final Object source, final Throwable e, final String msg) { + com.jcabi.log.Logger.info(source, msg); + } + + public static void info(final Object source, final Throwable e) { + com.jcabi.log.Logger.info(source, "%[exception]s", e); + } + + public static void info( + final Object source, + final String msg, final Throwable e, final Object... args + ) { + if (com.jcabi.log.Logger.isInfoEnabled(source)) { + com.jcabi.log.Logger.info(source, msg + ": %[exception]s", ObjectArrays.concat(args, e)); + } + } + + public static void warn(final Object source, final Throwable e, final String msg) { + com.jcabi.log.Logger.warn(source, msg); + } + + public static void warn(final Object source, final Throwable e) { + com.jcabi.log.Logger.warn(source, "%[exception]s", e); + } + + public static void warn( + final Object source, + final String msg, final Throwable e, final Object... args + ) { + if (com.jcabi.log.Logger.isWarnEnabled(source)) { + com.jcabi.log.Logger.warn(source, msg + ": %[exception]s", ObjectArrays.concat(args, e)); + } + } + + public static void error(final Object source, final Throwable e, final String msg) { + com.jcabi.log.Logger.error(source, msg); + } + + public static void error(final Object source, + final String msg, final Throwable e, final Object... args) { + // error is always logged. Therefore, no isErrorEnabled(Object) exists + com.jcabi.log.Logger.error(source, msg + ": %[exception]s", ObjectArrays.concat(args, e)); + } + +} diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 8ddcb93dd52..75504a44a3b 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -15,6 +15,7 @@ import org.jabref.Globals; import org.jabref.JabRefException; +import org.jabref.Logger; import org.jabref.gui.externalfiles.AutoSetLinks; import org.jabref.gui.importer.fetcher.EntryFetcher; import org.jabref.gui.importer.fetcher.EntryFetchers; @@ -52,12 +53,9 @@ import org.jabref.shared.prefs.SharedDatabasePreferences; import com.google.common.base.Throwables; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class ArgumentProcessor { - private static final Log LOGGER = LogFactory.getLog(ArgumentProcessor.class); private final JabRefCLI cli; private final List parserResults; private final Mode startupMode; @@ -210,13 +208,13 @@ private List processArguments() { } } - LOGGER.debug("Finished export"); + Logger.debug(this, "Finished export"); if (cli.isPreferencesExport()) { try { Globals.prefs.exportPreferences(cli.getPreferencesExport()); } catch (JabRefException ex) { - LOGGER.error("Cannot export preferences", ex); + Logger.error(this, "Cannot export preferences", ex); } } @@ -470,7 +468,7 @@ private void importPreferences() { SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs); ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences); } catch (JabRefException ex) { - LOGGER.error("Cannot import preferences", ex); + Logger.error(this, "Cannot import preferences", ex); } } @@ -482,7 +480,7 @@ private void resetPreferences(String value) { new SharedDatabasePreferences().clear(); } catch (BackingStoreException e) { System.err.println(Localization.lang("Unable to clear preferences.")); - LOGGER.error("Unable to clear preferences", e); + Logger.error(this, "Unable to clear preferences", e); } } else { String[] keys = value.split(","); @@ -500,7 +498,7 @@ private void resetPreferences(String value) { private void automaticallySetFileLinks(List loaded) { for (ParserResult parserResult : loaded) { BibDatabase database = parserResult.getDatabase(); - LOGGER.info(Localization.lang("Automatically setting file links")); + Logger.info(this, Localization.lang("Automatically setting file links")); AutoSetLinks.autoSetLinks(database.getEntries(), parserResult.getDatabaseContext()); } } @@ -511,7 +509,7 @@ private void regenerateBibtexKeys(List loaded) { MetaData metaData = parserResult.getMetaData(); if (metaData != null) { - LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata")); + Logger.info(this, Localization.lang("Regenerating BibTeX keys according to metadata")); for (BibEntry entry : database.getEntries()) { // try to make a new label BibtexKeyPatternUtil.makeAndSetLabel( @@ -519,7 +517,7 @@ private void regenerateBibtexKeys(List loaded) { database, entry, Globals.prefs.getBibtexKeyPatternPreferences()); } } else { - LOGGER.info(Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys")); + Logger.info(this, Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys")); } } } diff --git a/src/main/java/org/jabref/cli/JabRefCLI.java b/src/main/java/org/jabref/cli/JabRefCLI.java index 0aa5be8d7a0..fc9237510da 100644 --- a/src/main/java/org/jabref/cli/JabRefCLI.java +++ b/src/main/java/org/jabref/cli/JabRefCLI.java @@ -4,6 +4,7 @@ import java.util.List; import org.jabref.Globals; +import org.jabref.Logger; import org.jabref.logic.exporter.ExportFormats; import org.jabref.logic.l10n.Localization; @@ -13,12 +14,9 @@ import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class JabRefCLI { - private static final Log LOGGER = LogFactory.getLog(JabRefCLI.class); private List leftOver; private final CommandLine cl; @@ -32,7 +30,7 @@ public JabRefCLI(String[] args) { this.cl = new DefaultParser().parse(options, args); this.leftOver = Arrays.asList(cl.getArgs()); } catch (ParseException e) { - LOGGER.warn("Problem parsing arguments", e); + Logger.warn(this, "Problem parsing arguments", e); this.printUsage(); throw new RuntimeException(); diff --git a/src/main/java/org/jabref/collab/ChangeScanner.java b/src/main/java/org/jabref/collab/ChangeScanner.java index c413b583d67..3f4e7e3019e 100644 --- a/src/main/java/org/jabref/collab/ChangeScanner.java +++ b/src/main/java/org/jabref/collab/ChangeScanner.java @@ -15,6 +15,7 @@ import org.jabref.Globals; import org.jabref.JabRefExecutorService; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; import org.jabref.logic.bibtex.DuplicateCheck; @@ -39,11 +40,7 @@ import org.jabref.model.groups.GroupTreeNode; import org.jabref.model.metadata.MetaData; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - public class ChangeScanner implements Runnable { - private static final Log LOGGER = LogFactory.getLog(ChangeScanner.class); private static final String[] SORT_BY = new String[] {FieldName.YEAR, FieldName.AUTHOR, FieldName.TITLE}; @@ -115,7 +112,7 @@ public void run() { scanGroups(metadataInTemp, metadataOnDisk); } catch (IOException ex) { - LOGGER.warn("Problem running", ex); + Logger.warn(this, "Problem running", ex); } } @@ -155,7 +152,7 @@ private void storeTempDatabase() { SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(databaseInTemp, metadataInTemp, defaults), prefs); ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle())); } catch (SaveException ex) { - LOGGER.warn("Problem updating tmp file after accepting external changes", ex); + Logger.warn(this, "Problem updating tmp file after accepting external changes", ex); } }); } diff --git a/src/main/java/org/jabref/collab/EntryChange.java b/src/main/java/org/jabref/collab/EntryChange.java index 7efd5b41126..9e5ae88c9dc 100644 --- a/src/main/java/org/jabref/collab/EntryChange.java +++ b/src/main/java/org/jabref/collab/EntryChange.java @@ -10,6 +10,7 @@ import javax.swing.JLabel; import javax.swing.JScrollPane; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableFieldChange; @@ -18,12 +19,8 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - class EntryChange extends Change { - private static final Log LOGGER = LogFactory.getLog(EntryChange.class); public EntryChange(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskEntry) { super(); @@ -42,7 +39,7 @@ public EntryChange(BibEntry memEntry, BibEntry tmpEntry, BibEntry diskEntry) { // in the same way. Check for this, too. boolean modificationsAgree = (DuplicateCheck.compareEntriesStrictly(memEntry, diskEntry) > 1); - LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + Logger.debug(this, "Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + "\n Modified locally: " + isModifiedLocally + " Modifications agree: " + modificationsAgree); Set allFields = new TreeSet<>(); diff --git a/src/main/java/org/jabref/collab/EntryDeleteChange.java b/src/main/java/org/jabref/collab/EntryDeleteChange.java index 758363e113f..18fa77e53d0 100644 --- a/src/main/java/org/jabref/collab/EntryDeleteChange.java +++ b/src/main/java/org/jabref/collab/EntryDeleteChange.java @@ -3,6 +3,7 @@ import javax.swing.JComponent; import javax.swing.JScrollPane; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.PreviewPanel; import org.jabref.gui.undo.NamedCompound; @@ -12,12 +13,8 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - class EntryDeleteChange extends Change { - private static final Log LOGGER = LogFactory.getLog(EntryDeleteChange.class); private final BibEntry memEntry; private final BibEntry tmpEntry; @@ -36,7 +33,7 @@ public EntryDeleteChange(BibEntry memEntry, BibEntry tmpEntry) { // Check if it has been modified locally, since last tempfile was saved. boolean isModifiedLocally = (matchWithTmp <= 1); - LOGGER.debug("Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + Logger.debug(this, "Modified entry: " + memEntry.getCiteKeyOptional().orElse("") + "\n Modified locally: " + isModifiedLocally); PreviewPanel pp = new PreviewPanel(null, memEntry, null); diff --git a/src/main/java/org/jabref/collab/FileUpdateMonitor.java b/src/main/java/org/jabref/collab/FileUpdateMonitor.java index 9d009f19848..061b870ec3a 100644 --- a/src/main/java/org/jabref/collab/FileUpdateMonitor.java +++ b/src/main/java/org/jabref/collab/FileUpdateMonitor.java @@ -7,9 +7,9 @@ import java.util.HashMap; import java.util.Map; +import org.jabref.Logger; import org.jabref.logic.util.io.FileUtil; -import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** @@ -17,7 +17,6 @@ * in the file's last modification time stamp. The */ public class FileUpdateMonitor implements Runnable { - private static final Log LOGGER = LogFactory.getLog(FileUpdateMonitor.class); private static final int WAIT = 4000; private final Map entries = new HashMap<>(); @@ -29,7 +28,7 @@ private static synchronized Path getTempFile() { temporaryFile = Files.createTempFile("jabref", null); temporaryFile.toFile().deleteOnExit(); } catch (IOException ex) { - LOGGER.warn("Could not create temporary file.", ex); + LogFactory.getLog(FileUpdateMonitor.class).warn("Could not create temporary file.", ex); } return temporaryFile; } @@ -52,7 +51,7 @@ public void run() { try { Thread.sleep(WAIT); } catch (InterruptedException ex) { - LOGGER.debug("FileUpdateMonitor has been interrupted. Terminating...", ex); + Logger.debug(this, "FileUpdateMonitor has been interrupted. Terminating...", ex); return; } } @@ -119,7 +118,7 @@ public void updateTimeStamp(String key) { try { entry.updateTimeStamp(); } catch (IOException e) { - LOGGER.error("Couldn't update timestamp", e); + Logger.error(this, "Couldn't update timestamp", e); } } } diff --git a/src/main/java/org/jabref/collab/PreambleChange.java b/src/main/java/org/jabref/collab/PreambleChange.java index 3245ed24d74..a240081d161 100644 --- a/src/main/java/org/jabref/collab/PreambleChange.java +++ b/src/main/java/org/jabref/collab/PreambleChange.java @@ -26,13 +26,13 @@ public PreambleChange(String mem, String disk) { text.append("

").append(Localization.lang("Changed preamble")).append("

"); if ((disk != null) && !disk.isEmpty()) { - text.append("

").append(Localization.lang("Value set externally")).append(":

" + "").append(disk).append(""); + text.append("

").append(Localization.lang("Value set externally")).append(":

").append(disk).append(""); } else { text.append("

").append(Localization.lang("Value cleared externally")).append("

"); } if ((mem != null) && !mem.isEmpty()) { - text.append("

").append(Localization.lang("Current value")).append(":

" + "").append(mem).append(""); + text.append("

").append(Localization.lang("Current value")).append(":

").append(mem).append(""); } tp.setText(text.toString()); diff --git a/src/main/java/org/jabref/collab/StringAddChange.java b/src/main/java/org/jabref/collab/StringAddChange.java index b2829830ca1..64b01d0ab57 100644 --- a/src/main/java/org/jabref/collab/StringAddChange.java +++ b/src/main/java/org/jabref/collab/StringAddChange.java @@ -3,6 +3,7 @@ import javax.swing.JComponent; import javax.swing.JScrollPane; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableInsertString; @@ -11,12 +12,8 @@ import org.jabref.model.database.KeyCollisionException; import org.jabref.model.entry.BibtexString; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - class StringAddChange extends Change { - private static final Log LOGGER = LogFactory.getLog(StringAddChange.class); private final BibtexString string; private final InfoPane tp = new InfoPane(); @@ -37,7 +34,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound if (panel.getDatabase().hasStringLabel(string.getName())) { // The name to change to is already in the database, so we can't comply. - LOGGER.info("Cannot add string '" + string.getName() + "' because the name " + Logger.info(this, "Cannot add string '" + string.getName() + "' because the name " + "is already in use."); } @@ -45,12 +42,12 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound panel.getDatabase().addString(string); undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), string)); } catch (KeyCollisionException ex) { - LOGGER.info("Error: could not add string '" + string.getName() + "': " + ex.getMessage(), ex); + Logger.info(this, "Error: could not add string '" + string.getName() + "'", ex); } try { secondary.addString(new BibtexString(string.getName(), string.getContent())); } catch (KeyCollisionException ex) { - LOGGER.info("Error: could not add string '" + string.getName() + "' to tmp database: " + ex.getMessage(), ex); + Logger.info(this, "Error: could not add string '" + string.getName() + "' to tmp database", ex); } return true; } diff --git a/src/main/java/org/jabref/collab/StringChange.java b/src/main/java/org/jabref/collab/StringChange.java index c93847d716f..abcb0951995 100644 --- a/src/main/java/org/jabref/collab/StringChange.java +++ b/src/main/java/org/jabref/collab/StringChange.java @@ -3,6 +3,7 @@ import javax.swing.JComponent; import javax.swing.JScrollPane; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableInsertString; @@ -12,12 +13,8 @@ import org.jabref.model.database.KeyCollisionException; import org.jabref.model.entry.BibtexString; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - class StringChange extends Change { - private static final Log LOGGER = LogFactory.getLog(StringChange.class); private final BibtexString string; private final String mem; private final String disk; @@ -63,7 +60,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound panel.getDatabase().addString(bs); undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs)); } catch (KeyCollisionException ex) { - LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex); + Logger.info(this, "Error: could not add string '" + bs.getName() + "'", ex); } } else { string.setContent(disk); diff --git a/src/main/java/org/jabref/collab/StringNameChange.java b/src/main/java/org/jabref/collab/StringNameChange.java index b53e7e63098..42c63522299 100644 --- a/src/main/java/org/jabref/collab/StringNameChange.java +++ b/src/main/java/org/jabref/collab/StringNameChange.java @@ -3,6 +3,7 @@ import javax.swing.JComponent; import javax.swing.JLabel; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableInsertString; @@ -12,12 +13,8 @@ import org.jabref.model.database.KeyCollisionException; import org.jabref.model.entry.BibtexString; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - class StringNameChange extends Change { - private static final Log LOGGER = LogFactory.getLog(StringNameChange.class); private final BibtexString string; private final String mem; private final String disk; @@ -42,7 +39,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound if (panel.getDatabase().hasStringLabel(disk)) { // The name to change to is already in the database, so we can't comply. - LOGGER.info("Cannot rename string '" + mem + "' to '" + disk + "' because the name " + Logger.info(this, "Cannot rename string '" + mem + "' to '" + disk + "' because the name " + "is already in use."); } @@ -53,7 +50,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound panel.getDatabase().addString(bs); undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs)); } catch (KeyCollisionException ex) { - LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex); + Logger.info(this, "Error: could not add string '" + bs.getName() + "'", ex); } } else { string.setName(disk); diff --git a/src/main/java/org/jabref/collab/StringRemoveChange.java b/src/main/java/org/jabref/collab/StringRemoveChange.java index 455704722ea..311a2a44ff7 100644 --- a/src/main/java/org/jabref/collab/StringRemoveChange.java +++ b/src/main/java/org/jabref/collab/StringRemoveChange.java @@ -3,6 +3,7 @@ import javax.swing.JComponent; import javax.swing.JScrollPane; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableRemoveString; @@ -10,11 +11,7 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibtexString; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - class StringRemoveChange extends Change { - private static final Log LOGGER = LogFactory.getLog(StringRemoveChange.class); private final BibtexString string; private final BibtexString inMem; @@ -42,7 +39,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound panel.getDatabase().removeString(inMem.getId()); undoEdit.addEdit(new UndoableRemoveString(panel, panel.getDatabase(), string)); } catch (Exception ex) { - LOGGER.info("Error: could not add string '" + string.getName() + "': " + ex.getMessage(), ex); + Logger.info(this, "Error: could not add string '" + string.getName() + "'", ex); } // Update tmp database: diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index fa37f93badf..a34f350d3d1 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -43,6 +43,7 @@ import org.jabref.Globals; import org.jabref.JabRefExecutorService; +import org.jabref.Logger; import org.jabref.collab.ChangeScanner; import org.jabref.collab.FileUpdateListener; import org.jabref.collab.FileUpdatePanel; @@ -144,12 +145,9 @@ import com.google.common.eventbus.Subscribe; import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListener { - private static final Log LOGGER = LogFactory.getLog(BasePanel.class); // Divider size for BaseFrame split pane. 0 means non-resizable. private static final int SPLIT_PANE_DIVIDER_SIZE = 4; @@ -230,7 +228,7 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) { try { fileMonitorHandle = Globals.getFileUpdateMonitor().addUpdateListener(this, file.get()); } catch (IOException ex) { - LOGGER.warn("Could not register FileUpdateMonitor", ex); + Logger.warn(this, "Could not register FileUpdateMonitor", ex); } } else { if (bibDatabaseContext.getDatabase().hasEntries()) { @@ -541,7 +539,7 @@ public void update() { try { JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath()); } catch (IOException e) { - LOGGER.info("Could not open folder", e); + Logger.info(this, "Could not open folder", e); } } })); @@ -635,7 +633,7 @@ public void update() { } output(outputStr); } catch (Throwable ex) { - LOGGER.warn("Could not unmark", ex); + Logger.warn(this, "Could not unmark", ex); } }); @@ -946,7 +944,7 @@ private void copyKeyAndTitle() { Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)) .getLayoutFromText(); } catch (IOException e) { - LOGGER.info("Could not get layout", e); + Logger.info(this, "Could not get layout", e); return; } @@ -1015,7 +1013,7 @@ private void openExternalFile() { */ public void runCommand(final String _command) { if (!actions.containsKey(_command)) { - LOGGER.info("No action defined for '" + _command + '\''); + Logger.info(this, "No action defined for '" + _command + '\''); return; } @@ -1031,7 +1029,7 @@ public void runCommand(final String _command) { // The call to unblock will simply hide the glasspane, so there is no harm in calling // it even if the frame hasn't been blocked. frame.unblock(); - LOGGER.error("runCommand error: " + ex.getMessage(), ex); + Logger.error(this, "runCommand error", ex); } } @@ -1066,7 +1064,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc, highlightEntry(ex.getEntry()); showEntry(ex.getEntry()); } else { - LOGGER.warn("Could not save", ex); + Logger.warn(this, "Could not save", ex); } JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + "\n" + ex.getMessage(), @@ -1176,7 +1174,7 @@ public BibEntry newEntry(EntryType type) { return be; } catch (KeyCollisionException ex) { - LOGGER.info(ex.getMessage(), ex); + Logger.info(this, ex); } } return null; @@ -1205,7 +1203,7 @@ public void insertEntry(final BibEntry bibEntry) { } highlightEntry(bibEntry); } catch (KeyCollisionException ex) { - LOGGER.info("Collision for bibtex key" + bibEntry.getId(), ex); + Logger.info(this, "Collision for bibtex key" + bibEntry.getId(), ex); } } } @@ -1264,7 +1262,7 @@ public void actionPerformed(ActionEvent e) { entryEditorClosing(getCurrentEditor()); break; default: - LOGGER.warn("unknown BasePanelMode: '" + mode + "', doing nothing"); + Logger.warn(this, "unknown BasePanelMode: '" + mode + "', doing nothing"); break; } } @@ -1277,7 +1275,7 @@ public void actionPerformed(ActionEvent e) { try { runCommand(Actions.CUT); } catch (Throwable ex) { - LOGGER.warn("Could not cut", ex); + Logger.warn(this, "Could not cut", ex); } } }); @@ -1288,7 +1286,7 @@ public void actionPerformed(ActionEvent e) { try { runCommand(Actions.COPY); } catch (Throwable ex) { - LOGGER.warn("Could not copy", ex); + Logger.warn(this, "Could not copy", ex); } } }); @@ -1299,7 +1297,7 @@ public void actionPerformed(ActionEvent e) { try { runCommand(Actions.PASTE); } catch (Throwable ex) { - LOGGER.warn("Could not paste", ex); + Logger.warn(this, "Could not paste", ex); } } }); @@ -1328,7 +1326,7 @@ public void keyPressed(KeyEvent e) { try { runCommand(Actions.EDIT); } catch (Throwable ex) { - LOGGER.warn("Could not run action based on key press", ex); + Logger.warn(this, "Could not run action based on key press", ex); } } } @@ -1613,7 +1611,7 @@ public void markBaseChanged() { try { SwingUtilities.invokeAndWait(() -> markBasedChangedInternal()); } catch (InvocationTargetException | InterruptedException e) { - LOGGER.info("Problem marking database as changed", e); + Logger.info(this, "Problem marking database as changed", e); } } } @@ -1670,7 +1668,7 @@ public void changeTypeOfSelectedEntries(String newType) { private void changeType(List entries, String newType) { if ((entries == null) || (entries.isEmpty())) { - LOGGER.error("At least one entry must be selected to be able to change the type."); + Logger.error(this, "At least one entry must be selected to be able to change the type."); return; } @@ -1808,7 +1806,7 @@ public void fileUpdated() { if ((getBibDatabaseContext().getDatabaseFile().isPresent()) && !FileBasedLock.waitForFileLock(getBibDatabaseContext().getDatabaseFile().get().toPath())) { // The file is locked even after the maximum wait. Do nothing. - LOGGER.error("File updated externally, but change scan failed because the file is locked."); + Logger.error(this, "File updated externally, but change scan failed because the file is locked."); // Perturb the stored timestamp so successive checks are made: Globals.getFileUpdateMonitor().perturbTimestamp(getFileMonitorHandle()); return; @@ -1842,7 +1840,7 @@ public void fileUpdated() { @Override public void fileRemoved() { - LOGGER.info("File '" + getBibDatabaseContext().getDatabaseFile().get().getPath() + "' has been deleted."); + Logger.info(this, "File '" + getBibDatabaseContext().getDatabaseFile().get().getPath() + "' has been deleted."); } /** @@ -2151,7 +2149,7 @@ public void action() { markBaseChanged(); frame.output(Localization.lang("Undo")); } catch (CannotUndoException ex) { - LOGGER.warn("Nothing to undo", ex); + Logger.warn(this, "Nothing to undo", ex); frame.output(Localization.lang("Nothing to undo") + '.'); } @@ -2202,7 +2200,7 @@ public void action() { output(Localization.lang("External viewer called") + '.'); } catch (IOException e) { output(Localization.lang("Could not open link")); - LOGGER.info("Could not open link", e); + Logger.info(this, "Could not open link", e); } } } diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index e202f51a7fa..a36851009cc 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -14,6 +14,7 @@ import java.util.Optional; import org.jabref.Globals; +import org.jabref.Logger; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.fetcher.DoiFetcher; import org.jabref.logic.importer.fileformat.BibtexParser; @@ -21,11 +22,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.identifier.DOI; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - public class ClipBoardManager implements ClipboardOwner { - private static final Log LOGGER = LogFactory.getLog(ClipBoardManager.class); private static final Clipboard CLIPBOARD = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -59,7 +56,7 @@ public String getClipboardContents() { result = (String) contents.getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException | IOException e) { //highly unlikely since we are using a standard DataFlavor - LOGGER.info("problem with getting clipboard contents", e); + Logger.info(this, "problem with getting clipboard contents", e); } } return result; @@ -86,33 +83,33 @@ public List extractBibEntriesFromClipboard() { List contents = (List) content.getTransferData(TransferableBibtexEntry.ENTRY_FLAVOR); result = contents; } catch (UnsupportedFlavorException | ClassCastException ex) { - LOGGER.warn("Could not paste this type", ex); + Logger.warn(this, "Could not paste this type", ex); } catch (IOException ex) { - LOGGER.warn("Could not paste", ex); + Logger.warn(this, "Could not paste", ex); } } else if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { String data = (String) content.getTransferData(DataFlavor.stringFlavor); // fetch from doi if (DOI.parse(data).isPresent()) { - LOGGER.info("Found DOI in clipboard"); + Logger.info(this, "Found DOI in clipboard"); Optional entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(new DOI(data).getDOI()); entry.ifPresent(result::add); } else { // parse bibtex string BibtexParser bp = new BibtexParser(Globals.prefs.getImportFormatPreferences()); BibDatabase db = bp.parse(new StringReader(data)).getDatabase(); - LOGGER.info("Parsed " + db.getEntryCount() + " entries from clipboard text"); + Logger.info(this, "Parsed " + db.getEntryCount() + " entries from clipboard text"); if (db.hasEntries()) { result = db.getEntries(); } } } catch (UnsupportedFlavorException ex) { - LOGGER.warn("Could not parse this type", ex); + Logger.warn(this, "Could not parse this type", ex); } catch (IOException ex) { - LOGGER.warn("Data is no longer available in the requested flavor", ex); + Logger.warn(this, "Data is no longer available in the requested flavor", ex); } catch (FetcherException ex) { - LOGGER.error("Error while fetching", ex); + Logger.error(this, "Error while fetching", ex); } } diff --git a/src/main/java/org/jabref/gui/DefaultInjector.java b/src/main/java/org/jabref/gui/DefaultInjector.java index 93845ce5dca..3f47cabe0db 100644 --- a/src/main/java/org/jabref/gui/DefaultInjector.java +++ b/src/main/java/org/jabref/gui/DefaultInjector.java @@ -3,6 +3,7 @@ import java.util.function.Function; import org.jabref.Globals; +import org.jabref.Logger; import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.journals.JournalAbbreviationLoader; @@ -10,12 +11,10 @@ import com.airhacks.afterburner.injection.Injector; import com.airhacks.afterburner.injection.PresenterFactory; -import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class DefaultInjector implements PresenterFactory { - private static final Log LOGGER = LogFactory.getLog(DefaultInjector.class); /** * This method takes care of creating dependencies. @@ -39,7 +38,7 @@ private static Object createDependency(Class clazz) { try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { - LOGGER.error("Cannot instantiate dependency: " + clazz, ex); + LogFactory.getLog(DefaultInjector.class).error("Cannot instantiate dependency: " + clazz, ex); return null; } } @@ -47,7 +46,7 @@ private static Object createDependency(Class clazz) { @Override public T instantiatePresenter(Class clazz, Function injectionContext) { - LOGGER.debug("Instantiate " + clazz.getName()); + Logger.debug(this, "Instantiate " + clazz.getName()); // Use our own method to construct dependencies Injector.setInstanceSupplier(DefaultInjector::createDependency); diff --git a/src/main/java/org/jabref/gui/EntryTypeDialog.java b/src/main/java/org/jabref/gui/EntryTypeDialog.java index 27c0e5f1d55..21e7e5fa3f2 100644 --- a/src/main/java/org/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/org/jabref/gui/EntryTypeDialog.java @@ -26,6 +26,7 @@ import javax.swing.SwingWorker; import org.jabref.Globals; +import org.jabref.Logger; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import org.jabref.logic.importer.FetcherException; @@ -42,8 +43,6 @@ import org.jabref.model.entry.IEEETranEntryTypes; import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.VerticalLayout; /** @@ -52,7 +51,6 @@ */ public class EntryTypeDialog extends JabRefDialog implements ActionListener { - private static final Log LOGGER = LogFactory.getLog(EntryTypeDialog.class); private static final int COLUMN = 3; private final JabRefFrame frame; private final CancelAction cancelAction = new CancelAction(); @@ -291,7 +289,7 @@ protected Optional doInBackground() throws Exception { try { bibEntry = fetcher.performSearchById(searchID); } catch (FetcherException e) { - LOGGER.error(e.getMessage(), e); + Logger.error(this, e.getMessage(), e); fetcherException = true; fetcherExceptionMessage = e.getMessage(); } @@ -316,7 +314,7 @@ protected void done() { JOptionPane.showMessageDialog(frame, Localization.lang("Fetcher_'%0'_did_not_find_an_entry_for_id_'%1'.", fetcher.getName(), searchID) + "\n" + fetcherExceptionMessage, Localization.lang("No files found."), JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(frame, - Localization.lang("Error while fetching from %0", fetcher.getName()) + "." + "\n" + fetcherExceptionMessage, + Localization.lang("Error while fetching from %0", fetcher.getName()) + ".\n" + fetcherExceptionMessage, Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); } fetcherWorker = new FetcherWorker(); @@ -327,7 +325,7 @@ protected void done() { generateButton.setEnabled(true); }); } catch (ExecutionException | InterruptedException e) { - LOGGER.error(String.format("Exception during fetching when using fetcher '%s' with entry id '%s'.", searchID, fetcher.getName()), e); + Logger.error(this, "Exception during fetching when using fetcher '%s' with entry id '%s'", e, searchID, fetcher.getName()); } } } diff --git a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java index 678fa520942..200a780675f 100644 --- a/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java +++ b/src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java @@ -67,6 +67,7 @@ import org.jabref.Globals; import org.jabref.JabRefExecutorService; import org.jabref.JabRefGUI; +import org.jabref.Logger; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.importer.EntryFromFileCreator; import org.jabref.gui.importer.EntryFromFileCreatorManager; @@ -83,8 +84,6 @@ import org.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * GUI Dialog for the feature "Find unlinked files". @@ -99,7 +98,6 @@ public class FindUnlinkedFilesDialog extends JabRefDialog { public static final String ACTION_SHORT_DESCRIPTION = Localization .lang("Searches for unlinked PDF files on the file system"); - private static final Log LOGGER = LogFactory.getLog(FindUnlinkedFilesDialog.class); private static final String GLOBAL_PREFS_WORKING_DIRECTORY_KEY = "findUnlinkedFilesWD"; private static final String GLOBAL_PREFS_DIALOG_SIZE_KEY = "findUnlinkedFilesDialogSize"; @@ -212,7 +210,7 @@ private void restoreSizeOfDialog() { String[] dim = store.split(";"); dimension = new Dimension(Integer.valueOf(dim[0]), Integer.valueOf(dim[1])); } catch (NumberFormatException ignoredEx) { - LOGGER.debug("RestoreSizeDialog Exception ", ignoredEx); + Logger.debug(this, "RestoreSizeDialog Exception ", ignoredEx); } } if (dimension != null) { @@ -938,7 +936,7 @@ public void mousePressed(MouseEvent e) { JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(), fnw.file.getAbsolutePath(), FieldName.PDF); } catch (IOException e1) { - LOGGER.info("Error opening file", e1); + Logger.info(this, "Error opening file: %[exception]s", e1); } } } else { diff --git a/src/main/java/org/jabref/gui/JEditorPaneWithHighlighting.java b/src/main/java/org/jabref/gui/JEditorPaneWithHighlighting.java index 147df8f34f0..aec4534068d 100644 --- a/src/main/java/org/jabref/gui/JEditorPaneWithHighlighting.java +++ b/src/main/java/org/jabref/gui/JEditorPaneWithHighlighting.java @@ -11,16 +11,11 @@ import javax.swing.text.Highlighter; import javax.swing.text.LayeredHighlighter.LayerPainter; -import org.jabref.gui.fieldeditors.JTextAreaWithHighlighting; +import org.jabref.Logger; import org.jabref.logic.search.SearchQueryHighlightListener; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - public class JEditorPaneWithHighlighting extends JEditorPane implements SearchQueryHighlightListener { - private static final Log LOGGER = LogFactory.getLog(JTextAreaWithHighlighting.class); - public void highlightPattern(Optional highlightPattern) { Highlighter highlighter = getHighlighter(); highlighter.removeAllHighlights(); @@ -38,7 +33,7 @@ public void highlightPattern(Optional highlightPattern) { highlighter.addHighlight(matcher.start(), matcher.end(), painter); } catch (BadLocationException ble) { // should not occur if matcher works right - LOGGER.warn("Highlighting not possible, bad location", ble); + Logger.warn(this, "Highlighting not possible, bad location", ble); } } } @@ -49,7 +44,7 @@ private String getDocumentText() { try { text = doc.getText(0, doc.getLength()); } catch (Exception e) { - LOGGER.error("Error while getting document text"); + Logger.error(this, "Error while getting document text"); text = ""; } return text; diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 1b25660beb2..a226f09e14f 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -64,6 +64,7 @@ import javafx.application.Platform; import org.jabref.Globals; +import org.jabref.Logger; import org.jabref.gui.actions.Actions; import org.jabref.gui.actions.AutoLinkFilesAction; import org.jabref.gui.actions.ConnectToSharedDatabaseAction; @@ -145,15 +146,12 @@ import com.google.common.eventbus.Subscribe; import com.jgoodies.looks.HeaderStyle; import com.jgoodies.looks.Options; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import osx.macadapter.MacAdapter; /** * The main window of the application. */ public class JabRefFrame extends JFrame implements OutputPrinter { - private static final Log LOGGER = LogFactory.getLog(JabRefFrame.class); // Frame titles. private static final String FRAME_TITLE = "JabRef"; @@ -651,7 +649,7 @@ public void windowClosing(WindowEvent e) { try { new MacAdapter().registerMacEvents(this); } catch (Exception e) { - LOGGER.fatal("Could not interface with Mac OS X methods.", e); + Logger.error(this, "Could not interface with Mac OS X methods.", e); } } @@ -1517,7 +1515,7 @@ private List collectDatabaseFilePaths() { dbPaths.add(""); } } catch (IOException ex) { - LOGGER.error("Invalid database file path: " + ex.getMessage()); + Logger.error(this, "Invalid database file path: " + ex.getMessage()); } } return dbPaths; @@ -1685,7 +1683,7 @@ private void changeBlocking(boolean blocked) { try { SwingUtilities.invokeAndWait(() -> getGlassPane().setVisible(blocked)); } catch (InvocationTargetException | InterruptedException e) { - LOGGER.error("Problem " + (blocked ? "" : "un") + "blocking UI", e); + Logger.error(this, "Problem " + (blocked ? "" : "un") + "blocking UI", e); } } } @@ -2042,10 +2040,10 @@ public void actionPerformed(ActionEvent e) { try { ((BasePanel) tabbedPane.getSelectedComponent()).runCommand(command); } catch (Throwable ex) { - LOGGER.error("Problem with executing command: " + command, ex); + Logger.error(this, "Problem with executing command: " + command, ex); } } else { - LOGGER.info("Action '" + command + "' must be disabled when no database is open."); + Logger.info(this, "Action '" + command + "' must be disabled when no database is open."); } } } @@ -2127,7 +2125,7 @@ public EditAction(String command, String menuTitle, String description, KeyStrok @Override public void actionPerformed(ActionEvent e) { - LOGGER.debug(Globals.getFocusListener().getFocused().toString()); + Logger.debug(this, Globals.getFocusListener().getFocused().toString()); JComponent source = Globals.getFocusListener().getFocused(); Action action = source.getActionMap().get(command); if (action != null) { diff --git a/src/main/java/org/jabref/gui/PreviewPanel.java b/src/main/java/org/jabref/gui/PreviewPanel.java index 848c410e1d3..f4b151bd653 100644 --- a/src/main/java/org/jabref/gui/PreviewPanel.java +++ b/src/main/java/org/jabref/gui/PreviewPanel.java @@ -28,6 +28,7 @@ import org.jabref.Globals; import org.jabref.JabRefExecutorService; +import org.jabref.Logger; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.fieldeditors.PreviewPanelTransferHandler; import org.jabref.gui.keyboard.KeyBinding; @@ -45,15 +46,12 @@ import org.jabref.preferences.PreviewPreferences; import com.google.common.eventbus.Subscribe; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Displays an BibEntry using the given layout format. */ public class PreviewPanel extends JPanel implements SearchQueryHighlightListener, EntryContainer { - private static final Log LOGGER = LogFactory.getLog(PreviewPanel.class); /** * The bibtex entry currently shown @@ -174,7 +172,7 @@ public Dimension getPreferredScrollableViewportSize() { String address = hyperlinkEvent.getURL().toString(); JabRefDesktop.openExternalViewer(PreviewPanel.this.databaseContext.get(), address, FieldName.URL); } catch (IOException e) { - LOGGER.warn("Could not open external viewer", e); + Logger.warn(this, "Could not open external viewer", e); } } }); @@ -195,7 +193,7 @@ public void setBasePanel(BasePanel basePanel) { public void updateLayout() { if (fixedLayout) { - LOGGER.debug("cannot change the layout because the layout is fixed"); + Logger.debug(this, "cannot change the layout because the layout is fixed"); return; } @@ -229,7 +227,7 @@ private void updatePreviewLayout(String layoutFile) { .getLayoutFromText()); } catch (IOException e) { layout = Optional.empty(); - LOGGER.debug("no layout could be set", e); + Logger.debug(this, "no layout could be set", e); } } @@ -329,7 +327,7 @@ public PreviewPanel setFixedLayout(Object parameter) { basePanel.get().getCitationStyleCache().setCitationStyle((CitationStyle) parameter); } } else { - LOGGER.error("unknown style type"); + Logger.error(this, "unknown style type"); } update(); return this; @@ -357,7 +355,7 @@ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(PreviewPanel.this, Localization.lang("Could not print preview") + ".\n" + e.getMessage(), Localization.lang("Print entry preview"), JOptionPane.ERROR_MESSAGE); - LOGGER.info("Could not print preview", e); + Logger.info(this, "Could not print preview", e); } }); } diff --git a/src/main/java/org/jabref/gui/actions/LookupIdentifierAction.java b/src/main/java/org/jabref/gui/actions/LookupIdentifierAction.java index 9e1fb4f1126..eb1bfc6ca88 100644 --- a/src/main/java/org/jabref/gui/actions/LookupIdentifierAction.java +++ b/src/main/java/org/jabref/gui/actions/LookupIdentifierAction.java @@ -4,17 +4,14 @@ import javax.swing.Action; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefFrame; import org.jabref.gui.worker.LookupIdentifiersWorker; import org.jabref.logic.importer.IdFetcher; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - public class LookupIdentifierAction extends MnemonicAwareAction { - private static final Log LOGGER = LogFactory.getLog(LookupIdentifierAction.class); private final JabRefFrame frame; private final IdFetcher fetcher; @@ -32,7 +29,7 @@ public void actionPerformed(ActionEvent actionEvent) { try { BasePanel.runWorker(new LookupIdentifiersWorker(frame, fetcher)); } catch (Exception e) { - LOGGER.error(e); + Logger.error(this, "worker error", e); } } } diff --git a/src/main/java/org/jabref/gui/actions/NewEntryAction.java b/src/main/java/org/jabref/gui/actions/NewEntryAction.java index 63e009fa665..3d836d4ac2d 100644 --- a/src/main/java/org/jabref/gui/actions/NewEntryAction.java +++ b/src/main/java/org/jabref/gui/actions/NewEntryAction.java @@ -5,6 +5,7 @@ import javax.swing.Action; import javax.swing.KeyStroke; +import org.jabref.Logger; import org.jabref.gui.EntryTypeDialog; import org.jabref.gui.IconTheme; import org.jabref.gui.JabRefFrame; @@ -13,11 +14,7 @@ import org.jabref.model.entry.EntryType; import org.jabref.model.strings.StringUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - public class NewEntryAction extends MnemonicAwareAction { - private static final Log LOGGER = LogFactory.getLog(NewEntryAction.class); private final JabRefFrame jabRefFrame; private String type; // The type of item to create. @@ -65,7 +62,7 @@ public void actionPerformed(ActionEvent e) { EntryTypes.getType(thisType, jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMode()) .get()); } else { - LOGGER.info("Action 'New entry' must be disabled when no database is open."); + Logger.info(this, "Action 'New entry' must be disabled when no database is open."); } } } diff --git a/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveUIManager.java b/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveUIManager.java index 52efccbb5f0..28c700d5a62 100644 --- a/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveUIManager.java +++ b/src/main/java/org/jabref/gui/autosaveandbackup/AutosaveUIManager.java @@ -1,12 +1,11 @@ package org.jabref.gui.autosaveandbackup; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.exporter.SaveDatabaseAction; import org.jabref.model.database.event.AutosaveEvent; import com.google.common.eventbus.Subscribe; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * This class has an abstract UI role as it listens for an {@link AutosaveEvent} @@ -14,7 +13,6 @@ */ public class AutosaveUIManager { - private static final Log LOGGER = LogFactory.getLog(AutosaveUIManager.class); private final BasePanel panel; @@ -27,7 +25,7 @@ public void listen(@SuppressWarnings("unused") AutosaveEvent event) { try { new SaveDatabaseAction(panel).runCommand(); } catch (Throwable e) { - LOGGER.error("Problem occured while saving.", e); + Logger.error(this, "Problem occured while saving.", e); } } } diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 2de98920b40..2e42c598177 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -112,7 +112,7 @@ private void jbInit() { JLabel desc = new JLabel("

" + Localization.lang("AUX file import") + "

" + Localization.lang("This feature generates a new library based on which entries " + "are needed in an existing LaTeX document.") - + "

" + "

" + + "

" + Localization.lang("You need to select one of your open libraries from which to choose " + "entries, as well as the AUX file produced by LaTeX when compiling your document.") + "

"); diff --git a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java index 2fb061ee6e9..e7d4404f336 100644 --- a/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java +++ b/src/main/java/org/jabref/gui/contentselector/ContentSelectorDialog.java @@ -28,6 +28,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; +import org.jabref.Logger; import org.jabref.gui.BasePanel; import org.jabref.gui.JabRefDialog; import org.jabref.gui.JabRefFrame; @@ -41,14 +42,11 @@ import org.jabref.model.metadata.MetaData; import com.jgoodies.forms.builder.ButtonBarBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class ContentSelectorDialog extends JabRefDialog { private static final String WORD_FIRSTLINE_TEXT = Localization.lang("