diff --git a/.classpath b/.classpath index fb1a79e75..da46644a7 100644 --- a/.classpath +++ b/.classpath @@ -19,5 +19,7 @@ + + diff --git a/build.xml b/build.xml index 932571124..112d6095f 100644 --- a/build.xml +++ b/build.xml @@ -5,6 +5,8 @@ + + @@ -31,7 +33,7 @@ deprecation="false" debug="false" debuglevel="lines,vars,source" - classpath="${classpath}:${jorbis.file}:${rsyntaxtextarea.file}:${jhexview.file}:${montemedia.file}:${apng_writer.file}:${json.file}:${commonmark.file}:${flatlaf.file}:${flatlafthemes.file}"> + classpath="${classpath}:${tinylog-api.file}:${tinylog-impl.file}:${jorbis.file}:${rsyntaxtextarea.file}:${jhexview.file}:${montemedia.file}:${apng_writer.file}:${json.file}:${commonmark.file}:${flatlaf.file}:${flatlafthemes.file}"> @@ -50,6 +52,8 @@ basedir="${build.path}" includes="**/*" level="9"> + + diff --git a/lib/tinylog/license.txt b/lib/tinylog/license.txt new file mode 100644 index 000000000..f433b1a53 --- /dev/null +++ b/lib/tinylog/license.txt @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/lib/tinylog/readme.txt b/lib/tinylog/readme.txt new file mode 100644 index 000000000..cadda4f7a --- /dev/null +++ b/lib/tinylog/readme.txt @@ -0,0 +1,24 @@ +Copyright 2018 Martin Winandy + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +------------------- + Using tinylog +------------------- + +To use tinylog as a logging framework, add tinylog-api.jar and an +implementation such as tinylog-impl.jar to the classpath. + +tinylog-impl.jar is the default implementation for tinylog. There are also +implementations for application and web servers to use their logging +frameworks. Since tinylog 2, multiple implementations can even be used in +parallel. diff --git a/lib/tinylog/tinylog-api-2.7.0-sources.jar b/lib/tinylog/tinylog-api-2.7.0-sources.jar new file mode 100644 index 000000000..8ba31eea1 Binary files /dev/null and b/lib/tinylog/tinylog-api-2.7.0-sources.jar differ diff --git a/lib/tinylog/tinylog-api-2.7.0.jar b/lib/tinylog/tinylog-api-2.7.0.jar new file mode 100644 index 000000000..94c2bdc36 Binary files /dev/null and b/lib/tinylog/tinylog-api-2.7.0.jar differ diff --git a/lib/tinylog/tinylog-impl-2.7.0-sources.jar b/lib/tinylog/tinylog-impl-2.7.0-sources.jar new file mode 100644 index 000000000..a72d47e1c Binary files /dev/null and b/lib/tinylog/tinylog-impl-2.7.0-sources.jar differ diff --git a/lib/tinylog/tinylog-impl-2.7.0.jar b/lib/tinylog/tinylog-impl-2.7.0.jar new file mode 100644 index 000000000..3daf6899c Binary files /dev/null and b/lib/tinylog/tinylog-impl-2.7.0.jar differ diff --git a/src/org/infinity/NearInfinity.java b/src/org/infinity/NearInfinity.java index 5068dde3e..71ddbfdee 100644 --- a/src/org/infinity/NearInfinity.java +++ b/src/org/infinity/NearInfinity.java @@ -134,6 +134,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; public final class NearInfinity extends JFrame implements ActionListener, ViewableContainer { // the current Near Infinity version @@ -371,7 +372,7 @@ public static void main(String args[]) { final LookAndFeel o = lf.getDeclaredConstructor().newInstance(); UIManager.installLookAndFeel(o.getName(), o.getClass().getCanonicalName()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -445,7 +446,7 @@ protected Void doInBackground() throws Exception { try { checkFileAccess(tlkFile); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(NearInfinity.this, String.format("Unable to open the game \"%s\".\n" + "The file \"%s\" is locked by another process.", @@ -468,7 +469,7 @@ protected Void doInBackground() throws Exception { worker.execute(); worker.get(); } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + Logger.error(e); System.exit(10); } @@ -484,7 +485,7 @@ public void windowClosing(WindowEvent event) { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(this); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } cacheResourceIcons(true); @@ -623,7 +624,7 @@ public void popupWindowWillBecomeInvisible(PopupWindowEvent event) { } } } catch (Exception e) { - System.out.println("Failed to check for updates: " + e.getMessage()); + Logger.warn("Failed to check for updates: {}", e.getMessage()); } }).start(); } @@ -704,7 +705,7 @@ public void actionPerformed(ActionEvent event) { LookAndFeelInfo info = BrowserMenuBar.getInstance().getOptions().getLookAndFeel(); updateLookAndFeel(info, true); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } else if (event.getActionCommand().equals("Collapse")) { try { @@ -840,7 +841,7 @@ public void openGame(Path keyFile) { try { checkFileAccess(tlkPath); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(NearInfinity.this, String.format("The file \"%s\" of the game \"%s\"\nis locked by another process. " + "Reverting to the previous game.", tlkPath.getFileName(), @@ -1285,7 +1286,7 @@ private boolean migratePreferences(String sourceNode, Preferences curPrefs, bool } } catch (Exception e) { prefsOld = null; - e.printStackTrace(); + Logger.error(e); } if (isPrefsEmpty && prefsOld != null && !prefsOld.equals(curPrefs)) { try { @@ -1297,7 +1298,7 @@ private boolean migratePreferences(String sourceNode, Preferences curPrefs, bool curPrefs.clear(); } catch (BackingStoreException bse) { } - e.printStackTrace(); + Logger.error(e); if (showError) { JOptionPane.showMessageDialog(this, "Error migrating old Near Infinity settings. Using defaults.", "Error", JOptionPane.ERROR_MESSAGE); @@ -1350,7 +1351,7 @@ private void enableOSXQuitStrategy() { method.invoke(instance, closeAllWindows); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -1370,7 +1371,7 @@ private boolean launchGameBinary(Path binPath) { } retVal = true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; @@ -1578,7 +1579,7 @@ private void cacheResourceIcons(boolean threaded) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } }; @@ -1593,7 +1594,7 @@ protected Void doInBackground() throws Exception { try { operation.perform(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } setProgress(100); return null; @@ -1660,7 +1661,7 @@ public void write(byte buf[], int off, int len) { try { text.append(new String(buf, off, len)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -1698,7 +1699,7 @@ public void drop(DropTargetDropEvent event) { event.acceptDrop(DnDConstants.ACTION_COPY); files = (List) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); event.dropComplete(false); } event.dropComplete(true); diff --git a/src/org/infinity/check/BCSIDSChecker.java b/src/org/infinity/check/BCSIDSChecker.java index dd931a119..89674ec13 100644 --- a/src/org/infinity/check/BCSIDSChecker.java +++ b/src/org/infinity/check/BCSIDSChecker.java @@ -41,6 +41,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.search.AbstractSearcher; import org.infinity.util.Misc; +import org.tinylog.Logger; /** Performs checking {@link BcsResource BCS} & {@code BS} resources. */ public final class BCSIDSChecker extends AbstractSearcher implements Runnable, ActionListener, ListSelectionListener { @@ -179,9 +180,7 @@ protected Runnable newWorker(ResourceEntry entry) { try { checkScript(new BcsResource(entry)); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } advanceProgress(); }; diff --git a/src/org/infinity/check/CreInvChecker.java b/src/org/infinity/check/CreInvChecker.java index 23a8aeecf..da7b25746 100644 --- a/src/org/infinity/check/CreInvChecker.java +++ b/src/org/infinity/check/CreInvChecker.java @@ -44,6 +44,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.search.AbstractSearcher; import org.infinity.util.Misc; +import org.tinylog.Logger; /** Performs checking {@link CreResource CRE} & {@code CHR} resources. */ public final class CreInvChecker extends AbstractSearcher implements Runnable, ActionListener, ListSelectionListener { @@ -181,9 +182,7 @@ protected Runnable newWorker(ResourceEntry entry) { try { checkCreature(new CreResource(entry)); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } advanceProgress(); }; diff --git a/src/org/infinity/check/DialogChecker.java b/src/org/infinity/check/DialogChecker.java index 3d0915621..e33637325 100644 --- a/src/org/infinity/check/DialogChecker.java +++ b/src/org/infinity/check/DialogChecker.java @@ -48,6 +48,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.search.AbstractSearcher; import org.infinity.util.Misc; +import org.tinylog.Logger; /** Performs checking {@link DlgResource DLG} resources. */ public final class DialogChecker extends AbstractSearcher @@ -242,9 +243,7 @@ protected Runnable newWorker(ResourceEntry entry) { } } } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } advanceProgress(); }; diff --git a/src/org/infinity/check/ResourceUseChecker.java b/src/org/infinity/check/ResourceUseChecker.java index 10454331d..b2e8e2a33 100644 --- a/src/org/infinity/check/ResourceUseChecker.java +++ b/src/org/infinity/check/ResourceUseChecker.java @@ -58,6 +58,7 @@ import org.infinity.resource.text.PlainTextResource; import org.infinity.util.Misc; import org.infinity.util.StringTable; +import org.tinylog.Logger; public final class ResourceUseChecker extends AbstractChecker implements Runnable, ListSelectionListener, ActionListener { @@ -245,9 +246,7 @@ private void checkDialog(DlgResource dialog) { checkCode(compiler.getCode(), type); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } else if (checkTypes.contains("WAV") && (entry instanceof State || entry instanceof Transition)) { for (final StructEntry e : ((AbstractStruct) entry).getFlatFields()) { @@ -263,9 +262,7 @@ private void checkScript(BcsResource script) { try { checkCode(script.getCode(), ScriptType.BCS); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } diff --git a/src/org/infinity/check/ScriptChecker.java b/src/org/infinity/check/ScriptChecker.java index 096dc2b99..1fa10873e 100644 --- a/src/org/infinity/check/ScriptChecker.java +++ b/src/org/infinity/check/ScriptChecker.java @@ -43,6 +43,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.search.AbstractSearcher; import org.infinity.util.Misc; +import org.tinylog.Logger; /** Performs checking {@link BcsResource BCS} & {@code BS} resources. */ public final class ScriptChecker extends AbstractSearcher @@ -240,9 +241,7 @@ protected Runnable newWorker(ResourceEntry entry) { } } } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } advanceProgress(); }; diff --git a/src/org/infinity/check/StringUseChecker.java b/src/org/infinity/check/StringUseChecker.java index 93623347c..dcbde2e78 100644 --- a/src/org/infinity/check/StringUseChecker.java +++ b/src/org/infinity/check/StringUseChecker.java @@ -61,6 +61,7 @@ import org.infinity.util.StringTable; import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; +import org.tinylog.Logger; public final class StringUseChecker extends AbstractSearcher implements Runnable, ListSelectionListener, SearchClient, ActionListener { @@ -375,9 +376,7 @@ private void checkDialog(DlgResource dialog) { checkCode(compiler.getCode(), type); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } } @@ -387,9 +386,7 @@ private void checkScript(BcsResource script) { try { checkCode(script.getCode(), ScriptType.BCS); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } @@ -550,7 +547,7 @@ private void checkBestiaryLua() { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/check/StringValidationChecker.java b/src/org/infinity/check/StringValidationChecker.java index c5dff6629..ecbb45e19 100644 --- a/src/org/infinity/check/StringValidationChecker.java +++ b/src/org/infinity/check/StringValidationChecker.java @@ -55,6 +55,7 @@ import org.infinity.util.Misc; import org.infinity.util.StringTable; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class StringValidationChecker extends AbstractSearcher implements Runnable, ActionListener, ListSelectionListener { @@ -257,17 +258,13 @@ protected Runnable newWorker(ResourceEntry entry) { try { validateInput(decoder, inBuf, outBuf, entry, idx, isFemale); } catch (IllegalStateException | CoderMalfunctionError e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } decoder.reset(); } } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } advanceProgress(); diff --git a/src/org/infinity/check/StrrefIndexChecker.java b/src/org/infinity/check/StrrefIndexChecker.java index 18c9edc9c..fa63e74bf 100644 --- a/src/org/infinity/check/StrrefIndexChecker.java +++ b/src/org/infinity/check/StrrefIndexChecker.java @@ -52,6 +52,7 @@ import org.infinity.util.StringTable; import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; +import org.tinylog.Logger; public class StrrefIndexChecker extends AbstractChecker implements ListSelectionListener { private final ChildFrame resultFrame = new ChildFrame("Illegal strrefs found", true); @@ -217,9 +218,7 @@ private void checkDialog(DlgResource dialog) { } } } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } } @@ -254,9 +253,7 @@ private void checkScript(BcsResource script) { } } } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } @@ -302,9 +299,7 @@ private void checkText(PlainTextResource text) { } } } catch (NumberFormatException e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } } diff --git a/src/org/infinity/check/StructChecker.java b/src/org/infinity/check/StructChecker.java index 320639028..5d2584dbe 100644 --- a/src/org/infinity/check/StructChecker.java +++ b/src/org/infinity/check/StructChecker.java @@ -57,6 +57,7 @@ import org.infinity.resource.wed.Tilemap; import org.infinity.util.Misc; import org.infinity.util.StringTable; +import org.tinylog.Logger; public final class StructChecker extends AbstractChecker implements ListSelectionListener { private static final String[] FILETYPES = { "ARE", "CHR", "CHU", "CRE", "DLG", "EFF", "GAM", "ITM", "PRO", "SPL", @@ -498,7 +499,7 @@ private void showInViewer(Corruption corruption, boolean newWindow) { try { ((AbstractStruct) res).getViewer().selectEntry(offset); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } else { @@ -512,7 +513,7 @@ private void showInViewer(Corruption corruption, boolean newWindow) { try { ((AbstractStruct) res).getViewer().selectEntry(offset); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } else { @@ -522,7 +523,7 @@ private void showInViewer(Corruption corruption, boolean newWindow) { try { ((AbstractStruct) viewable).getViewer().selectEntry(offset); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } }); diff --git a/src/org/infinity/datatype/AreResourceRef.java b/src/org/infinity/datatype/AreResourceRef.java index f2dd49478..0107b7758 100644 --- a/src/org/infinity/datatype/AreResourceRef.java +++ b/src/org/infinity/datatype/AreResourceRef.java @@ -47,8 +47,8 @@ public AreResourceRef(ByteBuffer buffer, int offset, String name, AreResource ar } // ResourceEntry entry = ResourceFactory.getInstance().getResourceEntry(getResourceName()); // if (!isLegalEntry(entry)) { -// System.out.println("Illegal: " + entry + " from " + entry.getActualFile()); -// System.out.println("In: " + are.getResourceEntry() + " from " + are.getResourceEntry().getActualFile()); +// Logger.info("Illegal: {} from {}", entry, entry.getActualFile()); +// Logger.info("In: {} from {}", are.getResourceEntry(), are.getResourceEntry().getActualFile()); // } } diff --git a/src/org/infinity/datatype/Bestiary.java b/src/org/infinity/datatype/Bestiary.java index 75fbc89aa..6862a1cbe 100644 --- a/src/org/infinity/datatype/Bestiary.java +++ b/src/org/infinity/datatype/Bestiary.java @@ -67,6 +67,7 @@ import org.infinity.util.IniMapSection; import org.infinity.util.Misc; import org.infinity.util.StringTable; +import org.tinylog.Logger; /** * Datatype for {@link GamResource#GAM_BESTIARY Bestiary} field of the {@link GamResource GAM} resource. @@ -809,18 +810,17 @@ private static List readCreatures() { private static List readCreatures(String filename, IniMap ini) { final IniMapSection init = ini.getSection("init"); if (init == null) { - System.err.println(filename + ": [init] section not found in the file. Creatures not loaded"); + Logger.warn("{}: [init] section not found in the file. Creatures not loaded", filename); return Collections.emptyList(); } final IniMapEntry entry = init.getEntry("beastcount"); if (entry == null) { - System.err.println(filename + ": \"beastcount\" key in [init] section not found. Creatures not loaded"); + Logger.warn("{}: \"beastcount\" key in [init] section not found. Creatures not loaded", filename); return Collections.emptyList(); } final Integer count = entry.getIntValue(); if (count == null) { - System.err.println(filename + ": \"beastcount\" key in [init] section: expected integer buf found " - + entry.getValue() + ". Creatures not loaded"); + Logger.warn("{}: \"beastcount\" key in [init] section: expected integer but found {}. Creatures not loaded.", filename, entry.getValue()); return Collections.emptyList(); } @@ -833,8 +833,7 @@ private static List readCreatures(String filename, IniMap ini) { continue; } if (i < 0 || i >= 256) { - System.err.println( - filename + ": invalid creature number " + i + ", expected number in range [0; 256]. Creature skipped"); + Logger.warn("{}: invalid creature number {}, expected number in range [0; 256]. Creature skipped.", filename, i); continue; } result.ensureCapacity(i); diff --git a/src/org/infinity/datatype/ColorValue.java b/src/org/infinity/datatype/ColorValue.java index 31fdcb377..9b959d96e 100644 --- a/src/org/infinity/datatype/ColorValue.java +++ b/src/org/infinity/datatype/ColorValue.java @@ -61,6 +61,7 @@ import org.infinity.util.Misc; import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; +import org.tinylog.Logger; /** * Field that represents indexed color or color range. @@ -431,7 +432,7 @@ private void initEntries(int defaultWidth, int defaultHeight) { colors.add(range); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/datatype/Datatype.java b/src/org/infinity/datatype/Datatype.java index f37d35e03..20ca9d25a 100644 --- a/src/org/infinity/datatype/Datatype.java +++ b/src/org/infinity/datatype/Datatype.java @@ -19,6 +19,7 @@ import org.infinity.resource.StructEntry; import org.infinity.util.io.ByteBufferOutputStream; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Base class for all types of fields. Supplies base properties for fields: its name (not stored in the file), offset in @@ -152,7 +153,7 @@ public ByteBuffer getDataBuffer() { try (ByteBufferOutputStream bbos = new ByteBufferOutputStream(bb)) { write(bbos); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } bb.position(0); return bb; diff --git a/src/org/infinity/datatype/DecNumber.java b/src/org/infinity/datatype/DecNumber.java index 9bb9d38e9..6265c059f 100644 --- a/src/org/infinity/datatype/DecNumber.java +++ b/src/org/infinity/datatype/DecNumber.java @@ -12,6 +12,7 @@ import java.util.Objects; import org.infinity.resource.AbstractStruct; +import org.tinylog.Logger; /** * Field that represents numerical value which is usually edited in a decimal mode. @@ -52,7 +53,7 @@ public boolean update(Object value) { } return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return false; diff --git a/src/org/infinity/datatype/EffectType.java b/src/org/infinity/datatype/EffectType.java index 89f5e4795..58f3ec652 100644 --- a/src/org/infinity/datatype/EffectType.java +++ b/src/org/infinity/datatype/EffectType.java @@ -12,6 +12,7 @@ import org.infinity.resource.AbstractStruct; import org.infinity.resource.StructEntry; import org.infinity.resource.effects.BaseOpcode; +import org.tinylog.Logger; public final class EffectType extends Bitmap implements UpdateListener { // EffectType-specific field labels @@ -42,7 +43,7 @@ public boolean updateValue(AbstractStruct struct) { struct.addFields(this, list); return true; } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return false; } @@ -56,7 +57,7 @@ public boolean valueUpdated(UpdateEvent event) { try { return BaseOpcode.updateOpcode(event.getStructure()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return false; } @@ -80,7 +81,7 @@ public int readAttributes(ByteBuffer buffer, int off, List list) { try { off = BaseOpcode.makeEffectStruct(getValue(), this, buffer, off, list, isV1); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } attrLength = off - attrLength; return off; diff --git a/src/org/infinity/datatype/FloatNumber.java b/src/org/infinity/datatype/FloatNumber.java index 0514391c4..ad9d674bb 100644 --- a/src/org/infinity/datatype/FloatNumber.java +++ b/src/org/infinity/datatype/FloatNumber.java @@ -12,6 +12,7 @@ import org.infinity.resource.AbstractStruct; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Field that represents numerical value which is usually edited in a floating point mode. @@ -51,7 +52,7 @@ public boolean update(Object value) { return true; } catch (NumberFormatException e) { - e.printStackTrace(); + Logger.error(e); } return false; } diff --git a/src/org/infinity/datatype/HexNumber.java b/src/org/infinity/datatype/HexNumber.java index 4fa09c440..14097c588 100644 --- a/src/org/infinity/datatype/HexNumber.java +++ b/src/org/infinity/datatype/HexNumber.java @@ -6,6 +6,8 @@ import java.nio.ByteBuffer; +import org.tinylog.Logger; + public class HexNumber extends DecNumber { public HexNumber(ByteBuffer buffer, int offset, int length, String desc) { super(buffer, offset, length, desc); @@ -19,7 +21,7 @@ public boolean update(Object value) { setValue((int) DecNumber.parseNumber(value, getSize(), true, true)); return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return false; } diff --git a/src/org/infinity/datatype/ItemTypeBitmap.java b/src/org/infinity/datatype/ItemTypeBitmap.java index d60efad59..0f46d12e1 100644 --- a/src/org/infinity/datatype/ItemTypeBitmap.java +++ b/src/org/infinity/datatype/ItemTypeBitmap.java @@ -16,6 +16,7 @@ import org.infinity.util.Misc; import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; +import org.tinylog.Logger; /** * Specialized {@link HashBitmap} that uses a mix of hardcoded entries and custom entries from ITEMTYPE.2DA @@ -104,7 +105,7 @@ private static TreeMap buildCategories() { retVal.put((long) idx, catName); } catch (NumberFormatException e) { // skip entry with log message - System.err.printf("%s: Invalid index at row=%d (value=%s)\n", TABLE_NAME, row, idxValue); + Logger.warn("{}: Invalid index at row={} (value={})", TABLE_NAME, row, idxValue); } } } else if (Profile.getEngine() == Profile.Engine.PST) { diff --git a/src/org/infinity/datatype/MultiNumber.java b/src/org/infinity/datatype/MultiNumber.java index 7d6111de9..f1c211414 100644 --- a/src/org/infinity/datatype/MultiNumber.java +++ b/src/org/infinity/datatype/MultiNumber.java @@ -32,6 +32,7 @@ import org.infinity.gui.menu.BrowserMenuBar; import org.infinity.resource.AbstractStruct; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * A Number object consisting of multiple values of a given number of bits. @@ -393,7 +394,7 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { data[VALUE][rowIndex] = Integer.valueOf(newVal); fireTableCellUpdated(rowIndex, columnIndex); } catch (NumberFormatException e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/datatype/ResourceRef.java b/src/org/infinity/datatype/ResourceRef.java index a7d10e2d1..ea8924220 100644 --- a/src/org/infinity/datatype/ResourceRef.java +++ b/src/org/infinity/datatype/ResourceRef.java @@ -46,6 +46,7 @@ import org.infinity.resource.sound.SoundResource; import org.infinity.util.Misc; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Represents reference to another resource in game. This resource can be sound, item, dialog, creature, image. @@ -429,7 +430,7 @@ private void closeResource(Resource resource) { try { ((Closeable) resource).close(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/datatype/StringRef.java b/src/org/infinity/datatype/StringRef.java index 66a25136b..8aef8bab7 100644 --- a/src/org/infinity/datatype/StringRef.java +++ b/src/org/infinity/datatype/StringRef.java @@ -54,6 +54,7 @@ import org.infinity.util.Misc; import org.infinity.util.StringTable; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; /** * A struct field that represents reference to string in a talk table file (dialog.tlk or dialogF.tlk). @@ -474,7 +475,7 @@ private String getStringRef(int strref, StringTable.Format fmt) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } else { // load TOH/TOT directly diff --git a/src/org/infinity/datatype/Summon2daBitmap.java b/src/org/infinity/datatype/Summon2daBitmap.java index a8a35c576..29dc93118 100644 --- a/src/org/infinity/datatype/Summon2daBitmap.java +++ b/src/org/infinity/datatype/Summon2daBitmap.java @@ -11,6 +11,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; +import org.tinylog.Logger; /** Specialized HashBitmap type for parsing {@code SMTABLES.2DA} from IWDEE. */ public class Summon2daBitmap extends HashBitmap { @@ -38,10 +39,10 @@ private static synchronized TreeMap getSummonTable() { String resref = table.get(row, 1).toUpperCase(Locale.ENGLISH) + ".2DA"; SUMMON_MAP.put(id, resref); if (!ResourceFactory.resourceExists(resref)) { - System.err.println("Resource does not exist: " + resref); + Logger.warn("Resource does not exist: {}", resref); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/datatype/UnknownDecimal.java b/src/org/infinity/datatype/UnknownDecimal.java index 21fc2c810..fdbb67878 100644 --- a/src/org/infinity/datatype/UnknownDecimal.java +++ b/src/org/infinity/datatype/UnknownDecimal.java @@ -8,6 +8,7 @@ import java.nio.ByteBuffer; import org.infinity.resource.AbstractStruct; +import org.tinylog.Logger; /** * Field that represents binary data in decimal format in their editor. @@ -50,7 +51,7 @@ public boolean updateValue(AbstractStruct struct) { return true; } } catch (NumberFormatException e) { - e.printStackTrace(); + Logger.error(e); } return false; } diff --git a/src/org/infinity/datatype/UnsignHexNumber.java b/src/org/infinity/datatype/UnsignHexNumber.java index e65494be2..0b99c36ca 100644 --- a/src/org/infinity/datatype/UnsignHexNumber.java +++ b/src/org/infinity/datatype/UnsignHexNumber.java @@ -6,6 +6,8 @@ import java.nio.ByteBuffer; +import org.tinylog.Logger; + public class UnsignHexNumber extends UnsignDecNumber { public UnsignHexNumber(ByteBuffer buffer, int offset, int length, String desc) { super(buffer, offset, length, desc); @@ -19,7 +21,7 @@ public boolean update(Object value) { setValue(UnsignDecNumber.parseNumber(value, getSize(), false, true)); return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return false; } diff --git a/src/org/infinity/gui/BIFFEditor.java b/src/org/infinity/gui/BIFFEditor.java index 4907afd66..4eb909796 100644 --- a/src/org/infinity/gui/BIFFEditor.java +++ b/src/org/infinity/gui/BIFFEditor.java @@ -45,6 +45,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class BIFFEditor implements ActionListener, ListSelectionListener, Runnable { private static boolean firstRun = true; @@ -121,7 +122,7 @@ public void run() { progress.setProgress(2, false); JOptionPane.showMessageDialog(editframe, "Error while extracting files from " + bifentry, "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); blocker.setBlocked(false); return; } @@ -147,7 +148,7 @@ public void run() { } catch (Exception e) { progress.setProgress(3, false); JOptionPane.showMessageDialog(editframe, "Error while saving " + bifentry, "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); blocker.setBlocked(false); return; } @@ -159,7 +160,7 @@ public void run() { try { Files.delete(file); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -182,7 +183,7 @@ public void run() { } catch (IOException e) { progress.setProgress(6, false); JOptionPane.showMessageDialog(editframe, "Error while saving keyfile", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } ResourceFactory.getResourceTreeModel().sort(); blocker.setBlocked(false); diff --git a/src/org/infinity/gui/BcsDropFrame.java b/src/org/infinity/gui/BcsDropFrame.java index 93f1d2bd4..86556d2d0 100644 --- a/src/org/infinity/gui/BcsDropFrame.java +++ b/src/org/infinity/gui/BcsDropFrame.java @@ -63,6 +63,7 @@ import org.infinity.util.Misc; import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; public class BcsDropFrame extends ChildFrame implements ActionListener, ListSelectionListener { private final JButton bOpen = new JButton("Open selected", Icons.ICON_OPEN_16.getIcon()); @@ -242,7 +243,7 @@ private SortedSet compileFile(Path file) { line = br.readLine(); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); return null; } Compiler compiler = new Compiler(source.toString()); @@ -269,7 +270,7 @@ private SortedSet compileFile(Path file) { try (BufferedWriter bw = Files.newBufferedWriter(output)) { bw.write(compiled); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); return null; } } @@ -285,7 +286,7 @@ private boolean decompileFile(Path file) { line = br.readLine(); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); return false; } String filename = file.getFileName().toString(); @@ -302,7 +303,7 @@ private boolean decompileFile(Path file) { bw.write(decompiler.getSource().replaceAll("\r?\n", Misc.LINE_SEPARATOR)); bw.newLine(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return false; } return true; @@ -322,7 +323,7 @@ private void filesDropped(Component component, List files) { files.add(p.toFile()); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } else if (file.getFileName().toString().toUpperCase(Locale.ENGLISH).endsWith(".BAF")) { SortedSet errors = compileFile(file); @@ -352,7 +353,7 @@ private void filesDropped(Component component, List files) { files.add(p.toFile()); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } else if (file.getFileName().toString().toUpperCase(Locale.ENGLISH).endsWith(".BCS") || file.getFileName().toString().toUpperCase(Locale.ENGLISH).endsWith(".BS")) { @@ -407,7 +408,7 @@ public void drop(DropTargetDropEvent event) { event.acceptDrop(DnDConstants.ACTION_COPY); files = (List) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); event.dropComplete(false); return; } diff --git a/src/org/infinity/gui/ChildFrame.java b/src/org/infinity/gui/ChildFrame.java index b2d2ddb85..a797fc3cb 100644 --- a/src/org/infinity/gui/ChildFrame.java +++ b/src/org/infinity/gui/ChildFrame.java @@ -34,6 +34,7 @@ import org.infinity.resource.Viewable; import org.infinity.resource.ViewableContainer; import org.infinity.resource.graphics.BamResource; +import org.tinylog.Logger; public class ChildFrame extends JFrame { private static final List WINDOWS = new ArrayList<>(); @@ -190,7 +191,7 @@ public void actionPerformed(ActionEvent e) { return; } } catch (Exception e2) { - e2.printStackTrace(); + Logger.error(e2); return; } WINDOWS.remove(ChildFrame.this); @@ -338,7 +339,7 @@ private static void closeWindow(ChildFrame frame, WindowEvent event) { } frame.dispose(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/gui/ChooseBIFFrame.java b/src/org/infinity/gui/ChooseBIFFrame.java index ecafd399f..c910fd675 100644 --- a/src/org/infinity/gui/ChooseBIFFrame.java +++ b/src/org/infinity/gui/ChooseBIFFrame.java @@ -29,6 +29,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.key.AbstractBIFFReader; import org.infinity.resource.key.BIFFEntry; +import org.tinylog.Logger; final class ChooseBIFFrame extends ChildFrame implements ActionListener { private final BIFFEditor editor; @@ -211,7 +212,7 @@ public void actionPerformed(ActionEvent event) { close(); editor.makeEditor(entry, file.getType()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/gui/DebugConsole.java b/src/org/infinity/gui/DebugConsole.java index fea613db0..f8aa330fc 100644 --- a/src/org/infinity/gui/DebugConsole.java +++ b/src/org/infinity/gui/DebugConsole.java @@ -28,6 +28,7 @@ import org.infinity.resource.Profile; import org.infinity.util.Misc; import org.infinity.util.io.FileEx; +import org.tinylog.Logger; public class DebugConsole extends ChildFrame implements ActionListener { private final JButton bClearConsole = new JButton("Clear", Icons.ICON_NEW_16.getIcon()); @@ -104,7 +105,7 @@ public void actionPerformed(ActionEvent event) { JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { JOptionPane.showMessageDialog(this, "Error while saving " + output, "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } else if (event.getSource() == cbExtraInfo) { diff --git a/src/org/infinity/gui/FontChooser.java b/src/org/infinity/gui/FontChooser.java index c644a13fd..f497d1d73 100644 --- a/src/org/infinity/gui/FontChooser.java +++ b/src/org/infinity/gui/FontChooser.java @@ -49,6 +49,7 @@ import javax.swing.text.Position; import org.infinity.util.Misc; +import org.tinylog.Logger; //import org.infinity.util.Misc; @@ -61,7 +62,7 @@ * int result = fontChooser.showDialog(parent); * if (result == FontChooser.OK_OPTION) { * Font font = fontChooser.getSelectedFont(); - * System.out.println("Selected Font : " + font); + * Logger.info("Selected Font : {}", font); * } * * @@ -495,7 +496,7 @@ private void update(DocumentEvent event) { Document doc = event.getDocument(); newValue = doc.getText(0, doc.getLength()); } catch (BadLocationException e) { - e.printStackTrace(); + Logger.error(e); } if (newValue.length() > 0) { diff --git a/src/org/infinity/gui/InfinityAmp.java b/src/org/infinity/gui/InfinityAmp.java index 6a627f6ae..b9aaf9311 100644 --- a/src/org/infinity/gui/InfinityAmp.java +++ b/src/org/infinity/gui/InfinityAmp.java @@ -40,6 +40,7 @@ import org.infinity.util.Misc; import org.infinity.util.SimpleListModel; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class InfinityAmp extends ChildFrame implements ActionListener, ListSelectionListener, Runnable, Closeable { @@ -284,7 +285,7 @@ private void playMus(ResourceEntry musEntry) { } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error accessing " + musEntry + '\n' + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/gui/InfinityTextArea.java b/src/org/infinity/gui/InfinityTextArea.java index 30df0a300..6a798c63d 100644 --- a/src/org/infinity/gui/InfinityTextArea.java +++ b/src/org/infinity/gui/InfinityTextArea.java @@ -44,6 +44,7 @@ import org.infinity.resource.text.modes.TLKTokenMaker; import org.infinity.resource.text.modes.WeiDULogTokenMaker; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * Extends {@link RSyntaxTextArea} by NearInfinity-specific features. @@ -402,7 +403,7 @@ public static void applyExtendedSettings(RSyntaxTextArea edit, Language language } catch (NullPointerException e) { // ignore } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/gui/LinkButton.java b/src/org/infinity/gui/LinkButton.java index b2b554e2c..a6028c34e 100644 --- a/src/org/infinity/gui/LinkButton.java +++ b/src/org/infinity/gui/LinkButton.java @@ -22,6 +22,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.key.ResourceEntry; import org.infinity.updater.Utils; +import org.tinylog.Logger; /** * A JLabel-based control which supports either internal game resources or external URLs. @@ -214,7 +215,7 @@ public void actionPerformed(ActionEvent e) { try { Utils.openWebPage(new URL(getUrl())); } catch (Exception ex) { - ex.printStackTrace(); + Logger.error(ex); JOptionPane.showMessageDialog(((LinkButton) e.getSource()).getTopLevelAncestor(), "Error opening link in browser.", "Error", JOptionPane.ERROR_MESSAGE); } diff --git a/src/org/infinity/gui/OpenFileFrame.java b/src/org/infinity/gui/OpenFileFrame.java index d794d8dbf..3d34b91b2 100644 --- a/src/org/infinity/gui/OpenFileFrame.java +++ b/src/org/infinity/gui/OpenFileFrame.java @@ -48,6 +48,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; public final class OpenFileFrame extends ChildFrame implements ActionListener { private static final JFileChooser FC = new JFileChooser("."); @@ -275,7 +276,7 @@ public void drop(DropTargetDropEvent event) { event.acceptDrop(DnDConstants.ACTION_COPY); files = (List) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); event.dropComplete(false); return; } diff --git a/src/org/infinity/gui/PreferencesDialog.java b/src/org/infinity/gui/PreferencesDialog.java index a11c3ddc9..8c024b7c9 100644 --- a/src/org/infinity/gui/PreferencesDialog.java +++ b/src/org/infinity/gui/PreferencesDialog.java @@ -89,6 +89,7 @@ import org.infinity.icon.Icons; import org.infinity.resource.Profile; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * This modal dialog provides access to application-wide options and preferences @@ -1380,7 +1381,7 @@ private void globalFontSizeOnAccept(OptionGroupBox gb) { gb.getOption().setValue(-size); } } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -1431,7 +1432,7 @@ private boolean globalFontSizeOnSelect(OptionGroupBox gb) { return true; } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } return true; @@ -1463,7 +1464,7 @@ private void lookAndFeelClassOnInit(OptionGroupBox gb) { label = ((LookAndFeel) o).getName(); } } catch (Exception e) { -// e.printStackTrace(); +// Logger.error(e); } if (label == null) { @@ -1484,7 +1485,7 @@ private void lookAndFeelClassOnInit(OptionGroupBox gb) { // need to track item index separately in case that a L&F class is not accessible curIdx++; } catch (Exception e) { -// e.printStackTrace(); +// Logger.error(e); } } @@ -1504,7 +1505,7 @@ private void lookAndFeelClassOnAccept(OptionGroupBox gb) { final DataItem item = (DataItem) gb.getItem(gb.getSelectedIndex()); gb.getOption().setValue(item.getData().getClassName()); } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -1557,7 +1558,7 @@ private void textFontOnAccept(OptionGroupBox gb) { } gb.getOption().setValue(Integer.valueOf(index)); } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -1583,7 +1584,7 @@ private boolean textFontOnSelect(OptionGroupBox gb) { } } } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } return true; @@ -1642,7 +1643,7 @@ private void tlkCharsetTypeOnAccept(OptionGroupBox gb) { gb.getOption().setValue(item.getData()); } } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -1704,7 +1705,7 @@ private void gameLanguagesOnAccept(OptionGroupBox gb) { languageDefinitions = OptionsMenuItem.updateGameLanguages(languageDefinitions, Profile.getGame(), langCode); gb.getOption().setValue(languageDefinitions); } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -1768,7 +1769,7 @@ private void uiScaleFactorOnAccept(OptionGroupBox gb) { final DataItem item = (DataItem) gb.getItem(gb.getSelectedIndex()); gb.getOption().setValue(item.getData()); } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -1819,7 +1820,7 @@ private boolean uiScaleFactorOnSelect(OptionGroupBox gb) { return true; } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } return false; } diff --git a/src/org/infinity/gui/ResourceTree.java b/src/org/infinity/gui/ResourceTree.java index 5049c8d32..882774d34 100644 --- a/src/org/infinity/gui/ResourceTree.java +++ b/src/org/infinity/gui/ResourceTree.java @@ -72,6 +72,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class ResourceTree extends JPanel implements TreeSelectionListener, ActionListener { private final JButton bnext = new JButton("Forward", Icons.ICON_FORWARD_16.getIcon()); @@ -302,7 +303,7 @@ public static void renameResource(FileResourceEntry entry) { } catch (IOException e) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error renaming file \"" + filename + "\"!", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return; } // ResourceFactory.getResourceTreeModel().resourceEntryChanged(entry); @@ -323,7 +324,7 @@ public static void deleteResource(ResourceEntry entry) { try { Files.delete(bakFile); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } try { @@ -331,7 +332,7 @@ public static void deleteResource(ResourceEntry entry) { } catch (IOException e) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error deleting file \"" + entry.getResourceName() + "\"!", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } else if (entry instanceof BIFFResourceEntry) { String options[] = { "Delete", "Cancel" }; @@ -346,7 +347,7 @@ public static void deleteResource(ResourceEntry entry) { try { Files.delete(bakFile); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } try { @@ -354,7 +355,7 @@ public static void deleteResource(ResourceEntry entry) { } catch (IOException e) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error deleting file \"" + entry.getResourceName() + "\"!", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } @@ -385,7 +386,7 @@ public static void restoreResource(ResourceEntry entry) { try { Files.delete(tmpFile); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Backup has been restored successfully.", "Restore backup", JOptionPane.INFORMATION_MESSAGE); @@ -401,11 +402,11 @@ public static void restoreResource(ResourceEntry entry) { + String.format("Please manually rename the file \"%s\" into \"%s\", located in \n + \"%s\"", tmpName, curName, path), "Critical Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return; } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } JOptionPane.showMessageDialog(NearInfinity.getInstance(), @@ -420,7 +421,7 @@ public static void restoreResource(ResourceEntry entry) { } catch (IOException e) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error removing file \"" + entry + "\" from override folder!", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } @@ -442,7 +443,7 @@ public static void createZipFile(Path path) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Zip file created.", "Information", JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); wb.setBlocked(false); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error while creating zip file.", "Error", JOptionPane.ERROR_MESSAGE); @@ -727,7 +728,7 @@ public void actionPerformed(ActionEvent event) { new ViewFrame(NearInfinity.getInstance(), res); } } catch (NullPointerException e) { - System.err.println("Does not exist in BIFF: " + node); + Logger.warn("Does not exist in BIFF: {}", node); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Does not exist in BIFF: " + node, "Error", JOptionPane.ERROR_MESSAGE); } diff --git a/src/org/infinity/gui/SortableTable.java b/src/org/infinity/gui/SortableTable.java index b1be0ec35..268626bbb 100644 --- a/src/org/infinity/gui/SortableTable.java +++ b/src/org/infinity/gui/SortableTable.java @@ -36,6 +36,7 @@ import org.infinity.resource.Profile; import org.infinity.util.ArrayUtil; import org.infinity.util.io.FileEx; +import org.tinylog.Logger; public final class SortableTable extends JTable implements MouseListener { private static final String WITH_DELIMITERS = "(?<=%1$s)(?!%1$s)|(? FILTER_INFO_LIST = new ArrayList<>(); @@ -99,7 +101,7 @@ public static BamFilterBase createInstance(ConvertToBam parent, Class convert() { } result.add("Conversion finished successfully."); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); result.add(null); result.add(String.format("Error while exporting BAM files.\n(%s)", e.getMessage())); } @@ -4009,7 +4010,7 @@ private void updateFilteredBamDecoder(int bamVersion, boolean force) throws Exce } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); throw e; } } else if (filter instanceof BamFilterBaseTransform) { @@ -4028,16 +4029,16 @@ private void updateFilteredBamDecoder(int bamVersion, boolean force) throws Exce } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); throw e; } } else if (filter instanceof BamFilterBaseOutput) { // skipping output filter } else { if (filter != null) { - System.err.println(String.format("Skipping unrecognized filter: %s", filter)); + Logger.warn("Skipping unrecognized filter: {}", filter); } else { - System.err.println("Skipping null filter"); + Logger.warn("Skipping null filter"); } } } @@ -5657,7 +5658,7 @@ private boolean saveData(Path outFile, boolean silent) { } retVal = true; } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); if (!silent) { JOptionPane.showMessageDialog(bam, "Error exporting BAM session.", "Error", JOptionPane.ERROR_MESSAGE); } diff --git a/src/org/infinity/gui/converter/ConvertToBmp.java b/src/org/infinity/gui/converter/ConvertToBmp.java index 20a24a3a1..c755768b0 100644 --- a/src/org/infinity/gui/converter/ConvertToBmp.java +++ b/src/org/infinity/gui/converter/ConvertToBmp.java @@ -58,6 +58,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class ConvertToBmp extends ChildFrame implements ActionListener, FocusListener, PropertyChangeListener { private static Path currentPath = Profile.getGameRoot(); @@ -221,7 +222,7 @@ public void propertyChange(PropertyChangeEvent event) { try { sl = workerConvert.get(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } workerConvert = null; @@ -522,7 +523,7 @@ private void inputAddFolder() { } catch (IOException e) { JOptionPane.showMessageDialog(this, "Unable to read files from the specified folder.", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return; } listInputFiles.setSelectedIndex(idx - 1); @@ -768,7 +769,7 @@ private boolean writeBMP(Image srcImage, Path file, boolean hasAlpha) { } return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return false; diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 98c562bcf..03ceaefa1 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -63,6 +63,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class ConvertToMos extends ChildFrame implements ActionListener, PropertyChangeListener, ChangeListener, FocusListener { @@ -241,7 +242,7 @@ public static boolean convertV1(Component parent, BufferedImage img, String mosF try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { os.write(dst); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); result.add(null); result.add("Error writing TIS file to disk."); return false; @@ -386,7 +387,7 @@ public static boolean convertV2(Component parent, BufferedImage img, String mosF try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { os.write(dst); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); result.add(null); result.add("Error writing MOS file to disk."); return false; @@ -496,14 +497,14 @@ private static boolean createPvrzPages(Path path, BufferedImage img, DxtEncoder. try (OutputStream os = StreamUtils.getOutputStream(pvrzFile, true)) { os.write(pvrz); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); result.add(null); result.add(String.format("Error writing PVRZ file \"%s\" to disk.", pvrzFile)); return false; } pvrz = null; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); result.add(null); result.add(String.format("Error while generating PVRZ files:\n%s", e.getMessage())); return false; @@ -614,7 +615,7 @@ public void propertyChange(PropertyChangeEvent event) { try { sl = workerConvert.get(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } workerConvert = null; diff --git a/src/org/infinity/gui/converter/ConvertToPvrz.java b/src/org/infinity/gui/converter/ConvertToPvrz.java index e8bb6210e..26c12a0dd 100644 --- a/src/org/infinity/gui/converter/ConvertToPvrz.java +++ b/src/org/infinity/gui/converter/ConvertToPvrz.java @@ -59,6 +59,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class ConvertToPvrz extends ChildFrame implements ActionListener, PropertyChangeListener { private static String currentDir = Profile.getGameRoot().toString(); @@ -276,7 +277,7 @@ public void propertyChange(PropertyChangeEvent event) { try { sl = workerConvert.get(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } workerConvert = null; @@ -613,7 +614,7 @@ private List convert() { } catch (IOException e) { bb = null; errors++; - e.printStackTrace(); + Logger.error(e); } if (bb != null) { byte[] buffer = bb.array(); @@ -622,7 +623,7 @@ private List convert() { os.write(output); } catch (Exception e) { errors++; - e.printStackTrace(); + Logger.error(e); } } } else if (isGraphics) { @@ -744,7 +745,7 @@ private List convert() { os.write(pvrz); } catch (Exception e) { errors++; - e.printStackTrace(); + Logger.error(e); } // cleaning up diff --git a/src/org/infinity/gui/converter/ConvertToTis.java b/src/org/infinity/gui/converter/ConvertToTis.java index 49f75dd93..5e87f990e 100644 --- a/src/org/infinity/gui/converter/ConvertToTis.java +++ b/src/org/infinity/gui/converter/ConvertToTis.java @@ -65,6 +65,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class ConvertToTis extends ChildFrame implements ActionListener, PropertyChangeListener, ChangeListener, FocusListener, KeyListener { @@ -229,7 +230,7 @@ public static boolean convertV1(Component parent, BufferedImage img, String tisF os.write(dst); } catch (Exception e) { // error handling - e.printStackTrace(); + Logger.error(e); result.add(null); result.add("Error writing TIS file to disk."); return false; @@ -384,7 +385,7 @@ public static boolean convertV2(Component parent, BufferedImage img, String tisF os.write(dst); } catch (Exception e) { // error handling - e.printStackTrace(); + Logger.error(e); result.add(null); result.add("Error writing TIS file to disk."); return false; @@ -538,14 +539,14 @@ public static boolean createPvrzPages(String tisFileName, BufferedImage srcImg, os.write(pvrz); } catch (Exception e) { // critical error - e.printStackTrace(); + Logger.error(e); result.add(null); result.add(String.format("Error writing PVRZ file \"%s\" to disk.", pvrzName)); return false; } pvrz = null; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); result.add(null); result.add(String.format("Error while generating PVRZ files:\n%s", e.getMessage())); return false; @@ -700,7 +701,7 @@ public void propertyChange(PropertyChangeEvent event) { try { sl = workerConvert.get(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } workerConvert = null; diff --git a/src/org/infinity/gui/hexview/ResourceDataProvider.java b/src/org/infinity/gui/hexview/ResourceDataProvider.java index c460c21d9..7b896d1e7 100644 --- a/src/org/infinity/gui/hexview/ResourceDataProvider.java +++ b/src/org/infinity/gui/hexview/ResourceDataProvider.java @@ -9,6 +9,7 @@ import java.util.HashMap; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; import tv.porst.jhexview.DataChangedEvent; import tv.porst.jhexview.IDataChangedListener; @@ -60,7 +61,7 @@ public byte[] getData(long offset, int length) { } return retVal; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return null; @@ -76,7 +77,7 @@ public int getDataLength() { size = (int) resSize; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return size; diff --git a/src/org/infinity/gui/hexview/StructHexViewer.java b/src/org/infinity/gui/hexview/StructHexViewer.java index 30b35911b..3d666887f 100644 --- a/src/org/infinity/gui/hexview/StructHexViewer.java +++ b/src/org/infinity/gui/hexview/StructHexViewer.java @@ -77,6 +77,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; import tv.porst.jhexview.DataChangedEvent; import tv.porst.jhexview.HexViewEvent; @@ -487,7 +488,7 @@ private boolean saveResource(Path outFile) { } catch (IOException e) { JOptionPane.showMessageDialog(this, "Unable to create override folder.", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return false; } } @@ -513,7 +514,7 @@ private boolean saveResource(Path outFile) { Files.move(outPath, bakPath); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } } else { @@ -538,7 +539,7 @@ private boolean saveResource(Path outFile) { } catch (IOException e) { JOptionPane.showMessageDialog(this, "Error while saving " + getStruct().getResourceEntry().toString(), "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return false; } return true; diff --git a/src/org/infinity/gui/hexview/StructuredDataProvider.java b/src/org/infinity/gui/hexview/StructuredDataProvider.java index 15ae9405b..d883ff4f1 100644 --- a/src/org/infinity/gui/hexview/StructuredDataProvider.java +++ b/src/org/infinity/gui/hexview/StructuredDataProvider.java @@ -15,6 +15,7 @@ import org.infinity.resource.AbstractStruct; import org.infinity.resource.StructEntry; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; import tv.porst.jhexview.DataChangedEvent; import tv.porst.jhexview.IDataChangedListener; @@ -97,7 +98,7 @@ public byte[] getData(long offset, int length) { try { entry.write(os); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } curOfs += entry.getSize(); } @@ -106,7 +107,7 @@ public byte[] getData(long offset, int length) { try { System.arraycopy(os.toByteArray(), (int) offset - startOffset, retVal, 0, length); } catch (ArrayIndexOutOfBoundsException e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -193,7 +194,7 @@ public void setData(long offset, byte[] data) { hasChanged = true; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/gui/menu/FileMenu.java b/src/org/infinity/gui/menu/FileMenu.java index 5b7403984..1c530391c 100644 --- a/src/org/infinity/gui/menu/FileMenu.java +++ b/src/org/infinity/gui/menu/FileMenu.java @@ -26,6 +26,7 @@ import org.infinity.resource.key.BIFFResourceEntry; import org.infinity.resource.key.FileResourceEntry; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** * Handles File menu items for the {@link BrowserMenuBar}. @@ -182,7 +183,7 @@ public void actionPerformed(ActionEvent event) { new ViewFrame(NearInfinity.getInstance(), res); } } catch (NullPointerException e) { - System.err.println("Does not exist in BIFF: " + node); + Logger.warn("Does not exist in BIFF: {}", node); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Does not exist in BIFF: " + node, "Error", JOptionPane.ERROR_MESSAGE); } diff --git a/src/org/infinity/gui/menu/GameMenu.java b/src/org/infinity/gui/menu/GameMenu.java index e947437ae..48e24d549 100644 --- a/src/org/infinity/gui/menu/GameMenu.java +++ b/src/org/infinity/gui/menu/GameMenu.java @@ -34,6 +34,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * Handles Game menu items for the {@link BrowserMenuBar}. @@ -316,7 +317,7 @@ public void actionPerformed(ActionEvent event) { try { isEqual = keyFile.equals(Profile.getChitinKey().toAbsolutePath()); } catch (IOError e) { - e.printStackTrace(); + Logger.error(e); } if (!isEqual) { int confirm = JOptionPane.YES_OPTION; diff --git a/src/org/infinity/gui/menu/HelpMenu.java b/src/org/infinity/gui/menu/HelpMenu.java index 548e37f9f..2fb32f6d9 100644 --- a/src/org/infinity/gui/menu/HelpMenu.java +++ b/src/org/infinity/gui/menu/HelpMenu.java @@ -45,6 +45,7 @@ import org.infinity.util.DataString; import org.infinity.util.Misc; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * Handles Help menu items for the {@link BrowserMenuBar}. @@ -65,6 +66,7 @@ public class HelpMenu extends JMenu implements BrowserSubMenu, ActionListener { private final JMenuItem helpApngWriterLicense; private final JMenuItem helpCommonMarkLicense; private final JMenuItem helpFlatLafLicense; + private final JMenuItem helpTinyLogLicense; private final JMenuItem helpOracleLicense; private final JMenuItem helpUpdateSettings; private final JMenuItem helpUpdateCheck; @@ -118,6 +120,9 @@ public HelpMenu(BrowserMenuBar parent) { helpOracleLicense = BrowserMenuBar.makeMenuItem("Oracle License", KeyEvent.VK_O, Icons.ICON_EDIT_16.getIcon(), -1, this); miscLicenses.add(helpOracleLicense); + helpTinyLogLicense = BrowserMenuBar.makeMenuItem("tinylog License", KeyEvent.VK_T, Icons.ICON_EDIT_16.getIcon(), -1, this); + miscLicenses.add(helpTinyLogLicense); + addSeparator(); helpUpdateSettings = BrowserMenuBar.makeMenuItem("Update settings...", KeyEvent.VK_S, null, -1, this); @@ -187,6 +192,8 @@ public void actionPerformed(ActionEvent event) { displayLicense("org/infinity/commonmark.License.txt", "BSD License"); } else if (event.getSource() == helpOracleLicense) { displayLicense("org/infinity/Oracle.License.txt", "BSD License"); + } else if (event.getSource() == helpTinyLogLicense) { + displayLicense("org/infinity/tinylog.License.txt", "Apache License"); } else if (event.getSource() == helpUpdateSettings) { UpdaterSettings.showDialog(NearInfinity.getInstance()); } else if (event.getSource() == helpUpdateCheck) { @@ -204,7 +211,7 @@ public void actionPerformed(ActionEvent event) { info = null; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Check for updates: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); return; @@ -257,6 +264,7 @@ private void displayAbout() { add("JHexView by Sebastian Porst - GNU General Public License."); add("CommonMark-Java (\u00A9) Atlassian Pty. Ltd. - BSD License."); add("FlatLaf (\u00A9) FormDev Software GmbH - Apache License."); + add("tinylog 2 by Martin Winandy - Apache License."); add("APNG Writer by Weoulren - BSD License."); } }; @@ -434,7 +442,7 @@ private void displayLicense(String classPath, String title) { try { tphelp.setPage(ClassLoader.getSystemResource(classPath)); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } JOptionPane.showMessageDialog(NearInfinity.getInstance(), panel, title, JOptionPane.PLAIN_MESSAGE); diff --git a/src/org/infinity/gui/menu/OptionsMenuItem.java b/src/org/infinity/gui/menu/OptionsMenuItem.java index 3636c7079..b7b84ec8a 100644 --- a/src/org/infinity/gui/menu/OptionsMenuItem.java +++ b/src/org/infinity/gui/menu/OptionsMenuItem.java @@ -51,6 +51,7 @@ import org.infinity.util.Misc; import org.infinity.util.StringTable; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * Handles Option menu items for the {@link BrowserMenuBar}. @@ -966,7 +967,7 @@ private void applyChanges(Collection options) { refresh = true; restart = true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } else if (option.equals(AppOption.TEXT_FONT)) { int idx = option.getIntValue(); diff --git a/src/org/infinity/gui/menu/ToolsMenu.java b/src/org/infinity/gui/menu/ToolsMenu.java index 9765632c9..17dda2f39 100644 --- a/src/org/infinity/gui/menu/ToolsMenu.java +++ b/src/org/infinity/gui/menu/ToolsMenu.java @@ -282,7 +282,7 @@ public ToolsMenu(BrowserMenuBar parent) { // } catch (IOException e) { // JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error writing keyfile", "Error", // JOptionPane.ERROR_MESSAGE); -// e.printStackTrace(); +// Logger.error(e); // } // } // } diff --git a/src/org/infinity/icon/Icons.java b/src/org/infinity/icon/Icons.java index 29d952ead..760a6e845 100644 --- a/src/org/infinity/icon/Icons.java +++ b/src/org/infinity/icon/Icons.java @@ -11,6 +11,8 @@ import javax.imageio.ImageIO; import javax.swing.ImageIcon; +import org.tinylog.Logger; + /** * Provides {@code ImageIcon} instances of selected graphics files. */ @@ -137,7 +139,7 @@ public static ImageIcon getIcon(Class cls, String fileName) { retVal = new ImageIcon(image); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -167,7 +169,7 @@ public static Image getImage(Class cls, String fileName) { retVal = ImageIO.read(is); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return retVal; diff --git a/src/org/infinity/resource/AbstractStruct.java b/src/org/infinity/resource/AbstractStruct.java index 920119d94..c23c9cc11 100644 --- a/src/org/infinity/resource/AbstractStruct.java +++ b/src/org/infinity/resource/AbstractStruct.java @@ -44,6 +44,7 @@ import org.infinity.search.ReferenceSearcher; import org.infinity.util.io.ByteBufferOutputStream; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public abstract class AbstractStruct extends AbstractTableModel implements StructEntry, Viewable, Closeable, Referenceable, PropertyChangeListener { @@ -296,7 +297,7 @@ public ByteBuffer getDataBuffer() { try (ByteBufferOutputStream bbos = new ByteBufferOutputStream(bb)) { writeFlatFields(bbos); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } bb.position(0); return bb; @@ -1221,7 +1222,7 @@ private void fixHoles(ByteBuffer buffer) { Unknown hole = new Unknown(buffer, offset, delta, COMMON_UNUSED_BYTES); fields.add(hole); flatList.add(i, hole); - System.out.println("Hole: " + name + " off: " + Integer.toHexString(offset) + "h len: " + delta); + Logger.warn("Hole: {} off: {} h len: {}", name, Integer.toHexString(offset), delta); i++; } // Using max() as shared data regions may confuse the hole detection algorithm @@ -1229,8 +1230,7 @@ private void fixHoles(ByteBuffer buffer) { } if (endoffset < buffer.limit()) { // Does this break anything? fields.add(new Unknown(buffer, endoffset, buffer.limit() - endoffset, COMMON_UNUSED_BYTES)); - System.out.println( - "Hole: " + name + " off: " + Integer.toHexString(endoffset) + "h len: " + (buffer.limit() - endoffset)); + Logger.warn("Hole: {} off: {} h len: {}", name, Integer.toHexString(endoffset), (buffer.limit() - endoffset)); endoffset = buffer.limit(); } } diff --git a/src/org/infinity/resource/Profile.java b/src/org/infinity/resource/Profile.java index 5a427bfd0..d98c45800 100644 --- a/src/org/infinity/resource/Profile.java +++ b/src/org/infinity/resource/Profile.java @@ -50,12 +50,14 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.resource.key.ResourceTreeModel; import org.infinity.util.DataString; +import org.infinity.util.DebugTimer; import org.infinity.util.Platform; import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; import org.infinity.util.io.DlcManager; import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; /** * Provides engine- and game-specific properties of the currently opened Infinity Engine game.
@@ -640,7 +642,7 @@ public static Game gameFromString(String gameName) { try { return Enum.valueOf(Game.class, gameName); } catch (IllegalArgumentException e) { - System.err.println("Unknown game type \"" + gameName + "\" specified. Falling back to \"Unknown\"."); + Logger.warn("Unknown game type \"{}\" specified. Falling back to \"Unknown\".", gameName); } } return Game.Unknown; @@ -678,10 +680,12 @@ public static boolean openGame(Path keyFile, String desc) { public static boolean openGame(Path keyFile, String desc, Game forcedGame) { try { closeGame(); + final DebugTimer timer = new DebugTimer(); instance = new Profile(keyFile, desc, forcedGame); + Logger.info(timer.getTimerFormatted("Initializing game resources")); return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } closeGame(); return false; @@ -1709,7 +1713,7 @@ private static String getLuaValue(Path file, String key, String defaultValue, bo } } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; @@ -2572,11 +2576,11 @@ private List initDlc(Path rootDir, Path homeDir) { list.add(dlcRoot); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } // DLCs of the same root are sorted alphabetically (in reverse order) if (!list.isEmpty()) { diff --git a/src/org/infinity/resource/ResourceFactory.java b/src/org/infinity/resource/ResourceFactory.java index ba86db2d3..6c9f31fc8 100644 --- a/src/org/infinity/resource/ResourceFactory.java +++ b/src/org/infinity/resource/ResourceFactory.java @@ -93,6 +93,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Handles game-specific resource access. @@ -259,8 +260,7 @@ public static Resource getResource(ResourceEntry entry, String forcedExtension) final String msg = String.format("Error reading %s @ %s - %s", entry, entry.getActualPath(), e); NearInfinity.getInstance().getStatusBar().setMessage(msg); } - System.err.println("Error reading " + entry); - e.printStackTrace(); + Logger.error(e, "Error reading {}", entry); } return res; } @@ -314,7 +314,7 @@ public static ResourceEntry getResourceIcon(ResourceEntry entry, String forcedEx // forward exception to caller throw e; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -418,7 +418,7 @@ public static Class detectResourceType(ResourceEntry entry) throw new Exception(entry.getResourceName() + ": Unable to determine resource type"); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return cls; @@ -429,7 +429,7 @@ public static void exportResource(ResourceEntry entry, Component parent) { try { getInstance().exportResourceInternal(entry, parent, null); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(parent, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } @@ -440,7 +440,7 @@ public static void exportResource(ResourceEntry entry, ByteBuffer buffer, String try { getInstance().exportResourceInternal(entry, buffer, filename, parent, null); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(parent, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } @@ -766,7 +766,7 @@ public static List getAvailableGameLanguages() { .isFile()))) { dstream.forEach(path -> list.add(path)); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -802,7 +802,7 @@ public static String autodetectGameLanguage(Path iniFile) { } } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error parsing " + iniFile.getFileName() + ". Using language defaults.", "Error", JOptionPane.ERROR_MESSAGE); @@ -838,7 +838,7 @@ static Path getHomeRoot(boolean allowMissing) { userPrefix = splitted[splitted.length - 1]; userPath = FileManager.resolve(userPrefix, EE_DIR); } catch (Throwable t) { - t.printStackTrace(); + Logger.error(t); return null; } } else if (osName.contains("mac") || osName.contains("darwin")) { @@ -908,7 +908,7 @@ static List getBIFFDirs() { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); dirList.clear(); } } @@ -999,7 +999,7 @@ private ResourceFactory(Path keyFile) { loadResourcesInternal(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "No Infinity Engine game found", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } @@ -1523,7 +1523,7 @@ private void saveCopyOfResourceInternal(ResourceEntry entry) { } catch (IOException e) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Could not create " + outPath + ".", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return; } } @@ -1547,7 +1547,7 @@ private void saveCopyOfResourceInternal(ResourceEntry entry) { } catch (Exception e) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error while copying " + entry, "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } @@ -1586,7 +1586,7 @@ private boolean saveResourceInternal(Resource resource, Component parent, Path o } catch (IOException e) { JOptionPane.showMessageDialog(parent, "Unable to create override folder.", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return false; } } @@ -1603,7 +1603,7 @@ private boolean saveResourceInternal(Resource resource, Component parent, Path o } catch (IOException e) { JOptionPane.showMessageDialog(parent, "Unable to create folder: " + outPath.getParent(), "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return false; } } @@ -1626,7 +1626,7 @@ private boolean saveResourceInternal(Resource resource, Component parent, Path o Files.move(outPath, bakPath); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } } else { @@ -1638,7 +1638,7 @@ private boolean saveResourceInternal(Resource resource, Component parent, Path o ((Writeable) resource).write(os); } catch (IOException e) { JOptionPane.showMessageDialog(parent, "Error while saving " + entry, "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return false; } diff --git a/src/org/infinity/resource/StructureFactory.java b/src/org/infinity/resource/StructureFactory.java index 104ecc815..c6fe5f876 100644 --- a/src/org/infinity/resource/StructureFactory.java +++ b/src/org/infinity/resource/StructureFactory.java @@ -25,6 +25,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; // Create different pre-initialized IE game resources from scratch and writes them to disk. public final class StructureFactory { @@ -142,7 +143,7 @@ public void newResource(ResType type, Window parent) { } catch (Exception e) { JOptionPane.showMessageDialog(parent, "Error while creating " + outFile.getFileName(), title, JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/are/AreResource.java b/src/org/infinity/resource/are/AreResource.java index 88144b85a..2296e3aeb 100644 --- a/src/org/infinity/resource/are/AreResource.java +++ b/src/org/infinity/resource/are/AreResource.java @@ -55,6 +55,7 @@ import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * The ARE resource describes the content of an area (rather than its visual representation). ARE files contain the list @@ -212,7 +213,7 @@ private static void initMapNames(boolean force) { LuaEntry entries = LuaParser.Parse(luaFiles, "cheatAreas\\w*", false); mapNames = createMapNamesFromLua(entries); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } else if (ResourceFactory.resourceExists("MAPNAME.2DA")) { // PST map names diff --git a/src/org/infinity/resource/are/viewer/AreaViewer.java b/src/org/infinity/resource/are/viewer/AreaViewer.java index c868b2d9c..56c3d4683 100644 --- a/src/org/infinity/resource/are/viewer/AreaViewer.java +++ b/src/org/infinity/resource/are/viewer/AreaViewer.java @@ -117,6 +117,7 @@ import org.infinity.resource.wed.WedResource; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * The Area Viewer shows a selected map with its associated structures, such as actors, regions or animations. @@ -238,7 +239,7 @@ protected Void doInBackground() throws Exception { try { init(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -695,7 +696,7 @@ private void init() { try { initGuiSettings(); } catch (OutOfMemoryError e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(this, "Not enough memory to load area!", "Error", JOptionPane.ERROR_MESSAGE); throw e; } @@ -2229,7 +2230,7 @@ private void exportMap() { bRet = ImageIO.write(dstImage, "png", os); dstImage.flush(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { releaseProgressMonitor(); WindowBlocker.blockWindow(AreaViewer.this, false); @@ -2402,7 +2403,7 @@ public void actionPerformed(ActionEvent event) { try { setZoomFactor(Settings.ITEM_ZOOM_FACTOR[cbZoomLevel.getSelectedIndex()], previousZoomFactor); } catch (OutOfMemoryError e) { - e.printStackTrace(); + Logger.error(e); cbZoomLevel.hidePopup(); WindowBlocker.blockWindow(AreaViewer.this, false); String msg = "Not enough memory to set selected zoom level.\n" @@ -2554,7 +2555,7 @@ public void mouseWheelMoved(MouseWheelEvent event) { try { setZoomFactor(zoom, previousZoomFactor); } catch (OutOfMemoryError e) { - e.printStackTrace(); + Logger.error(e); cbZoomLevel.hidePopup(); WindowBlocker.blockWindow(AreaViewer.this, false); String msg = "Not enough memory to set selected zoom level.\n" @@ -2918,7 +2919,7 @@ public void reloadWed(int dayNight) { wedItem[dayNight].setVisible(false); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } else { wed[dayNight] = wed[ViewerConstants.AREA_DAY]; @@ -2931,7 +2932,7 @@ public void reloadWed(int dayNight) { try { wed[dayNight] = new WedResource(ResourceFactory.getResourceEntry(wedNameNight)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/are/viewer/LayerActor.java b/src/org/infinity/resource/are/viewer/LayerActor.java index 7146e8a45..c7d93a862 100644 --- a/src/org/infinity/resource/are/viewer/LayerActor.java +++ b/src/org/infinity/resource/are/viewer/LayerActor.java @@ -33,6 +33,7 @@ import org.infinity.util.IniMapCache; import org.infinity.util.IniMapEntry; import org.infinity.util.IniMapSection; +import org.tinylog.Logger; /** * Manages actor layer objects. @@ -83,7 +84,7 @@ protected void loadLayer() { setListeners(obj); objectList.add(obj); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -121,7 +122,7 @@ protected void loadLayer() { setListeners(loa); objectList.add(loa); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -191,7 +192,7 @@ public Void doInBackground() { progress.setProgress(i + 1); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { progress.close(); if (blocker != null) { diff --git a/src/org/infinity/resource/are/viewer/LayerAutomap.java b/src/org/infinity/resource/are/viewer/LayerAutomap.java index 606883668..e23273812 100644 --- a/src/org/infinity/resource/are/viewer/LayerAutomap.java +++ b/src/org/infinity/resource/are/viewer/LayerAutomap.java @@ -17,6 +17,7 @@ import org.infinity.util.IniMap; import org.infinity.util.IniMapCache; import org.infinity.util.IniMapSection; +import org.tinylog.Logger; /** * Manages automap notes layer objects (both PST-specific and generic types). @@ -106,7 +107,7 @@ private void loadPredefinedAutoNotes(AreResource are) { objectList.add(obj); } } catch (IllegalArgumentException e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/are/viewer/LayerDoor.java b/src/org/infinity/resource/are/viewer/LayerDoor.java index 76785fd05..9438c82f0 100644 --- a/src/org/infinity/resource/are/viewer/LayerDoor.java +++ b/src/org/infinity/resource/are/viewer/LayerDoor.java @@ -10,6 +10,7 @@ import org.infinity.gui.layeritem.AbstractLayerItem; import org.infinity.resource.are.AreResource; import org.infinity.resource.are.Door; +import org.tinylog.Logger; /** * Manages door layer objects. @@ -61,7 +62,7 @@ public void setLayerVisible(boolean visible) { break; default: item.setVisible(false); - System.out.println("Unknown layer id: " + item.getId()); + Logger.info("Unknown layer id: {}", item.getId()); } } }); diff --git a/src/org/infinity/resource/are/viewer/LayerManager.java b/src/org/infinity/resource/are/viewer/LayerManager.java index b2a0dbf86..61daa5141 100644 --- a/src/org/infinity/resource/are/viewer/LayerManager.java +++ b/src/org/infinity/resource/are/viewer/LayerManager.java @@ -10,6 +10,7 @@ import org.infinity.resource.are.AreResource; import org.infinity.resource.are.viewer.ViewerConstants.LayerType; import org.infinity.resource.wed.WedResource; +import org.tinylog.Logger; /** * Manages all layer objects of a single ARE map. @@ -601,7 +602,7 @@ private void init(AreResource are, WedResource wed, boolean forced) { loadLayer(layer, forced || wedChanged); break; default: - System.err.println(String.format("Unsupported layer type: %s", layer.toString())); + Logger.warn("Unsupported layer type: {}", layer); } } } @@ -753,7 +754,7 @@ private int loadLayer(LayerType layer, boolean forced) { break; } default: - System.err.println(String.format("Unsupported layer type: %s", layer.toString())); + Logger.warn("Unsupported layer type: {}", layer); } } return retVal; diff --git a/src/org/infinity/resource/are/viewer/LayerObjectAmbient.java b/src/org/infinity/resource/are/viewer/LayerObjectAmbient.java index 8bd53c5a2..9ee9593b1 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectAmbient.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectAmbient.java @@ -22,6 +22,7 @@ import org.infinity.resource.are.Ambient; import org.infinity.resource.are.AreResource; import org.infinity.resource.are.viewer.icon.ViewerIcons; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Ambient Sound and Ambient Sound Range @@ -71,7 +72,7 @@ public LayerObjectAmbient(AreResource parent, Ambient ambient) { msg = ambient.getAttribute(Ambient.ARE_AMBIENT_NAME).toString(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } // Using cached icons diff --git a/src/org/infinity/resource/are/viewer/LayerObjectAnimation.java b/src/org/infinity/resource/are/viewer/LayerObjectAnimation.java index b53ec5252..e03589112 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectAnimation.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectAnimation.java @@ -28,6 +28,7 @@ import org.infinity.resource.key.FileResourceEntry; import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Background Animation @@ -169,7 +170,7 @@ public LayerObjectAnimation(AreResource parent, Animation anim) { animation.setStartFrame(skippedFrames); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } // Using cached icons @@ -306,7 +307,7 @@ private static int[] getExternalPalette(ResourceRef bmpRef) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return new int[0]; diff --git a/src/org/infinity/resource/are/viewer/LayerObjectAreActor.java b/src/org/infinity/resource/are/viewer/LayerObjectAreActor.java index da664290b..f041fc785 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectAreActor.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectAreActor.java @@ -23,6 +23,7 @@ import org.infinity.resource.are.viewer.icon.ViewerIcons; import org.infinity.resource.cre.CreResource; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Actor @@ -79,7 +80,7 @@ public LayerObjectAreActor(AreResource parent, Actor actor) { ea = ((IsNumeric) cre.getAttribute(CreResource.CRE_ALLEGIANCE)).getValue(); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } this.cre = cre; @@ -142,7 +143,7 @@ public synchronized void loadAnimation() { item.setAnimation(sprite); item.setComposite(Settings.UseActorAccurateBlending ? sprite.getDecoder().getComposite() : null); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/are/viewer/LayerObjectAutomap.java b/src/org/infinity/resource/are/viewer/LayerObjectAutomap.java index e17606e29..39d3b5f17 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectAutomap.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectAutomap.java @@ -18,6 +18,7 @@ import org.infinity.resource.key.FileResourceEntry; import org.infinity.resource.to.TohResource; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Automap Note (except for PST) @@ -60,7 +61,7 @@ public LayerObjectAutomap(AreResource parent, AutomapNote note) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } // Using cached icons diff --git a/src/org/infinity/resource/are/viewer/LayerObjectAutomapPST.java b/src/org/infinity/resource/are/viewer/LayerObjectAutomapPST.java index a5531def8..533a1ff4e 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectAutomapPST.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectAutomapPST.java @@ -14,6 +14,7 @@ import org.infinity.resource.are.AreResource; import org.infinity.resource.are.AutomapNotePST; import org.infinity.resource.are.viewer.icon.ViewerIcons; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Automap Note (PST-specific, user-defined) @@ -42,7 +43,7 @@ public LayerObjectAutomapPST(AreResource parent, AutomapNotePST note) { location.y = (int) (y.getValue() * MAP_SCALE); msg = note.getAttribute(AutomapNotePST.ARE_AUTOMAP_TEXT).toString(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } // Using cached icons diff --git a/src/org/infinity/resource/are/viewer/LayerObjectContainer.java b/src/org/infinity/resource/are/viewer/LayerObjectContainer.java index 1bb11059c..8710bc055 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectContainer.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectContainer.java @@ -21,6 +21,7 @@ import org.infinity.resource.are.Container; import org.infinity.resource.are.viewer.icon.ViewerIcons; import org.infinity.resource.vertex.Vertex; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Container @@ -73,7 +74,7 @@ public LayerObjectContainer(AreResource parent, Container container) { launchPoint.x = ((IsNumeric) container.getAttribute(Container.ARE_CONTAINER_LAUNCH_POINT_X)).getValue(); launchPoint.y = ((IsNumeric) container.getAttribute(Container.ARE_CONTAINER_LAUNCH_POINT_Y)).getValue(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } final Polygon poly = createPolygon(shapeCoords, 1.0); final Rectangle bounds = normalizePolygon(poly); diff --git a/src/org/infinity/resource/are/viewer/LayerObjectDoor.java b/src/org/infinity/resource/are/viewer/LayerObjectDoor.java index aaee4035c..a5be11750 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectDoor.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectDoor.java @@ -27,6 +27,7 @@ import org.infinity.resource.are.viewer.icon.ViewerIcons; import org.infinity.resource.vertex.ClosedVertex; import org.infinity.resource.vertex.OpenVertex; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Door @@ -88,7 +89,7 @@ public LayerObjectDoor(AreResource parent, Door door) { launchPoint.x = ((IsNumeric) door.getAttribute(Door.ARE_DOOR_LAUNCH_POINT_X)).getValue(); launchPoint.y = ((IsNumeric) door.getAttribute(Door.ARE_DOOR_LAUNCH_POINT_Y)).getValue(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } for (final DoorInfo info: getDoors()) { diff --git a/src/org/infinity/resource/are/viewer/LayerObjectDoorCells.java b/src/org/infinity/resource/are/viewer/LayerObjectDoorCells.java index a94971112..48bd8c746 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectDoorCells.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectDoorCells.java @@ -23,6 +23,7 @@ import org.infinity.resource.are.Door; import org.infinity.resource.vertex.ClosedVertexImpeded; import org.infinity.resource.vertex.OpenVertexImpeded; +import org.tinylog.Logger; /** * Handles specific layer subtype: ARE/Door blocked cells @@ -63,7 +64,7 @@ public LayerObjectDoorCells(AreResource parent, Door door) { itemCoords = createCellPolygons(loadVertices(door, cOfs, 0, cNum, ClosedVertexImpeded.class)); doorClosed.setCoords(itemCoords); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } for (final DoorInfo info: getDoors()) { diff --git a/src/org/infinity/resource/are/viewer/LayerObjectDoorPoly.java b/src/org/infinity/resource/are/viewer/LayerObjectDoorPoly.java index b5430e23c..835f76900 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectDoorPoly.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectDoorPoly.java @@ -23,6 +23,7 @@ import org.infinity.resource.vertex.Vertex; import org.infinity.resource.wed.Door; import org.infinity.resource.wed.WedResource; +import org.tinylog.Logger; /** * Handles specific layer type: WED/Door Polygon. @@ -63,7 +64,7 @@ public LayerObjectDoorPoly(WedResource parent, Door doorPoly) { // processing closed door polygons fillData(ofsClosed, numClosed, numOpen, info); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); if (info == null) { info = new String[count]; } diff --git a/src/org/infinity/resource/are/viewer/LayerObjectEntrance.java b/src/org/infinity/resource/are/viewer/LayerObjectEntrance.java index 23cbee50a..f4b15f787 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectEntrance.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectEntrance.java @@ -15,6 +15,7 @@ import org.infinity.resource.are.AreResource; import org.infinity.resource.are.Entrance; import org.infinity.resource.are.viewer.icon.ViewerIcons; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Entrance @@ -46,7 +47,7 @@ public LayerObjectEntrance(AreResource parent, Entrance entrance) { final String name = entrance.getAttribute(Entrance.ARE_ENTRANCE_NAME).toString(); msg = String.format("%s (%s)", name, AbstractStruct.OPTION_ORIENTATION[o]); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } // Using cached icons diff --git a/src/org/infinity/resource/are/viewer/LayerObjectGlobalActor.java b/src/org/infinity/resource/are/viewer/LayerObjectGlobalActor.java index 5175c1d19..4dd924458 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectGlobalActor.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectGlobalActor.java @@ -23,6 +23,7 @@ import org.infinity.resource.gam.GamResource; import org.infinity.resource.gam.PartyNPC; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** * Handles specific layer type: global GAM/Actor @@ -119,7 +120,7 @@ public void loadAnimation() { item.setAnimation(sprite); item.setComposite(Settings.UseActorAccurateBlending ? sprite.getDecoder().getComposite() : null); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/are/viewer/LayerObjectIniActor.java b/src/org/infinity/resource/are/viewer/LayerObjectIniActor.java index 2b0a6d639..175ec0628 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectIniActor.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectIniActor.java @@ -21,6 +21,7 @@ import org.infinity.resource.text.PlainTextResource; import org.infinity.util.IniMapEntry; import org.infinity.util.IniMapSection; +import org.tinylog.Logger; /** * Handles specific layer type: INI/Actor @@ -71,7 +72,7 @@ public LayerObjectIniActor(PlainTextResource ini, IniMapSection creData, int cre try { cre = new CreResource(creEntry); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); throw new IllegalArgumentException(creData.getName() + ": Invalid CRE resource", e); } @@ -179,7 +180,7 @@ public synchronized void loadAnimation() { item.setAnimation(sprite); item.setComposite(Settings.UseActorAccurateBlending ? sprite.getDecoder().getComposite() : null); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/are/viewer/LayerObjectProTrap.java b/src/org/infinity/resource/are/viewer/LayerObjectProTrap.java index 721e7b88d..a1cfc3d21 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectProTrap.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectProTrap.java @@ -14,6 +14,7 @@ import org.infinity.resource.are.AreResource; import org.infinity.resource.are.ProTrap; import org.infinity.resource.are.viewer.icon.ViewerIcons; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Projectile Trap @@ -49,7 +50,7 @@ public LayerObjectProTrap(AreResource parent, ProTrap trap) { msg += " (friendly)"; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } // Using cached icons diff --git a/src/org/infinity/resource/are/viewer/LayerObjectRegion.java b/src/org/infinity/resource/are/viewer/LayerObjectRegion.java index 64ad68065..34a2d3b29 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectRegion.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectRegion.java @@ -24,6 +24,7 @@ import org.infinity.resource.are.ITEPoint; import org.infinity.resource.are.viewer.icon.ViewerIcons; import org.infinity.resource.vertex.Vertex; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Region @@ -112,7 +113,7 @@ ITEPoint.TYPE_ARRAY[type], getAttributes(), } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } final Polygon poly = createPolygon(shapeCoords, 1.0); final Rectangle bounds = normalizePolygon(poly); diff --git a/src/org/infinity/resource/are/viewer/LayerObjectSpawnPoint.java b/src/org/infinity/resource/are/viewer/LayerObjectSpawnPoint.java index da58e3381..01ff372a5 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectSpawnPoint.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectSpawnPoint.java @@ -15,6 +15,7 @@ import org.infinity.resource.are.AreResource; import org.infinity.resource.are.SpawnPoint; import org.infinity.resource.are.viewer.icon.ViewerIcons; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Spawn Point @@ -43,7 +44,7 @@ public LayerObjectSpawnPoint(AreResource parent, SpawnPoint sp) { scheduleFlags = ((Flag) sp.getAttribute(SpawnPoint.ARE_SPAWN_ACTIVE_AT)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } // Using cached icons diff --git a/src/org/infinity/resource/are/viewer/LayerObjectTransition.java b/src/org/infinity/resource/are/viewer/LayerObjectTransition.java index 6d63f86c0..aa22406bc 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectTransition.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectTransition.java @@ -13,6 +13,7 @@ import org.infinity.gui.layeritem.ShapedLayerItem; import org.infinity.resource.Viewable; import org.infinity.resource.are.AreResource; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Map transition @@ -46,7 +47,7 @@ public LayerObjectTransition(AreResource parent, AreResource destination, int ed msg = String.format("Transition to %s", ref); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } item = new ShapedLayerItem(destination, msg, null); diff --git a/src/org/infinity/resource/are/viewer/LayerObjectWallPoly.java b/src/org/infinity/resource/are/viewer/LayerObjectWallPoly.java index 148569a1d..bcb552a46 100644 --- a/src/org/infinity/resource/are/viewer/LayerObjectWallPoly.java +++ b/src/org/infinity/resource/are/viewer/LayerObjectWallPoly.java @@ -17,6 +17,7 @@ import org.infinity.resource.vertex.Vertex; import org.infinity.resource.wed.WallPolygon; import org.infinity.resource.wed.WedResource; +import org.tinylog.Logger; /** * Handles specific layer type: ARE/Wall Polygon @@ -45,7 +46,7 @@ public LayerObjectWallPoly(WedResource parent, WallPolygon wall) { int startIdx = flags.isFlagSet(2) ? 2 : 0; // skipping first two vertices for "hovering walls" shapeCoords = loadVertices(wall, vOfs, startIdx, vNum - startIdx, Vertex.class); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } final Polygon poly = createPolygon(shapeCoords, 1.0); final Rectangle bounds = normalizePolygon(poly); diff --git a/src/org/infinity/resource/are/viewer/LayerTransition.java b/src/org/infinity/resource/are/viewer/LayerTransition.java index a7c580d94..301967190 100644 --- a/src/org/infinity/resource/are/viewer/LayerTransition.java +++ b/src/org/infinity/resource/are/viewer/LayerTransition.java @@ -9,6 +9,7 @@ import org.infinity.datatype.ResourceRef; import org.infinity.resource.ResourceFactory; import org.infinity.resource.are.AreResource; +import org.tinylog.Logger; /** * Manages map transition layer objects. @@ -33,7 +34,7 @@ protected void loadLayer() { setListeners(obj); list.add(obj); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/are/viewer/Settings.java b/src/org/infinity/resource/are/viewer/Settings.java index 1a1686108..d88629132 100644 --- a/src/org/infinity/resource/are/viewer/Settings.java +++ b/src/org/infinity/resource/are/viewer/Settings.java @@ -12,6 +12,7 @@ import org.infinity.resource.are.viewer.ViewerConstants.LayerStackingType; import org.infinity.resource.are.viewer.ViewerConstants.LayerType; +import org.tinylog.Logger; /** * Manages global area viewer settings. @@ -307,7 +308,7 @@ public static void storeSettings(boolean force) { try { prefs.flush(); } catch (BackingStoreException e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/resource/are/viewer/TilesetRenderer.java b/src/org/infinity/resource/are/viewer/TilesetRenderer.java index 001a19e79..596ad1ded 100644 --- a/src/org/infinity/resource/are/viewer/TilesetRenderer.java +++ b/src/org/infinity/resource/are/viewer/TilesetRenderer.java @@ -31,6 +31,7 @@ import org.infinity.resource.wed.Overlay; import org.infinity.resource.wed.Tilemap; import org.infinity.resource.wed.WedResource; +import org.tinylog.Logger; /** * Specialized renderer for drawing tileset-based graphics data. @@ -761,11 +762,11 @@ private boolean hasOverlay(int ovlIdx) { // Draws a grid on the map with the specified parameters private void drawGrid(Graphics g, double gridWidth, double gridHeight, Color color) { if (g == null) { - System.err.println("TilesetRenderer.drawGrid: Graphics argument is null"); + Logger.warn("TilesetRenderer.drawGrid: Graphics argument is null"); return; } if (color == null) { - System.err.println("TilesetRenderer.drawGrid: Color argument is null"); + Logger.warn("TilesetRenderer.drawGrid: Color argument is null"); return; } final double gridWidthZoomed = gridWidth * zoomFactor; @@ -965,7 +966,7 @@ private synchronized void drawTile(Tile tile, boolean isDoorTile) { if (tileIdx < listTilesets.get(0).listTileData.size()) { srcSec = listTilesets.get(0).listTileData.get(tileIdx); } else { - System.err.println("Invalid tile index: " + tileIdx + " of " + listTilesets.get(0).listTileData.size()); + Logger.warn("Invalid tile index: {} of {}", tileIdx, listTilesets.get(0).listTileData.size()); } } @@ -1156,7 +1157,7 @@ private void init(WedResource wed, Overlay ovl) { decoder.close(); decoder = null; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return; } } diff --git a/src/org/infinity/resource/bcs/BafResource.java b/src/org/infinity/resource/bcs/BafResource.java index a11c32527..400f2ccd3 100644 --- a/src/org/infinity/resource/bcs/BafResource.java +++ b/src/org/infinity/resource/bcs/BafResource.java @@ -57,6 +57,7 @@ import org.infinity.util.Misc; import org.infinity.util.StaticSimpleXorDecryptor; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class BafResource implements TextResource, Writeable, Closeable, ItemListener, ActionListener, DocumentListener { // for source panel @@ -416,7 +417,7 @@ private void compile() { bpmUses.setMenuItems(usesItems); bpmUses.setEnabled(usesItems.length > 0); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -429,7 +430,7 @@ private void decompile() { try { sourceText.setText(decompiler.getSource()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } sourceText.setCaretPosition(0); Set uses = decompiler.getResourcesUsed(); @@ -501,7 +502,7 @@ public String getDescription() { } catch (IOException e) { JOptionPane.showMessageDialog(panel, "Error saving " + chooser.getSelectedFile().toString(), "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/bcs/BcsResource.java b/src/org/infinity/resource/bcs/BcsResource.java index 2d39ef827..fd96f19f0 100644 --- a/src/org/infinity/resource/bcs/BcsResource.java +++ b/src/org/infinity/resource/bcs/BcsResource.java @@ -62,6 +62,7 @@ import org.infinity.util.Misc; import org.infinity.util.StaticSimpleXorDecryptor; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * This resource represent scripted actions. {@code .bcs} files are scripts attached to anything other than the player @@ -487,7 +488,7 @@ public String getDescription() { } catch (IOException e) { JOptionPane.showMessageDialog(panel, "Error exporting " + chooser.getSelectedFile().toString(), "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } else if (bpmExport.getSelectedItem() == iExportScript) { @@ -529,7 +530,7 @@ public String getText() { try { return decompiler.getSource(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return "// Error: " + e.getMessage(); } } @@ -739,7 +740,7 @@ private void decompile() { try { sourceText.setText(decompiler.getSource()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); sourceText.setText("/*\nError: " + e.getMessage() + "\n*/"); } sourceText.setCaretPosition(0); diff --git a/src/org/infinity/resource/cre/CreResource.java b/src/org/infinity/resource/cre/CreResource.java index 44d47239a..97c6530c7 100644 --- a/src/org/infinity/resource/cre/CreResource.java +++ b/src/org/infinity/resource/cre/CreResource.java @@ -79,6 +79,7 @@ import org.infinity.util.StringTable; import org.infinity.util.Table2da; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * This resource describes a "creature". Creatures have several stats (some visible through the game UI) which are @@ -617,7 +618,7 @@ public static void convertCHRtoCRE(ResourceEntry resourceEntry) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "File saved to " + path, "Conversion complete", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Errors during conversion", "Error", JOptionPane.ERROR_MESSAGE); } @@ -627,7 +628,7 @@ public static void convertCHRtoCRE(ResourceEntry resourceEntry) { private static void convertToSemiStandard(CreResource crefile) { final List fields = crefile.getFields(); if (!fields.get(1).toString().equals("V1.0")) { - System.err.println("Conversion to semi-standard aborted: Unsupported CRE version"); + Logger.warn("Conversion to semi-standard aborted: Unsupported CRE version"); return; } @@ -2135,7 +2136,7 @@ private boolean convertEffects(int version, SectionOffset so, SectionCount sc) { addDatatype(newEff); retVal |= true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } else if (version == 1 && so.getSection().equals(Effect.class)) { @@ -2165,7 +2166,7 @@ private boolean convertEffects(int version, SectionOffset so, SectionCount sc) { addDatatype(newEff); retVal |= true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/resource/cre/ViewerAnimation.java b/src/org/infinity/resource/cre/ViewerAnimation.java index b08e438f8..21cda12a6 100644 --- a/src/org/infinity/resource/cre/ViewerAnimation.java +++ b/src/org/infinity/resource/cre/ViewerAnimation.java @@ -47,6 +47,7 @@ import org.infinity.resource.cre.decoder.util.Sequence; import org.infinity.resource.cre.decoder.util.SpriteUtils; import org.infinity.resource.graphics.ColorConvert; +import org.tinylog.Logger; /** * A basic creature animation viewer. @@ -247,7 +248,7 @@ public void open() { WindowBlocker.blockWindow(true); initAnimation(); } catch (Exception ex) { - ex.printStackTrace(); + Logger.error(ex); WindowBlocker.blockWindow(false); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Creature animation could not be loaded.\nError message: " + ex.getMessage(), "Error", @@ -286,7 +287,7 @@ public void actionPerformed(ActionEvent event) { setAnimationSequence(seq); updateControls(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); cbSequences.setSelectedItem(getAnimationSequence()); } finally { @@ -315,7 +316,7 @@ public void actionPerformed(ActionEvent event) { getDecoder().setBoundingBoxVisible(showOverlayBorders); resetAnimationSequence(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { WindowBlocker.blockWindow(false); } diff --git a/src/org/infinity/resource/cre/browser/CreUtils.java b/src/org/infinity/resource/cre/browser/CreUtils.java index 24cb50d41..1c9c11388 100644 --- a/src/org/infinity/resource/cre/browser/CreUtils.java +++ b/src/org/infinity/resource/cre/browser/CreUtils.java @@ -25,6 +25,7 @@ import org.infinity.resource.cre.decoder.util.ItemInfo; import org.infinity.resource.key.ResourceEntry; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * Collection of methods for creating and manipulating CRE resources. @@ -132,7 +133,7 @@ public static ItemInfo getEquipmentHelmet(CreResource cre) { retVal = ItemInfo.getValidated(itemEntry); retVal.overrideDroppableFlag(((Flag) item.getAttribute(Item.CRE_ITEM_FLAGS)).isFlagSet(3)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -172,7 +173,7 @@ public static ItemInfo getEquipmentArmor(CreResource cre) { retVal = ItemInfo.getValidated(itemEntry); retVal.overrideDroppableFlag(((Flag) item.getAttribute(Item.CRE_ITEM_FLAGS)).isFlagSet(3)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -220,7 +221,7 @@ public static ItemInfo getEquipmentShield(CreResource cre) { retVal = ItemInfo.getValidated(itemEntry); retVal.overrideDroppableFlag(((Flag) item.getAttribute(Item.CRE_ITEM_FLAGS)).isFlagSet(3)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -266,7 +267,7 @@ public static ItemInfo getEquipmentWeapon(CreResource cre) { retVal = ItemInfo.getValidated(itemEntry); retVal.overrideDroppableFlag(((Flag) item.getAttribute(Item.CRE_ITEM_FLAGS)).isFlagSet(3)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -383,7 +384,7 @@ private static void addEquippedItem(CreResource cre, ItemInfo item, String slotN cre.addDatatype(newItem); setFieldValue(cre.getAttribute(slotName), null, numItems); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -528,7 +529,7 @@ private static int setFieldValue(Readable field, ByteBuffer buf, int value) { try { retVal = field.read(buf, pos); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; @@ -556,7 +557,7 @@ private static int setFieldValue(Readable field, ByteBuffer buf, String value, i try { retVal = field.read(buf, pos); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; diff --git a/src/org/infinity/resource/cre/browser/CreatureBrowser.java b/src/org/infinity/resource/cre/browser/CreatureBrowser.java index b68ac1dbc..d836a7304 100644 --- a/src/org/infinity/resource/cre/browser/CreatureBrowser.java +++ b/src/org/infinity/resource/cre/browser/CreatureBrowser.java @@ -27,6 +27,7 @@ import org.infinity.resource.cre.CreResource; import org.infinity.resource.cre.decoder.SpriteDecoder; import org.infinity.resource.cre.decoder.util.SpriteUtils; +import org.tinylog.Logger; /** * The Creature Browser implements a highly customizable browser and viewer for creature animations. @@ -199,7 +200,7 @@ private Object taskSetCreResource() throws Exception { /** A generic catch-all operation that can be used to evaluate exceptions thrown in a background task. */ private void postTaskDefault(Object o, Exception e) { if (e != null) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(this, "Error: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } @@ -236,7 +237,7 @@ protected TaskInfo doInBackground() throws Exception { if (retVal.postAction != null) { retVal.exception = e; } else { - e.printStackTrace(); + Logger.error(e); } } finally { if (blocker != null) { diff --git a/src/org/infinity/resource/cre/browser/CreatureControlModel.java b/src/org/infinity/resource/cre/browser/CreatureControlModel.java index e2efa5fe1..2e971edf8 100644 --- a/src/org/infinity/resource/cre/browser/CreatureControlModel.java +++ b/src/org/infinity/resource/cre/browser/CreatureControlModel.java @@ -20,6 +20,7 @@ import org.infinity.resource.cre.decoder.util.ItemInfo; import org.infinity.resource.cre.decoder.util.ItemInfo.ItemPredicate; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** * This model controls the relationships between creature controls and provides access to the various creature-specific @@ -480,7 +481,7 @@ public void reset() { try { creSelectionChanged(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/resource/cre/browser/CreatureControlPanel.java b/src/org/infinity/resource/cre/browser/CreatureControlPanel.java index 08b452383..5f2eec4ed 100644 --- a/src/org/infinity/resource/cre/browser/CreatureControlPanel.java +++ b/src/org/infinity/resource/cre/browser/CreatureControlPanel.java @@ -44,6 +44,7 @@ import org.infinity.util.IdsMapCache; import org.infinity.util.IdsMapEntry; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * This panel provides controls for customizing various aspects of a CRE resource. @@ -145,7 +146,7 @@ public void applySettings() { try { getControlModel().resetDecoder(cre); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); getBrowser().showErrorMessage(e.getMessage(), "Loading creature"); } @@ -506,7 +507,7 @@ public void actionPerformed(ActionEvent e) { getControlModel().creSelectionChanged(); updateToolTip(cbCreSelection); } catch (Exception ex) { - ex.printStackTrace(); + Logger.error(ex); getBrowser().showErrorMessage(ex.getMessage(), "Creature selection"); } } else if (e.getSource() == cbCreAnimation) { diff --git a/src/org/infinity/resource/cre/browser/CreatureSelectionModel.java b/src/org/infinity/resource/cre/browser/CreatureSelectionModel.java index 16ed74a93..83ab844b6 100644 --- a/src/org/infinity/resource/cre/browser/CreatureSelectionModel.java +++ b/src/org/infinity/resource/cre/browser/CreatureSelectionModel.java @@ -25,6 +25,7 @@ import org.infinity.util.ResourceStructure; import org.infinity.util.io.StreamUtils; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * {@code ComboBoxModel} for the creature selection combo box used in the Creature Animation Browser. @@ -261,7 +262,7 @@ private static ResourceEntry createCreature() { retVal = new BufferedResourceEntry(buf, "*.CRE"); } catch (StructureException e) { - e.printStackTrace(); + Logger.error(e); } return retVal; diff --git a/src/org/infinity/resource/cre/browser/MediaPanel.java b/src/org/infinity/resource/cre/browser/MediaPanel.java index bad015b1d..c42dd0224 100644 --- a/src/org/infinity/resource/cre/browser/MediaPanel.java +++ b/src/org/infinity/resource/cre/browser/MediaPanel.java @@ -54,6 +54,7 @@ import org.infinity.resource.cre.decoder.util.Sequence; import org.infinity.resource.graphics.ColorConvert; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; import ork.sevenstates.apng.APNGSeqWriter; @@ -321,7 +322,7 @@ public void loadSequence(Sequence seq) throws IllegalArgumentException { throw new Exception(); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); throw new IllegalArgumentException("Could not load animation sequence"); } @@ -819,7 +820,7 @@ private void exportBamSequence() { JOptionPane.showMessageDialog(browser, message, "Export animation sequence", JOptionPane.INFORMATION_MESSAGE); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(browser, "Unable to export animation sequence.", "Error", JOptionPane.ERROR_MESSAGE); } } @@ -893,7 +894,7 @@ public void itemStateChanged(ItemEvent e) { WindowBlocker.blockWindow(getBrowser(), true); loadSequence(seq); } catch (Exception ex) { - ex.printStackTrace(); + Logger.error(ex); getBrowser().showErrorMessage(ex.getMessage(), "Sequence selection"); } finally { WindowBlocker.blockWindow(getBrowser(), false); diff --git a/src/org/infinity/resource/cre/browser/bg/Backgrounds.java b/src/org/infinity/resource/cre/browser/bg/Backgrounds.java index 7f663fdcc..705d06587 100644 --- a/src/org/infinity/resource/cre/browser/bg/Backgrounds.java +++ b/src/org/infinity/resource/cre/browser/bg/Backgrounds.java @@ -15,6 +15,7 @@ import javax.swing.UIManager; import org.infinity.resource.Profile; +import org.tinylog.Logger; /** * Backgrounds for the creature animation browser. @@ -80,7 +81,7 @@ public static Image getImage(Class c, String fileName) { URL url = getValidURL(c, fileName); retVal = ImageIO.read(url); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; } diff --git a/src/org/infinity/resource/cre/decoder/PlaceholderDecoder.java b/src/org/infinity/resource/cre/decoder/PlaceholderDecoder.java index 89d53e599..37b0c56e4 100644 --- a/src/org/infinity/resource/cre/decoder/PlaceholderDecoder.java +++ b/src/org/infinity/resource/cre/decoder/PlaceholderDecoder.java @@ -24,6 +24,7 @@ import org.infinity.util.IniMapEntry; import org.infinity.util.IniMapSection; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * General-purpose creature animation decoder for handling non-existing or unknown animation types. @@ -50,7 +51,7 @@ private static ResourceEntry loadPlaceholderBam() { baos.flush(); retVal = new BufferedResourceEntry(StreamUtils.getByteBuffer(baos.toByteArray()), "placeholder.bam"); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return retVal; } diff --git a/src/org/infinity/resource/cre/decoder/SpriteDecoder.java b/src/org/infinity/resource/cre/decoder/SpriteDecoder.java index 0a93a0bc0..83801270d 100644 --- a/src/org/infinity/resource/cre/decoder/SpriteDecoder.java +++ b/src/org/infinity/resource/cre/decoder/SpriteDecoder.java @@ -60,6 +60,7 @@ import org.infinity.util.IniMapSection; import org.infinity.util.Misc; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * Specialized BAM decoder for creature animation sprites. @@ -295,7 +296,7 @@ public T getAttribute(DecoderAttribute att) { try { retVal = (T) data; } catch (ClassCastException e) { - // e.printStackTrace(); + // Logger.error(e); } } return retVal; @@ -392,7 +393,7 @@ public boolean loadSequence(Sequence seq, Direction[] directions) throws Excepti } catch (NullPointerException e) { retVal = (seq != Sequence.NONE); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); retVal = (seq != Sequence.NONE); } } @@ -841,7 +842,7 @@ public void applyAnimationChanges() { try { reset(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -1490,7 +1491,7 @@ protected int[] getColorData(int colorIndex, boolean allowRandom) { try { retVal = SpriteUtils.getColorGradient(colorIndex, allowRandom); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; } diff --git a/src/org/infinity/resource/cre/decoder/tables/InfinityTables.java b/src/org/infinity/resource/cre/decoder/tables/InfinityTables.java index 5adcfa3c4..94e68f8d6 100644 --- a/src/org/infinity/resource/cre/decoder/tables/InfinityTables.java +++ b/src/org/infinity/resource/cre/decoder/tables/InfinityTables.java @@ -21,6 +21,7 @@ import org.infinity.util.IdsMapEntry; import org.infinity.util.IniMap; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * A static class dedicated to processing Infinity Animation slots. @@ -57,7 +58,7 @@ public static List createIniMaps(int animationId) { IdsMap table = new IdsMap(entry); retVal.addAll(processTable(table, animationId)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -95,9 +96,9 @@ private static List processTable(IdsMap idsMap, int animationId) { } } catch (InvocationTargetException ite) { if (ite.getCause() != null) { - ite.getCause().printStackTrace(); + Logger.error(ite.getCause()); } else { - ite.printStackTrace(); + Logger.error(ite); } } catch (Exception e) { return retVal; diff --git a/src/org/infinity/resource/cre/decoder/tables/SpriteTables.java b/src/org/infinity/resource/cre/decoder/tables/SpriteTables.java index f0a7b896b..50063f7bb 100644 --- a/src/org/infinity/resource/cre/decoder/tables/SpriteTables.java +++ b/src/org/infinity/resource/cre/decoder/tables/SpriteTables.java @@ -22,6 +22,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.IniMap; import org.infinity.util.Table2da; +import org.tinylog.Logger; /** * A static class that provides information and methods for hardcoded creature animations. @@ -206,12 +207,12 @@ private static List processTable(Table2da table, int animationId) { } } catch (InvocationTargetException ite) { if (ite.getCause() != null) { - ite.getCause().printStackTrace(); + Logger.error(ite.getCause()); } else { - ite.printStackTrace(); + Logger.error(ite); } } catch (NoSuchMethodException | IllegalAccessException e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/resource/cre/decoder/util/CreatureInfo.java b/src/org/infinity/resource/cre/decoder/util/CreatureInfo.java index 373a99c09..789c4cee6 100644 --- a/src/org/infinity/resource/cre/decoder/util/CreatureInfo.java +++ b/src/org/infinity/resource/cre/decoder/util/CreatureInfo.java @@ -33,6 +33,7 @@ import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * Provides useful information about a creature resource and their equipment. @@ -893,7 +894,7 @@ private void initEquipmentItem(ItemSlots slot, int itemIndex, List itemInfo.overrideDroppableFlag(isUndroppable); equipment.put(slot, itemInfo); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/cre/decoder/util/EffectInfo.java b/src/org/infinity/resource/cre/decoder/util/EffectInfo.java index 93a5507ab..a8081fa79 100644 --- a/src/org/infinity/resource/cre/decoder/util/EffectInfo.java +++ b/src/org/infinity/resource/cre/decoder/util/EffectInfo.java @@ -28,6 +28,7 @@ import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Manages effects opcodes for a specific target. @@ -462,7 +463,7 @@ private void resolveSPL(List list, Effect parent, ResourceEntry entry) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -476,7 +477,7 @@ private void resolveEFF(List list, Effect parent, ResourceEntry entry) { final List retList = resolveEffect(parent, Effect.fromEffectV2(entry.getResourceBuffer(), 8)); list.addAll(retList); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/resource/cre/decoder/util/ItemInfo.java b/src/org/infinity/resource/cre/decoder/util/ItemInfo.java index 21639de04..f504728f0 100644 --- a/src/org/infinity/resource/cre/decoder/util/ItemInfo.java +++ b/src/org/infinity/resource/cre/decoder/util/ItemInfo.java @@ -24,6 +24,7 @@ import org.infinity.util.Misc; import org.infinity.util.StringTable; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Provides useful information about equippable items. @@ -480,7 +481,7 @@ public static int getItemCategory(ResourceEntry itmEntry) { Misc.requireCondition(is.skip(0x14) == 0x14, "Could not advance in data stream"); return StreamUtils.readShort(is); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return -1; diff --git a/src/org/infinity/resource/cre/decoder/util/SpriteUtils.java b/src/org/infinity/resource/cre/decoder/util/SpriteUtils.java index 6d41a2181..5a26d3dae 100644 --- a/src/org/infinity/resource/cre/decoder/util/SpriteUtils.java +++ b/src/org/infinity/resource/cre/decoder/util/SpriteUtils.java @@ -65,6 +65,7 @@ import org.infinity.util.Table2daCache; import org.infinity.util.io.StreamUtils; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * Collection of helpful methods for Sprite rendering. @@ -448,7 +449,7 @@ public static Couple loadBamDecoderCont retVal = Couple.with(decoder, control); BAM_CACHE.put(entry, retVal); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; @@ -616,7 +617,7 @@ public static int[] loadReplacementPalette(String resref, int index) { PALETTE_CACHE.put(entry, retVal); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -711,7 +712,7 @@ public static int[] getColorGradient(int index, boolean allowRandom) { COLOR_GRADIENTS.put(y, pixels); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } else { // dummy entry to skip continuous gradient initialization attempts if gradient bitmap isn't available @@ -1279,7 +1280,7 @@ private static List guessIniMaps(int animationId) { break; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/dlg/AbstractCode.java b/src/org/infinity/resource/dlg/AbstractCode.java index a32620809..3dbf8d5fd 100644 --- a/src/org/infinity/resource/dlg/AbstractCode.java +++ b/src/org/infinity/resource/dlg/AbstractCode.java @@ -47,6 +47,7 @@ import org.infinity.resource.bcs.ScriptType; import org.infinity.util.Misc; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public abstract class AbstractCode extends Datatype implements Editable, IsTextual, AddRemovable, ActionListener, DocumentListener, ItemListener { @@ -325,7 +326,7 @@ public void addFlatList(List flatList) { ts.setOffset(off.getValue()); flatList.add(ts); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/resource/dlg/DlgResource.java b/src/org/infinity/resource/dlg/DlgResource.java index 2c497e1cf..0d0fe5dc2 100644 --- a/src/org/infinity/resource/dlg/DlgResource.java +++ b/src/org/infinity/resource/dlg/DlgResource.java @@ -50,6 +50,7 @@ import org.infinity.updater.Utils; import org.infinity.util.StringTable; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * DLG resource contains the structure of conversation, in what is effectievly a state machine. Dialogs contains string @@ -222,7 +223,7 @@ public void actionPerformed(ActionEvent e) { throw new Exception(); } } catch (Exception ex) { - ex.printStackTrace(); + Logger.error(ex); JOptionPane.showMessageDialog(getViewer().getTopLevelAncestor(), "Could not export resource into WeiDU dialog format.", "Error", JOptionPane.ERROR_MESSAGE); return; diff --git a/src/org/infinity/resource/dlg/DlgTreeModel.java b/src/org/infinity/resource/dlg/DlgTreeModel.java index b2a1c2d78..fb95f28e6 100644 --- a/src/org/infinity/resource/dlg/DlgTreeModel.java +++ b/src/org/infinity/resource/dlg/DlgTreeModel.java @@ -35,6 +35,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.StructEntry; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** Creates and manages the dialog tree structure. */ final class DlgTreeModel implements TreeModel, TreeNode, TableModelListener, PropertyChangeListener { @@ -905,7 +906,7 @@ private DlgResource getDialogResource(ResourceRef dlgRef) { try { return new DlgResource(ResourceFactory.getResourceEntry(name)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; }); diff --git a/src/org/infinity/resource/dlg/TreeWorker.java b/src/org/infinity/resource/dlg/TreeWorker.java index da9495add..c6d6e0fed 100644 --- a/src/org/infinity/resource/dlg/TreeWorker.java +++ b/src/org/infinity/resource/dlg/TreeWorker.java @@ -13,6 +13,8 @@ import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import org.tinylog.Logger; + //-------------------------- INNER CLASSES -------------------------- /** Applies expand or collapse operations on a set of dialog tree nodes in a background task. */ @@ -49,7 +51,7 @@ protected Void doInBackground() throws Exception { collapseNode(path); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -88,7 +90,7 @@ private void expandNode(final TreePath path) { try { SwingUtilities.invokeAndWait(() -> dlgTree.expandPath(path)); } catch (InterruptedException | InvocationTargetException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -126,7 +128,7 @@ private void collapseNode(final TreePath path) { try { SwingUtilities.invokeAndWait(() -> dlgTree.collapsePath(path)); } catch (InterruptedException | InvocationTargetException e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/dlg/Viewer.java b/src/org/infinity/resource/dlg/Viewer.java index 737da8dbd..a4a7efee0 100644 --- a/src/org/infinity/resource/dlg/Viewer.java +++ b/src/org/infinity/resource/dlg/Viewer.java @@ -53,6 +53,7 @@ import org.infinity.search.DialogSearcher; import org.infinity.util.Misc; import org.infinity.util.StringTable; +import org.tinylog.Logger; final class Viewer extends JPanel implements ActionListener, ItemListener, TableModelListener { private static final ButtonPanel.Control CTRL_NEXT_STATE = ButtonPanel.Control.CUSTOM_1; @@ -406,7 +407,7 @@ public void select(StructEntry entry) { showState(stateNrToShow); showTransition(transNrToShow); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -448,7 +449,7 @@ private void showState(int nr) { if (!isValid) { if (nr >= 0) { // Print warning about not correct resource - System.err.println(dlg.getName() + ": state " + nr + " is not exist"); + Logger.warn("{}: state {} does not exist", dlg.getName(), nr); } stateTextPanel.clearDisplay(); stateTriggerPanel.clearDisplay(); @@ -500,10 +501,9 @@ private void showTransition(int nr) { if (nr >= 0 && currentState != null) { // Print warning about not correct resource if (isValid) { - System.err.println( - dlg.getName() + ": transition " + nr + " is not transition from state " + currentState.getNumber()); + Logger.warn("{}: transition {} is not transition from state {}", dlg.getName(), nr, currentState.getNumber()); } else if (isBroken) { - System.err.println(dlg.getName() + ": transition " + nr + " is not exist"); + Logger.warn("{}: transition {} does not exist", dlg.getName(), nr); } } transTextPanel.clearDisplay(); diff --git a/src/org/infinity/resource/effects/BaseOpcode.java b/src/org/infinity/resource/effects/BaseOpcode.java index 28de51e10..c9bce48c1 100644 --- a/src/org/infinity/resource/effects/BaseOpcode.java +++ b/src/org/infinity/resource/effects/BaseOpcode.java @@ -36,6 +36,7 @@ import org.infinity.util.Table2daCache; import org.infinity.util.io.ByteBufferOutputStream; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Base class for opcode-handling classes. Derived classes should handle one opcode per class for all game variants. @@ -650,12 +651,12 @@ public static synchronized String[] getPortraitIconNames(String defaultName) { portraitIconNames[index] = StringTable.getStringRef(strref); } } catch (NumberFormatException nfe) { - nfe.printStackTrace(); + Logger.error(nfe); } } } } catch (NullPointerException npe) { - npe.printStackTrace(); + Logger.error(npe); } } @@ -888,7 +889,7 @@ public static ByteBuffer getEntryData(StructEntry entry) try (ByteBufferOutputStream bbos = new ByteBufferOutputStream(bb)) { entry.write(bbos); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); return null; } return bb; @@ -913,7 +914,7 @@ public static ByteBuffer getEntryData(AbstractStruct struct, EffectEntry id) } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return null; @@ -1026,7 +1027,7 @@ private static synchronized TreeMap getOpcodeMap() { } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/gam/GamResource.java b/src/org/infinity/resource/gam/GamResource.java index dbf54c734..6c5dc5037 100644 --- a/src/org/infinity/resource/gam/GamResource.java +++ b/src/org/infinity/resource/gam/GamResource.java @@ -45,6 +45,7 @@ import org.infinity.resource.text.QuestsPanel; import org.infinity.resource.text.QuestsResource; import org.infinity.util.Variables; +import org.tinylog.Logger; /** * This resource is used to hold game information in save games. The GAM file does not store {@link AreResource area}, @@ -192,7 +193,7 @@ public JComponent getViewerTab(int index) { try { return new QuestsPanel(new QuestsResource().readQuests(), globalVars); } catch (Exception ex) { - ex.printStackTrace(); + Logger.error(ex); final StringWriter w = new StringWriter(); ex.printStackTrace(new PrintWriter(w)); return new JTextArea(w.toString()); diff --git a/src/org/infinity/resource/graphics/BamDecoder.java b/src/org/infinity/resource/graphics/BamDecoder.java index b7efbbd95..ea60b2ce4 100644 --- a/src/org/infinity/resource/graphics/BamDecoder.java +++ b/src/org/infinity/resource/graphics/BamDecoder.java @@ -17,6 +17,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Common base class for handling BAM resources. @@ -60,7 +61,7 @@ public static Type getType(ResourceEntry bamEntry) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; diff --git a/src/org/infinity/resource/graphics/BamResource.java b/src/org/infinity/resource/graphics/BamResource.java index 7c1be00d9..ced009edf 100644 --- a/src/org/infinity/resource/graphics/BamResource.java +++ b/src/org/infinity/resource/graphics/BamResource.java @@ -80,6 +80,7 @@ import org.infinity.util.IntegerHashMap; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; import tv.porst.jhexview.DataChangedEvent; import tv.porst.jhexview.IDataChangedListener; @@ -155,7 +156,7 @@ public BamResource(ResourceEntry entry) { ((BamV1Decoder.BamV1Control) bamControl).setTransparencyEnabled(transparencyEnabled); } } catch (Throwable t) { - t.printStackTrace(); + Logger.error(t); decoder = null; } WindowBlocker.blockWindow(false); @@ -274,7 +275,7 @@ public void actionPerformed(ActionEvent event) { ByteBuffer buffer = Compressor.decompress(entry.getResourceBuffer()); ResourceFactory.exportResource(entry, buffer, entry.getResourceName(), panelMain.getTopLevelAncestor()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -293,7 +294,7 @@ public void actionPerformed(ActionEvent event) { ByteBuffer buffer = Compressor.compress(entry.getResourceBuffer(), "BAMC", "V1 "); ResourceFactory.exportResource(entry, buffer, entry.getResourceName(), panelMain.getTopLevelAncestor()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -357,7 +358,7 @@ public void propertyChange(PropertyChangeEvent event) { l = null; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } if (bamData != null) { if (bamData.length > 0) { @@ -398,7 +399,7 @@ public void stateChanged(ChangeEvent event) { hexViewer.setCurrentOffset(0L); panelRaw.add(hexViewer, BorderLayout.CENTER); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { WindowBlocker.blockWindow(false); } @@ -846,13 +847,13 @@ public static String exportFrames(BamDecoder decoder, Path filePath, String file counter++; } catch (IOException e) { failCounter++; - System.err.println("Error writing frame #" + i); + Logger.warn("Error writing frame #{}", i); } image.flush(); image = null; } else { failCounter++; - System.err.println("Skipping frame #" + i); + Logger.warn("Skipping frame #{}", i); } } } @@ -1236,7 +1237,7 @@ public List doInBackground() { list.add(buf); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return list; } @@ -1286,7 +1287,7 @@ public boolean containsPvrzReference(int index) { retVal = (curIndex == index); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; diff --git a/src/org/infinity/resource/graphics/BamV1Decoder.java b/src/org/infinity/resource/graphics/BamV1Decoder.java index 8a544d7ab..925cd71ae 100644 --- a/src/org/infinity/resource/graphics/BamV1Decoder.java +++ b/src/org/infinity/resource/graphics/BamV1Decoder.java @@ -19,6 +19,7 @@ import org.infinity.resource.Profile; import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Handles BAM v1 resources (both BAMC and uncompressed BAM V1). @@ -223,7 +224,7 @@ private void init() { defaultControl.setMode(BamControl.Mode.SHARED); defaultControl.setSharedPerCycle(false); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); close(); } } @@ -308,9 +309,8 @@ private void decodeFrame(BamControl control, int frameIdx, Image canvas) { dstOfs += dstWidth - srcWidth; } } catch (Exception e) { - System.err.printf("Error [%s]: input (offset=%d, size=%d), output (offset=%d, size=%d)\n", - e.getClass().getName(), srcOfs, bamBuffer.limit(), dstOfs, - bufferB != null ? bufferB.length : bufferI.length); + Logger.error("Error [{}]: input (offset={}, size={}), output (offset={}, size={})", + e.getClass().getName(), srcOfs, bamBuffer.limit(), dstOfs, bufferB != null ? bufferB.length : bufferI.length); } bufferB = null; bufferI = null; diff --git a/src/org/infinity/resource/graphics/BamV2Decoder.java b/src/org/infinity/resource/graphics/BamV2Decoder.java index 459e6d9fe..95ed96639 100644 --- a/src/org/infinity/resource/graphics/BamV2Decoder.java +++ b/src/org/infinity/resource/graphics/BamV2Decoder.java @@ -26,6 +26,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Handles BAM v2 resources. @@ -220,7 +221,7 @@ private void init() { defaultControl.setMode(BamControl.Mode.SHARED); defaultControl.setSharedPerCycle(false); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); close(); } } @@ -247,7 +248,7 @@ private PvrDecoder getPVR(int page) { return PvrDecoder.loadPvr(entry); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -466,7 +467,7 @@ private void decodeImage(ByteBuffer buffer, int ofsBlocks, int start, int count) decoder = null; srcImage = null; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/graphics/ColorConvert.java b/src/org/infinity/resource/graphics/ColorConvert.java index 14d3673a6..4afeddf60 100644 --- a/src/org/infinity/resource/graphics/ColorConvert.java +++ b/src/org/infinity/resource/graphics/ColorConvert.java @@ -41,6 +41,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.StreamUtils; import org.infinity.util.tuples.Triple; +import org.tinylog.Logger; /** * Contains a set of color-related static methods (little endian order only). @@ -806,7 +807,7 @@ public static int[] loadPaletteBMP(ResourceEntry entry) throws Exception { throw new Exception("Invalid BMP resource: " + entry.getResourceName()); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); throw new Exception("Unable to read BMP resource: " + entry.getResourceName()); } } else { @@ -840,7 +841,7 @@ public static int[] loadPalettePNG(Path file, boolean preserveAlpha) throws Exce throw new Exception("Error loading palette from PNG file " + file.getFileName()); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); throw new Exception("Unable to read PNG file " + file.getFileName()); } } else { @@ -893,7 +894,7 @@ public static int[] loadPalettePAL(Path file) throws Exception { throw new Exception("Invalid Windows palette file " + file.getFileName()); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); throw new Exception("Unable to read Windows palette file " + file.getFileName()); } } else { @@ -935,7 +936,7 @@ public static int[] loadPaletteACT(Path file) throws Exception { throw new Exception("Invalid Adobe Photoshop palette file " + file.getFileName()); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); throw new Exception("Unable to read Adobe Photoshop palette file " + file.getFileName()); } } else { @@ -987,7 +988,7 @@ public static int[] loadPaletteBAM(ResourceEntry entry, boolean preserveAlpha) t throw new Exception("Unsupport file type."); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); throw new Exception("Unable to read BAM resource: " + entry.getResourceName()); } } else { diff --git a/src/org/infinity/resource/graphics/MosDecoder.java b/src/org/infinity/resource/graphics/MosDecoder.java index c3094e41f..00b1be05f 100644 --- a/src/org/infinity/resource/graphics/MosDecoder.java +++ b/src/org/infinity/resource/graphics/MosDecoder.java @@ -10,6 +10,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Common base class for handling MOS resources. @@ -53,7 +54,7 @@ public static Type getType(ResourceEntry mosEntry) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; diff --git a/src/org/infinity/resource/graphics/MosResource.java b/src/org/infinity/resource/graphics/MosResource.java index 017c6c2ea..507aa0045 100644 --- a/src/org/infinity/resource/graphics/MosResource.java +++ b/src/org/infinity/resource/graphics/MosResource.java @@ -61,6 +61,7 @@ import org.infinity.util.DynamicArray; import org.infinity.util.IntegerHashMap; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * This resource describes static graphics in a tile based bitmap format. Such files are used for mini-maps and GUI @@ -137,7 +138,7 @@ public void actionPerformed(ActionEvent event) { buffer = Compressor.decompress(buffer); ResourceFactory.exportResource(entry, buffer, entry.getResourceName(), panel.getTopLevelAncestor()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), "Error while exporting " + entry, "Error", JOptionPane.ERROR_MESSAGE); } @@ -156,7 +157,7 @@ public void actionPerformed(ActionEvent event) { buffer = Compressor.compress(buffer, "MOSC", "V1 "); ResourceFactory.exportResource(entry, buffer, entry.getResourceName(), panel.getTopLevelAncestor()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), "Error while exporting " + entry, "Error", JOptionPane.ERROR_MESSAGE); } @@ -181,7 +182,7 @@ public void actionPerformed(ActionEvent event) { JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } else if (event.getSource() == miPvrzShow) { if (lastBlockIndex >= 0) { @@ -223,7 +224,7 @@ public void propertyChange(PropertyChangeEvent event) { l = null; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } if (mosData != null) { if (mosData.length > 0) { @@ -439,7 +440,7 @@ private void showProperties() { sb.append(""); JOptionPane.showMessageDialog(panel, sb.toString(), "Properties of " + resName, JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { if (decoder != null) { decoder.close(); @@ -497,7 +498,7 @@ private BufferedImage loadImage() { decoder = MosDecoder.loadMos(entry); mosType = decoder.getType(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -654,7 +655,7 @@ public List doInBackground() { list.add(buf); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return list; } @@ -704,7 +705,7 @@ public boolean containsPvrzReference(int index) { retVal = (curIndex == index); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; diff --git a/src/org/infinity/resource/graphics/MosV1Decoder.java b/src/org/infinity/resource/graphics/MosV1Decoder.java index 4c1de7962..5687b3f12 100644 --- a/src/org/infinity/resource/graphics/MosV1Decoder.java +++ b/src/org/infinity/resource/graphics/MosV1Decoder.java @@ -16,6 +16,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.DynamicArray; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class MosV1Decoder extends MosDecoder { private static final int BLOCK_DIMENSION = 64; // default block dimension @@ -68,7 +69,7 @@ public static MosDecoder.MosInfo getInfo(ResourceEntry mosEntry) { retVal = new MosDecoder.MosInfo(compressed, width, height, columns, rows, blockSize); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -418,7 +419,7 @@ private void init() { workingPalette = new int[256]; workingCanvas = new BufferedImage(BLOCK_DIMENSION, BLOCK_DIMENSION, BufferedImage.TYPE_INT_ARGB); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); close(); } } diff --git a/src/org/infinity/resource/graphics/MosV2Decoder.java b/src/org/infinity/resource/graphics/MosV2Decoder.java index b572a299e..aaff96737 100644 --- a/src/org/infinity/resource/graphics/MosV2Decoder.java +++ b/src/org/infinity/resource/graphics/MosV2Decoder.java @@ -22,6 +22,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.DynamicArray; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class MosV2Decoder extends MosDecoder { private static final int HEADER_SIZE = 16; // size of the MOS header @@ -59,7 +60,7 @@ public static MosDecoder.MosInfo getInfo(ResourceEntry mosEntry) { retVal = new MosDecoder.MosInfo(width, height, numBlocks); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -307,7 +308,7 @@ private void init() { dataBlocks.add(block); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); close(); } } @@ -321,7 +322,7 @@ private PvrDecoder getPVR(int page) { return PvrDecoder.loadPvr(entry); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -372,7 +373,7 @@ private boolean renderBlock(MosBlock block, Image canvas, int left, int top) { } return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return false; @@ -415,7 +416,7 @@ private boolean renderBlock(MosBlock block, int[] buffer, int width, int height, return true; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return false; diff --git a/src/org/infinity/resource/graphics/PltResource.java b/src/org/infinity/resource/graphics/PltResource.java index b4ed02478..2cfd507f5 100644 --- a/src/org/infinity/resource/graphics/PltResource.java +++ b/src/org/infinity/resource/graphics/PltResource.java @@ -64,6 +64,7 @@ import org.infinity.util.Table2da; import org.infinity.util.Table2daCache; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; import tv.porst.jhexview.DataChangedEvent; import tv.porst.jhexview.IDataChangedListener; @@ -286,7 +287,7 @@ public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("PNG writing is not supported"); } } catch (Exception ioe) { - ioe.printStackTrace(); + Logger.error(ioe); JOptionPane.showMessageDialog(panelMain.getTopLevelAncestor(), "Error while exporting " + entry, "Error", JOptionPane.ERROR_MESSAGE); } @@ -341,7 +342,7 @@ public void stateChanged(ChangeEvent event) { hexViewer.setCurrentOffset(0L); panelRaw.add(hexViewer, BorderLayout.CENTER); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { WindowBlocker.blockWindow(false); } @@ -727,7 +728,7 @@ private void init() { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } if (items == null) { diff --git a/src/org/infinity/resource/graphics/PseudoBamDecoder.java b/src/org/infinity/resource/graphics/PseudoBamDecoder.java index 191824438..515e95a86 100644 --- a/src/org/infinity/resource/graphics/PseudoBamDecoder.java +++ b/src/org/infinity/resource/graphics/PseudoBamDecoder.java @@ -34,6 +34,7 @@ import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * A decoder that takes individual images as input and simulates a BAM structure. Furthermore, this class provides @@ -865,7 +866,7 @@ public boolean exportBamV1(Path fileName, ProgressMonitor progress, int curProgr try (OutputStream os = StreamUtils.getOutputStream(fileName, true)) { os.write(bamData); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); throw e; } bamData = null; @@ -1014,7 +1015,7 @@ public boolean exportBamV2(Path fileName, DxtEncoder.DxtType dxtType, int pvrzIn try (OutputStream os = StreamUtils.getOutputStream(fileName, true)) { os.write(bamData); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); throw e; } bamData = null; @@ -1347,12 +1348,12 @@ private boolean createPvrzPages(Path path, DxtEncoder.DxtType dxtType, List"); JOptionPane.showMessageDialog(panel, sb.toString(), "Properties of " + resName, JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { decoder = null; } @@ -242,7 +243,7 @@ private BufferedImage loadImage() { if (decoder != null) { decoder = null; } - e.printStackTrace(); + Logger.error(e); } } return image; diff --git a/src/org/infinity/resource/graphics/TisConvert.java b/src/org/infinity/resource/graphics/TisConvert.java index 4141ba2b3..d305cb8d9 100644 --- a/src/org/infinity/resource/graphics/TisConvert.java +++ b/src/org/infinity/resource/graphics/TisConvert.java @@ -58,6 +58,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.StreamUtils; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * This utility class provides methods for converting tileset (TIS) resources. @@ -249,7 +250,7 @@ public static Status exportPNG(List tiles, int tileCols, Path pngFile, bo } } catch (IOException e) { retVal = Status.ERROR; - e.printStackTrace(); + Logger.error(e); } if (showProgress && progress.isCanceled()) { @@ -266,7 +267,7 @@ public static Status exportPNG(List tiles, int tileCols, Path pngFile, bo try { Files.delete(pngFile); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -375,7 +376,7 @@ public static ResourceEntry findWed(ResourceEntry tisEntry, boolean deepSearch) } catch (IOException e) { // do nothing } catch (Exception e) { - System.err.println(e.getClass().getName() + ": " + e.getMessage()); + Logger.warn("{}: {}", e.getClass().getName(), e.getMessage()); } } return false; @@ -639,7 +640,7 @@ public static Status convertToPaletteTis(Config config, boolean showProgress, Co tileImageOut.flush(); } catch (Exception e) { retVal = Status.ERROR; - e.printStackTrace(); + Logger.error(e); } finally { if (showProgress) { SwingUtilities.invokeLater(() -> progress.close()); @@ -649,7 +650,7 @@ public static Status convertToPaletteTis(Config config, boolean showProgress, Co try { Files.delete(config.getTisFile()); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -913,7 +914,7 @@ public static Status convertToPvrzTis(Config config, boolean showProgress, Compo retVal = Status.SUCCESS; } catch (Exception e) { retVal = Status.ERROR; - e.printStackTrace(); + Logger.error(e); } finally { if (showProgress) { SwingUtilities.invokeLater(() -> progress.close()); @@ -1220,7 +1221,7 @@ private static void createPvrz(Config config, Path pvrzFile, List tileM throw new IllegalArgumentException("Unsupported texture size (width=" + width + ", height=" + height + ")"); } if (tileMaps.isEmpty()) { - System.err.println("PVRZ creation: No tile maps available for " + pvrzFile.getFileName()); + Logger.warn("PVRZ creation: No tile maps available for {}", pvrzFile.getFileName()); } // generating texture image @@ -1263,7 +1264,7 @@ private static void createPvrz(Config config, Path pvrzFile, List tileM try { Files.delete(pvrzFile); } catch (IOException e2) { - e2.printStackTrace(); + Logger.error(e2); } throw e; } @@ -1299,7 +1300,7 @@ private static void renderTextureTiles(Config config, Graphics2D g, TileMap tile if (tmi != null) { config.getDecoder().getTile(tmi.getIndex(), tileImg); } else { - System.err.println("No tile available at " + p); + Logger.warn("No tile available at {}", p); continue; } @@ -1368,7 +1369,7 @@ private static void createPvrzTis(Config config, List ti Objects.requireNonNull(config); Objects.requireNonNull(tileList); if (tileList.isEmpty()) { - System.out.println(getErrorMessage(config, "Tile list is empty")); + Logger.info(getErrorMessage(config, "Tile list is empty")); } try (BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(config.getTisFile()))) { @@ -1394,7 +1395,7 @@ private static void createPvrzTis(Config config, List ti try { Files.delete(config.getTisFile()); } catch (IOException e2) { - e2.printStackTrace(); + Logger.error(e2); } throw e; } @@ -1928,7 +1929,7 @@ private WedInfo initWedInfo(ResourceEntry wedEntry) throws Exception { } } catch (Exception e) { wedInfo = null; - e.printStackTrace(); + Logger.error(e); } } @@ -1989,7 +1990,7 @@ private static OverlayConversion validateOverlayConversion(OverlayConversion con case BGEE_TO_BG2: case BG2EE_TO_BG1: case BG2EE_TO_BG2: - System.err.println("Unsupported overlay conversion mode: " + retVal); + Logger.warn("Unsupported overlay conversion mode: {}", retVal); retVal = OverlayConversion.NONE; break; default: @@ -2000,7 +2001,7 @@ private static OverlayConversion validateOverlayConversion(OverlayConversion con case BG1_TO_BG2EE: case BG2_TO_BGEE: case BG2_TO_BG2EE: - System.err.println("Unsupported overlay conversion mode: " + retVal); + Logger.warn("Unsupported overlay conversion mode: {}", retVal); retVal = OverlayConversion.NONE; break; default: diff --git a/src/org/infinity/resource/graphics/TisDecoder.java b/src/org/infinity/resource/graphics/TisDecoder.java index 7997938a8..6aa29e0fb 100644 --- a/src/org/infinity/resource/graphics/TisDecoder.java +++ b/src/org/infinity/resource/graphics/TisDecoder.java @@ -11,6 +11,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Common base class for handling TIS resources. @@ -55,7 +56,7 @@ public static Type getType(ResourceEntry tisEntry) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return retVal; @@ -84,7 +85,7 @@ public static TisInfo getInfo(ResourceEntry tisEntry) { retVal = new TisInfo(numTiles, tileSize, tileDim); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/resource/graphics/TisResource.java b/src/org/infinity/resource/graphics/TisResource.java index d311872f0..0e0a5140c 100644 --- a/src/org/infinity/resource/graphics/TisResource.java +++ b/src/org/infinity/resource/graphics/TisResource.java @@ -110,6 +110,7 @@ import org.infinity.util.DebugTimer; import org.infinity.util.io.FileEx; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; /** * This resource describes a tileset. There are currently two variants available: @@ -199,12 +200,12 @@ public void actionPerformed(ActionEvent event) { performBackgroundTask(() -> { DebugTimer.getInstance().timerReset(); Status status = TisConvert.convertToPaletteTis(config, true, panel.getTopLevelAncestor()); - DebugTimer.getInstance().timerShow("TIS conversion completed", DebugTimer.TimeFormat.MILLISECONDS); + Logger.info(DebugTimer.getInstance().getTimerFormatted("TIS conversion completed")); return status; }); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), "Tileset conversion: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } @@ -215,12 +216,12 @@ public void actionPerformed(ActionEvent event) { performBackgroundTask(() -> { DebugTimer.getInstance().timerReset(); Status status = TisConvert.convertToPvrzTis(config, true, panel.getTopLevelAncestor()); - DebugTimer.getInstance().timerShow("TIS conversion completed", DebugTimer.TimeFormat.MILLISECONDS); + Logger.info(DebugTimer.getInstance().getTimerFormatted("TIS conversion completed")); return status; }); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), "Tileset conversion: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } @@ -340,7 +341,7 @@ public void propertyChange(PropertyChangeEvent event) { retVal = Status.ERROR; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } if (retVal == Status.SUCCESS) { @@ -629,7 +630,7 @@ private void initTileset() { } WindowBlocker.blockWindow(false); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); WindowBlocker.blockWindow(false); if (tileImages == null) { tileImages = new ArrayList<>(); @@ -751,7 +752,7 @@ protected Status doInBackground() throws Exception { try { retVal = operation.get(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; } @@ -1126,7 +1127,7 @@ public static TisConvert.Config show(Component owner, TisResource tis) { dlg.setVisible(true); retVal = dlg.getConfig(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { if (dlg != null) { dlg.dispose(); @@ -1177,7 +1178,7 @@ private TisConvert.Config getConfig() { throw new Exception("Conversion not supported"); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -1488,7 +1489,7 @@ private void initPvrz() { try { tisPreview = new TisPreview(tis.decoder); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } final int previewWidth = sTilesPerRow.getValue(); @@ -1962,7 +1963,7 @@ private Path getTisPath() { try { return Paths.get(tfTisFile.getText().trim()); } catch (InvalidPathException e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -2161,7 +2162,7 @@ public void mouseMoved(MouseEvent e) { try { tisPreview.setTileSize(zoom); } catch (Exception ex) { - ex.printStackTrace(); + Logger.error(ex); // revert zoom change (if possible) for (int i = 0, size = cbPreviewImageZoom.getModel().getSize(); i < size; i++) { final int value = cbPreviewImageZoom.getModel().getElementAt(cbPreviewImageZoom.getSelectedIndex()).getData(); diff --git a/src/org/infinity/resource/graphics/TisV1Decoder.java b/src/org/infinity/resource/graphics/TisV1Decoder.java index 568b071b1..c35ee30d0 100644 --- a/src/org/infinity/resource/graphics/TisV1Decoder.java +++ b/src/org/infinity/resource/graphics/TisV1Decoder.java @@ -14,6 +14,7 @@ import java.util.Objects; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** * Handles legacy TIS resources (using palettized tiles). @@ -199,7 +200,7 @@ private void init() { workingPalette = new int[256]; workingCanvas = new BufferedImage(TILE_DIMENSION, TILE_DIMENSION, Transparency.BITMASK); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); close(); } } diff --git a/src/org/infinity/resource/graphics/TisV2Decoder.java b/src/org/infinity/resource/graphics/TisV2Decoder.java index dcbb15440..38a7d86c7 100644 --- a/src/org/infinity/resource/graphics/TisV2Decoder.java +++ b/src/org/infinity/resource/graphics/TisV2Decoder.java @@ -15,6 +15,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** * Handles new PVRZ-based TIS resources. @@ -163,7 +164,7 @@ private void init() { workingCanvas = new BufferedImage(TILE_DIMENSION, TILE_DIMENSION, BufferedImage.TYPE_INT_ARGB); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); close(); } } @@ -178,7 +179,7 @@ private PvrDecoder getPVR(int page) { return PvrDecoder.loadPvr(entry); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -253,7 +254,7 @@ private boolean updateWorkingCanvas(int tileIdx) { } return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); decoder = null; } } diff --git a/src/org/infinity/resource/key/BIFFEntry.java b/src/org/infinity/resource/key/BIFFEntry.java index 55c54c7a7..977ba2f2a 100644 --- a/src/org/infinity/resource/key/BIFFEntry.java +++ b/src/org/infinity/resource/key/BIFFEntry.java @@ -19,6 +19,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Provides information about the location of resource data within BIFF archives. @@ -218,8 +219,7 @@ public void updateBIFF(Path keyFile, int index, ByteBuffer buffer, int offset, b try { this.fileSize = (int) Files.size(this.biffFile); } catch (IOException e) { - System.err.println(String.format("Could not determine file size: %s", this.biffFile)); - e.printStackTrace(); + Logger.error(e, "Could not determine file size: {}", this.biffFile); } } } diff --git a/src/org/infinity/resource/key/BIFFResourceEntry.java b/src/org/infinity/resource/key/BIFFResourceEntry.java index 5368c2fa7..fd26c9de0 100644 --- a/src/org/infinity/resource/key/BIFFResourceEntry.java +++ b/src/org/infinity/resource/key/BIFFResourceEntry.java @@ -23,6 +23,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class BIFFResourceEntry extends ResourceEntry implements Writeable { /** Full path to KEY file containing BIFF entry. */ @@ -154,7 +155,7 @@ public Path getActualPath(boolean ignoreOverride) { try { return ResourceFactory.getKeyfile().getBIFFFile(getBIFFEntry()).getFile(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -181,7 +182,7 @@ public long getResourceSize(boolean ignoreOverride) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return retVal; } diff --git a/src/org/infinity/resource/key/FileResourceEntry.java b/src/org/infinity/resource/key/FileResourceEntry.java index fec931674..2d032af3e 100644 --- a/src/org/infinity/resource/key/FileResourceEntry.java +++ b/src/org/infinity/resource/key/FileResourceEntry.java @@ -23,6 +23,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.util.io.ByteBufferInputStream; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class FileResourceEntry extends ResourceEntry { private final boolean override; @@ -56,7 +57,7 @@ public long getResourceSize(boolean ignoreOverride) { try { return Files.size(file); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return -1L; } diff --git a/src/org/infinity/resource/key/Keyfile.java b/src/org/infinity/resource/key/Keyfile.java index 31cbc8bb4..e20d07c4e 100644 --- a/src/org/infinity/resource/key/Keyfile.java +++ b/src/org/infinity/resource/key/Keyfile.java @@ -30,6 +30,7 @@ import org.infinity.util.Misc; import org.infinity.util.io.FileEx; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class Keyfile { public static final ImageIcon ICON_STRUCT = Icons.ICON_ROW_INSERT_AFTER_16.getIcon(); @@ -348,7 +349,7 @@ public void addBIFFEntry(BIFFEntry entry) { // try { // Files.deleteIfExists(file); // } catch (IOException e) { - // e.printStackTrace(); + // Logger.error(e); // } // } // }); @@ -368,7 +369,7 @@ public void addBIFFEntry(BIFFEntry entry) { // // return true; // } catch (IOException e) { - // e.printStackTrace(); + // Logger.error(e); // } // // return false; @@ -455,7 +456,7 @@ private void cacheBIFFs() { try { AbstractBIFFReader.open(biffPath); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/key/ResourceEntry.java b/src/org/infinity/resource/key/ResourceEntry.java index 818313e37..6c868ecca 100644 --- a/src/org/infinity/resource/key/ResourceEntry.java +++ b/src/org/infinity/resource/key/ResourceEntry.java @@ -34,6 +34,7 @@ import org.infinity.search.SearchOptions; import org.infinity.util.io.FileEx; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public abstract class ResourceEntry implements Comparable { // list of file extensions not shown in the resource tree @@ -88,7 +89,7 @@ static int[] getLocalFileInfo(Path file) { return new int[] { (int) ch.size() }; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return null; @@ -205,7 +206,7 @@ public String getSearchString() { JOptionPane.ERROR_MESSAGE); } searchString = "Error"; - e.printStackTrace(); + Logger.error(e); } } return searchString; diff --git a/src/org/infinity/resource/key/ResourceTreeModel.java b/src/org/infinity/resource/key/ResourceTreeModel.java index ef8052a73..d3c1ea079 100644 --- a/src/org/infinity/resource/key/ResourceTreeModel.java +++ b/src/org/infinity/resource/key/ResourceTreeModel.java @@ -25,6 +25,7 @@ import org.infinity.util.Misc; import org.infinity.util.io.FileEx; +import org.tinylog.Logger; public final class ResourceTreeModel implements TreeModel { private final List treeModelListeners = new ArrayList<>(); @@ -111,7 +112,7 @@ public void addDirectory(ResourceTreeFolder parentFolder, Path directory, boolea parentFolder.sortChildren(true); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); return; } } diff --git a/src/org/infinity/resource/mus/Viewer.java b/src/org/infinity/resource/mus/Viewer.java index 5025189d5..78b57d823 100644 --- a/src/org/infinity/resource/mus/Viewer.java +++ b/src/org/infinity/resource/mus/Viewer.java @@ -32,6 +32,7 @@ import org.infinity.resource.sound.AudioPlayer; import org.infinity.util.Misc; import org.infinity.util.SimpleListModel; +import org.tinylog.Logger; public class Viewer extends JPanel implements Runnable, ActionListener { /** Provides quick access to the "play" and "pause" image icon. */ @@ -119,7 +120,7 @@ public void run() { } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error during playback", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } player.stopPlay(); setPlayButtonState(false); @@ -182,7 +183,7 @@ private boolean parseMusFile(MusResource mus) { try { entry.init(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(getTopLevelAncestor(), "Error loading " + entry.toString() + '\n' + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } diff --git a/src/org/infinity/resource/other/TtfResource.java b/src/org/infinity/resource/other/TtfResource.java index 933e5f50f..0cec953b2 100644 --- a/src/org/infinity/resource/other/TtfResource.java +++ b/src/org/infinity/resource/other/TtfResource.java @@ -39,6 +39,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.ViewableContainer; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; public class TtfResource implements Resource, DocumentListener, ActionListener { private static final ButtonPanel.Control PROPERTIES = ButtonPanel.Control.CUSTOM_1; @@ -64,7 +65,7 @@ public TtfResource(ResourceEntry entry) throws Exception { font = Font.createFont(Font.TRUETYPE_FONT, is); } catch (Exception e) { font = null; - e.printStackTrace(); + Logger.error(e); throw new Exception("Invalid TTF resource"); } @@ -183,7 +184,7 @@ private void updateText(String text) { try { doc.remove(0, doc.getLength()); } catch (BadLocationException e) { - e.printStackTrace(); + Logger.error(e); } } @@ -198,7 +199,7 @@ private void updateText(String text) { doc.insertString(pos, label, as); pos += label.length(); } catch (BadLocationException e) { - e.printStackTrace(); + Logger.error(e); } as = new SimpleAttributeSet(); @@ -210,7 +211,7 @@ private void updateText(String text) { doc.insertString(pos, "\n\n", as); pos += 2; } catch (BadLocationException e) { - e.printStackTrace(); + Logger.error(e); } } tpDisplay.setCaretPosition(0); diff --git a/src/org/infinity/resource/other/UnknownResource.java b/src/org/infinity/resource/other/UnknownResource.java index cfd7a466a..1e7d79dac 100644 --- a/src/org/infinity/resource/other/UnknownResource.java +++ b/src/org/infinity/resource/other/UnknownResource.java @@ -46,6 +46,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.Misc; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; import tv.porst.jhexview.DataChangedEvent; import tv.porst.jhexview.IDataChangedListener; @@ -337,7 +338,7 @@ private void synchronizeData(int tabIndex) { hexViewer.setCurrentOffset(0L); panelRaw.add(hexViewer, BorderLayout.CENTER); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { WindowBlocker.blockWindow(false); } @@ -407,7 +408,7 @@ protected Void doInBackground() throws Exception { editor.discardAllEdits(); // don't undo loading operation success = true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } if (success) { setEditorActive(true); diff --git a/src/org/infinity/resource/pro/ProResource.java b/src/org/infinity/resource/pro/ProResource.java index 8d2fda849..bfb5e2a97 100644 --- a/src/org/infinity/resource/pro/ProResource.java +++ b/src/org/infinity/resource/pro/ProResource.java @@ -38,6 +38,7 @@ import org.infinity.resource.StructEntry; import org.infinity.resource.key.ResourceEntry; import org.infinity.search.SearchOptions; +import org.tinylog.Logger; /** * This resource describes projectiles, and the files are referenced spells and projectile weapons. Projectile files can @@ -158,7 +159,7 @@ public boolean valueUpdated(UpdateEvent event) { struct.addDatatype(new ProAreaType(), struct.getFields().size()); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return false; } } else if (proType.getValue() == 2L) { // single target @@ -171,7 +172,7 @@ public boolean valueUpdated(UpdateEvent event) { try { struct.addDatatype(new ProSingleType(), struct.getFields().size()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return false; } } diff --git a/src/org/infinity/resource/sav/IOHandler.java b/src/org/infinity/resource/sav/IOHandler.java index 82f37fece..2257a4b34 100644 --- a/src/org/infinity/resource/sav/IOHandler.java +++ b/src/org/infinity/resource/sav/IOHandler.java @@ -23,6 +23,7 @@ import org.infinity.util.FileDeletionHook; import org.infinity.util.io.FileEx; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class IOHandler implements Writeable { private final ResourceEntry entry; @@ -73,13 +74,13 @@ public void close() { } } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } try { Files.delete(tempFolder); } catch (IOException e) { FileDeletionHook.getInstance().registerFile(tempFolder); - e.printStackTrace(); + Logger.error(e); } tempFolder = null; } diff --git a/src/org/infinity/resource/sav/SavResource.java b/src/org/infinity/resource/sav/SavResource.java index 8b0fefcf2..d94b1b952 100644 --- a/src/org/infinity/resource/sav/SavResource.java +++ b/src/org/infinity/resource/sav/SavResource.java @@ -51,6 +51,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.SimpleListModel; import org.infinity.util.io.FileEx; +import org.tinylog.Logger; /** * This resource acts as a standalone compressed archive. The file is zlib compressed, and allows incremental updates to @@ -125,7 +126,7 @@ public void actionPerformed(ActionEvent event) { Resource res = ResourceFactory.getResource(fileentry); new ViewFrame(panel.getTopLevelAncestor(), res); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), "Could not open selected resource.", "Error", JOptionPane.ERROR_MESSAGE); } @@ -220,7 +221,7 @@ public void mouseClicked(MouseEvent event) { Resource res = ResourceFactory.getResource(fileentry); new ViewFrame(panel.getTopLevelAncestor(), res); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), "Could not open selected resource.", "Error", JOptionPane.ERROR_MESSAGE); } @@ -336,7 +337,7 @@ private boolean compressData(boolean showError) { if (showError) { JOptionPane.showMessageDialog(panel, "Error compressing file", "Error", JOptionPane.ERROR_MESSAGE); } - e.printStackTrace(); + Logger.error(e); return false; } return true; @@ -363,7 +364,7 @@ private boolean decompressData(boolean showError) { if (showError) { JOptionPane.showMessageDialog(panel, "Error decompressing file", "Error", JOptionPane.ERROR_MESSAGE); } - e.printStackTrace(); + Logger.error(e); return false; } return true; @@ -412,7 +413,7 @@ private void addResource(ResourceEntry resourceEntry) { buttonPanel.getControlByType(CTRL_DELETE).setEnabled(filelist.getSelectedIndex() >= 0); buttonPanel.getControlByType(CTRL_EDIT).setEnabled(filelist.getSelectedIndex() >= 0); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel.getTopLevelAncestor(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } @@ -426,7 +427,7 @@ private void removeResource(int entryIndex) { try { Files.delete(file); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } entries.remove(resourceEntry); diff --git a/src/org/infinity/resource/sav/SavResourceEntry.java b/src/org/infinity/resource/sav/SavResourceEntry.java index 005a71363..aa755fd2c 100644 --- a/src/org/infinity/resource/sav/SavResourceEntry.java +++ b/src/org/infinity/resource/sav/SavResourceEntry.java @@ -20,6 +20,7 @@ import org.infinity.util.io.ByteBufferInputStream; import org.infinity.util.io.ByteBufferOutputStream; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Specialized ResourceEntry class for compressed entries in SAV resources. @@ -116,7 +117,7 @@ public int[] getResourceInfo(boolean ignoreoverride) throws Exception { return new int[] { data.getInt(8), data.getInt(12) }; } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -150,7 +151,7 @@ public long getResourceSize(boolean ignoreOverride) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return -1L; } diff --git a/src/org/infinity/resource/sound/AudioFactory.java b/src/org/infinity/resource/sound/AudioFactory.java index 99b924e51..0f27f18c3 100644 --- a/src/org/infinity/resource/sound/AudioFactory.java +++ b/src/org/infinity/resource/sound/AudioFactory.java @@ -8,6 +8,7 @@ import org.infinity.resource.sound.AudioBuffer.AudioOverride; import org.infinity.util.DynamicArray; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class AudioFactory { // supported audio formats @@ -37,7 +38,7 @@ public static AudioBuffer getAudioBuffer(ResourceEntry entry, AudioOverride over try { return getAudioBuffer(StreamUtils.toArray(entry.getResourceBuffer()), 0, override); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return null; } } @@ -78,7 +79,7 @@ public static AudioBuffer getAudioBuffer(byte[] buffer, int offset, AudioOverrid return null; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return null; } } @@ -105,7 +106,7 @@ public static byte[] convertAudio(ResourceEntry entry, AudioOverride override) { try { return convertAudio(StreamUtils.toArray(entry.getResourceBuffer()), 0, override); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return null; } } @@ -138,7 +139,7 @@ public static byte[] convertAudio(byte[] buffer, int offset, AudioOverride overr return ab.getAudioData(); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return null; } return null; diff --git a/src/org/infinity/resource/sound/OggBuffer.java b/src/org/infinity/resource/sound/OggBuffer.java index d21f78884..5ba26576f 100644 --- a/src/org/infinity/resource/sound/OggBuffer.java +++ b/src/org/infinity/resource/sound/OggBuffer.java @@ -8,6 +8,7 @@ import java.io.ByteArrayOutputStream; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; import com.jcraft.jogg.Packet; import com.jcraft.jogg.Page; @@ -243,7 +244,7 @@ private byte[] decodeOgg(byte[] inBuf, int offset) throws Exception { } if (result == -1) { // missing or corrupt data at this page position - System.err.println("Corrupt or missing data in bitstream; continuing..."); + Logger.warn("Corrupt or missing data in bitstream; continuing..."); } else { os.pagein(og); // can safely ignore errors at this point diff --git a/src/org/infinity/resource/sound/SoundResource.java b/src/org/infinity/resource/sound/SoundResource.java index 214a8ee14..51eefa26a 100644 --- a/src/org/infinity/resource/sound/SoundResource.java +++ b/src/org/infinity/resource/sound/SoundResource.java @@ -43,6 +43,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.search.WavReferenceSearcher; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Handles all kinds of supported single track audio files. @@ -179,7 +180,7 @@ public void run() { player.play(audioBuffer); } catch (Exception e) { JOptionPane.showMessageDialog(panel, "Error during playback", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } player.stopPlay(); timerTask.stop(); @@ -336,7 +337,7 @@ private boolean loadAudio() { return true; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(getContainer(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } return false; diff --git a/src/org/infinity/resource/text/modes/BCSFoldParser.java b/src/org/infinity/resource/text/modes/BCSFoldParser.java index cfc2a5ee5..618463f00 100644 --- a/src/org/infinity/resource/text/modes/BCSFoldParser.java +++ b/src/org/infinity/resource/text/modes/BCSFoldParser.java @@ -15,6 +15,7 @@ import org.fife.ui.rsyntaxtextarea.folding.Fold; import org.fife.ui.rsyntaxtextarea.folding.FoldParser; import org.fife.ui.rsyntaxtextarea.folding.FoldType; +import org.tinylog.Logger; /** * A fold parser for BCS scripts. It supports folding of multiline comments and IF/END blocks. @@ -84,7 +85,7 @@ public List getFolds(RSyntaxTextArea textArea) { } } } catch (BadLocationException e) { - e.printStackTrace(); + Logger.error(e); } return folds; diff --git a/src/org/infinity/resource/text/modes/BCSTokenMaker.java b/src/org/infinity/resource/text/modes/BCSTokenMaker.java index 2a0cdea56..5ca48e9c8 100644 --- a/src/org/infinity/resource/text/modes/BCSTokenMaker.java +++ b/src/org/infinity/resource/text/modes/BCSTokenMaker.java @@ -20,6 +20,7 @@ import org.infinity.util.IdsMap; import org.infinity.util.IdsMapCache; import org.infinity.util.IdsMapEntry; +import org.tinylog.Logger; /** * A token maker that turns text into a linked list of {@code Token}s for syntax highlighting Infinity Engine BCS @@ -544,7 +545,7 @@ public Token getTokenList(Segment text, int initialTokenType, int startOffset) { throw new Exception( String.format("Invalid token %d found at position %d", currentTokenType, newStartOfs + i)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } // end of default: } // end of switch (currentTokenType) diff --git a/src/org/infinity/resource/text/modes/GLSLTokenMaker.java b/src/org/infinity/resource/text/modes/GLSLTokenMaker.java index 539e0f58d..1e1712644 100644 --- a/src/org/infinity/resource/text/modes/GLSLTokenMaker.java +++ b/src/org/infinity/resource/text/modes/GLSLTokenMaker.java @@ -25,6 +25,7 @@ import org.fife.ui.rsyntaxtextarea.Token; import org.fife.ui.rsyntaxtextarea.TokenImpl; import org.infinity.util.Misc; +import org.tinylog.Logger; /** @@ -3805,7 +3806,7 @@ public Token getTokenList(Segment text, int initialTokenType, int startOffset) { yybegin(state); return yylex(); } catch (IOException ioe) { - ioe.printStackTrace(); + Logger.error(ioe); return new TokenImpl(); } diff --git a/src/org/infinity/resource/text/modes/INITokenMaker.java b/src/org/infinity/resource/text/modes/INITokenMaker.java index a36ba9fe2..f04911dd2 100644 --- a/src/org/infinity/resource/text/modes/INITokenMaker.java +++ b/src/org/infinity/resource/text/modes/INITokenMaker.java @@ -10,6 +10,7 @@ import org.fife.ui.rsyntaxtextarea.Token; import org.fife.ui.rsyntaxtextarea.TokenMap; import org.fife.ui.rsyntaxtextarea.TokenTypes; +import org.tinylog.Logger; /** * A token maker that turns text into a linked list of {@code Token}s for syntax highlighting Infinity Engine INI @@ -176,7 +177,7 @@ public Token getTokenList(Segment text, int initialTokenType, int startOffset) { try { throw new Exception("Invalid token " + currentTokenType + " found at position " + (newStartOfs + i)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/text/modes/MenuTokenMaker.java b/src/org/infinity/resource/text/modes/MenuTokenMaker.java index 4db3227f9..8f43a1862 100644 --- a/src/org/infinity/resource/text/modes/MenuTokenMaker.java +++ b/src/org/infinity/resource/text/modes/MenuTokenMaker.java @@ -23,6 +23,7 @@ import org.fife.ui.rsyntaxtextarea.AbstractJFlexTokenMaker; import org.fife.ui.rsyntaxtextarea.Token; import org.fife.ui.rsyntaxtextarea.TokenImpl; +import org.tinylog.Logger; /** @@ -4414,7 +4415,7 @@ public Token getTokenList(Segment text, int initialTokenType, int startOffset) { yybegin(state); return yylex(); } catch (IOException ioe) { - ioe.printStackTrace(); + Logger.error(ioe); return new TokenImpl(); } diff --git a/src/org/infinity/resource/text/modes/TLKTokenMaker.java b/src/org/infinity/resource/text/modes/TLKTokenMaker.java index dda9d9510..00ac2ad82 100644 --- a/src/org/infinity/resource/text/modes/TLKTokenMaker.java +++ b/src/org/infinity/resource/text/modes/TLKTokenMaker.java @@ -13,6 +13,7 @@ import org.fife.ui.rsyntaxtextarea.TokenMap; import org.fife.ui.rsyntaxtextarea.TokenTypes; import org.infinity.resource.Profile; +import org.tinylog.Logger; /** * A token maker that turns text into a linked list of {@link Token}s for syntax highlighting Infinity Engine text @@ -132,7 +133,7 @@ public Token getTokenList(Segment text, int initialTokenType, int startOffset) { try { throw new Exception("Invalid token " + currentTokenType + " found at position " + (newStartOfs + i)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/text/modes/WeiDULogTokenMaker.java b/src/org/infinity/resource/text/modes/WeiDULogTokenMaker.java index df19e4613..2e5ed9260 100644 --- a/src/org/infinity/resource/text/modes/WeiDULogTokenMaker.java +++ b/src/org/infinity/resource/text/modes/WeiDULogTokenMaker.java @@ -10,6 +10,7 @@ import org.fife.ui.rsyntaxtextarea.Token; import org.fife.ui.rsyntaxtextarea.TokenMap; import org.fife.ui.rsyntaxtextarea.TokenTypes; +import org.tinylog.Logger; /** * A token maker that turns text into a linked list of {@link Token}s for syntax highlighting WeiDU.log content. @@ -108,7 +109,7 @@ public Token getTokenList(Segment text, int initialTokenType, int startOffset) { try { throw new Exception("Invalid token " + currentTokenType + " found at position " + (newStartOfs + i)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/to/TohResource.java b/src/org/infinity/resource/to/TohResource.java index 0956b3630..b20ba65ec 100644 --- a/src/org/infinity/resource/to/TohResource.java +++ b/src/org/infinity/resource/to/TohResource.java @@ -25,6 +25,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.resource.sav.SavResource; import org.infinity.util.StringTable; +import org.tinylog.Logger; /** * This resource serves a similar purpose (and has a similar structure to) {@link StringTable TLK} files. The resource @@ -138,13 +139,13 @@ public static String getOverrideString(ResourceEntry tohEntry, ResourceEntry tot try { toh = (tohEntry != null) ? new TohResource(tohEntry) : null; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } if (!Profile.isEnhancedEdition()) { try { tot = (totEntry != null) ? new TotResource(totEntry, toh) : null; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return getOverrideString(toh, tot, strref); diff --git a/src/org/infinity/resource/to/TotResource.java b/src/org/infinity/resource/to/TotResource.java index 5fb29d93c..bf28c2651 100644 --- a/src/org/infinity/resource/to/TotResource.java +++ b/src/org/infinity/resource/to/TotResource.java @@ -19,6 +19,7 @@ import org.infinity.resource.sav.SavResource; import org.infinity.util.StringTable; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; /** * This resource serves a similar purpose (and has a similar structure to) {@link StringTable TLK} files. The files can @@ -128,7 +129,7 @@ public static boolean isStringEntryValid(StringEntry entry) { int ofsNext = ((IsNumeric) entry.getAttribute(StringEntry.TOT_STRING_OFFSET_NEXT_ENTRY)).getValue(); retVal = (ofsPrev == -1 && ofsNext == -1) || (ofsPrev != ofsNext); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -156,7 +157,7 @@ private TohResource loadAssociatedToh(ResourceEntry totResource) { try { toh = new TohResource(new FileResourceEntry(tohPath)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/resource/vef/VefType.java b/src/org/infinity/resource/vef/VefType.java index 7195f85ee..ec105211f 100644 --- a/src/org/infinity/resource/vef/VefType.java +++ b/src/org/infinity/resource/vef/VefType.java @@ -14,6 +14,7 @@ import org.infinity.datatype.TextString; import org.infinity.resource.AbstractStruct; import org.infinity.resource.StructEntry; +import org.tinylog.Logger; public final class VefType extends Bitmap { // VEF/VefType-specific field labels @@ -42,7 +43,7 @@ public boolean updateValue(AbstractStruct struct) { struct.addFields(this, list); return true; } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return false; } diff --git a/src/org/infinity/resource/video/MveDecoder.java b/src/org/infinity/resource/video/MveDecoder.java index 7ee977186..56512251a 100644 --- a/src/org/infinity/resource/video/MveDecoder.java +++ b/src/org/infinity/resource/video/MveDecoder.java @@ -16,6 +16,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Decodes a MVE video resource. @@ -526,7 +527,7 @@ private boolean manageSegment(MveChunk chunk, MveSegment segment) { return true; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return false; @@ -777,7 +778,7 @@ private boolean initSegments() { segments.add(segment); curSize += segmentSize; } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); return false; } } @@ -799,7 +800,7 @@ private boolean peekNextChunk() { nextChunkSize = StreamUtils.readUnsignedShort(in); nextChunkType = StreamUtils.readUnsignedShort(in); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); return false; } } diff --git a/src/org/infinity/resource/video/MvePlayer.java b/src/org/infinity/resource/video/MvePlayer.java index a16b1d9ae..74ea6a337 100644 --- a/src/org/infinity/resource/video/MvePlayer.java +++ b/src/org/infinity/resource/video/MvePlayer.java @@ -8,6 +8,8 @@ import javax.sound.sampled.AudioSystem; import javax.sound.sampled.SourceDataLine; +import org.tinylog.Logger; + public class MvePlayer { private boolean playing; private boolean paused; @@ -243,7 +245,7 @@ private void initAudio(MveDecoder decoder) throws Exception { try { dataLine = AudioSystem.getSourceDataLine(audioFormat); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); throw new Exception("Unsupported audio format"); } dataLine.open(audioFormat, 16384); diff --git a/src/org/infinity/resource/video/MveResource.java b/src/org/infinity/resource/video/MveResource.java index e211dda17..06480f791 100644 --- a/src/org/infinity/resource/video/MveResource.java +++ b/src/org/infinity/resource/video/MveResource.java @@ -56,6 +56,7 @@ import org.monte.media.VideoFormatKeys; import org.monte.media.avi.AVIWriter; import org.monte.media.math.Rational; +import org.tinylog.Logger; /** * This resource describes the movies played during the game. Movies can only be played by the engine when they are @@ -97,7 +98,7 @@ public MveResource(ResourceEntry entry) throws Exception { } } catch (Exception e) { decoder = null; - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error opening " + entry, "Error", JOptionPane.ERROR_MESSAGE); } @@ -207,7 +208,7 @@ public void run() { try { decoder.open(entry); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel, "Error starting video playback", "Error", JOptionPane.ERROR_MESSAGE); return; } @@ -221,7 +222,7 @@ public void run() { player.play(renderer, decoder); } catch (Exception e) { player.stopPlay(); - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(panel, "Error during playback", "Error", JOptionPane.ERROR_MESSAGE); } decoder.close(); @@ -457,7 +458,7 @@ AudioFormatKeys.SampleRateKey, new Rational(sampleRate), AudioFormatKeys.SampleS try { Files.delete(outFile); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } JOptionPane.showMessageDialog(parent, "Conversion has been cancelled.", "Information", @@ -489,7 +490,7 @@ AudioFormatKeys.SampleRateKey, new Rational(sampleRate), AudioFormatKeys.SampleS } return true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } if (!silent) { JOptionPane.showMessageDialog(parent, "Error while exporting " + inEntry + " as AVI file.", "Error", diff --git a/src/org/infinity/resource/video/MveVideoDecoder.java b/src/org/infinity/resource/video/MveVideoDecoder.java index b7354398e..b1c57be07 100644 --- a/src/org/infinity/resource/video/MveVideoDecoder.java +++ b/src/org/infinity/resource/video/MveVideoDecoder.java @@ -14,6 +14,7 @@ import org.infinity.resource.video.MveDecoder.MveInfo; import org.infinity.resource.video.MveDecoder.MveSegment; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * Decodes a single 8x8 pixel block of video data. (Internally used by MveDecoder) @@ -1126,7 +1127,7 @@ private void copyBlock8x8(BufferedImage src, int srcX, int srcY, int dstX, int d int srcOfs = srcY * src.getWidth() + srcX; int dstOfs = dstY * curBuffer.getWidth() + dstX; if (srcOfs < 0) { - System.err.println("Debug: copyBlock8x8(src, " + srcX + ", " + srcY + ", " + dstX + ", " + dstY + ")"); + Logger.debug("copyBlock8x8(src, {}, {}, {}, {})", srcX, srcY, dstX, dstY); return; } diff --git a/src/org/infinity/resource/video/WbmResource.java b/src/org/infinity/resource/video/WbmResource.java index f7894378c..5f83f79f2 100644 --- a/src/org/infinity/resource/video/WbmResource.java +++ b/src/org/infinity/resource/video/WbmResource.java @@ -39,6 +39,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class WbmResource implements Resource, Closeable, Referenceable, ActionListener { private final ResourceEntry entry; @@ -76,7 +77,7 @@ public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(NearInfinity.getInstance(), "Error opening video or no application registered " + "to play back WBM (WebM) files.", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); } } } finally { @@ -182,7 +183,7 @@ private Path getVideoFile() { isTempFile = true; FileDeletionHook.getInstance().registerFile(retVal); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); retVal = null; } } diff --git a/src/org/infinity/resource/wmp/ViewerMap.java b/src/org/infinity/resource/wmp/ViewerMap.java index 3eb51cfbe..1d3f6b127 100644 --- a/src/org/infinity/resource/wmp/ViewerMap.java +++ b/src/org/infinity/resource/wmp/ViewerMap.java @@ -69,6 +69,7 @@ import org.infinity.util.Misc; import org.infinity.util.StringTable; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public class ViewerMap extends JPanel { /** Needed to determine map edges to travel from/to. */ @@ -192,7 +193,7 @@ private enum Direction { pInfo.add(lInfoPos); add(pInfo, BorderLayout.SOUTH); } catch (Throwable t) { - t.printStackTrace(); + Logger.error(t); } // applying preselected overlays @@ -673,7 +674,7 @@ private void exportMap() { dstImage.flush(); dstImage = null; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } finally { showDot((AreaEntry) listPanel.getList().getSelectedValue(), false); WindowBlocker.blockWindow(wnd, false); diff --git a/src/org/infinity/search/AbstractSearcher.java b/src/org/infinity/search/AbstractSearcher.java index c6afbe48f..0cbe46ac1 100644 --- a/src/org/infinity/search/AbstractSearcher.java +++ b/src/org/infinity/search/AbstractSearcher.java @@ -16,6 +16,7 @@ import org.infinity.util.DebugTimer; import org.infinity.util.Misc; import org.infinity.util.Threading; +import org.tinylog.Logger; /** * Utility class for performing searching of resources in several threads with ability to cancel search. @@ -145,7 +146,7 @@ protected boolean runSearch(String operation, List entries) { // ignored } - DebugTimer.getInstance().timerShow(operation + " completed", DebugTimer.TimeFormat.MILLISECONDS); + Logger.info(DebugTimer.getInstance().getTimerFormatted(operation + " completed")); if (isCancelled) { JOptionPane.showMessageDialog(parent, operation + " cancelled", "Info", JOptionPane.INFORMATION_MESSAGE); diff --git a/src/org/infinity/search/DialogItemRefSearcher.java b/src/org/infinity/search/DialogItemRefSearcher.java index 52ede113a..df1b8d349 100644 --- a/src/org/infinity/search/DialogItemRefSearcher.java +++ b/src/org/infinity/search/DialogItemRefSearcher.java @@ -18,6 +18,8 @@ import org.infinity.resource.dlg.State; import org.infinity.resource.dlg.StateTrigger; import org.infinity.resource.dlg.Transition; +import org.infinity.util.DebugTimer; +import org.tinylog.Logger; public class DialogItemRefSearcher implements Runnable { private final DlgResource dlg; @@ -38,7 +40,7 @@ public void run() { final List searchItems = dlg.getFields(); ProgressMonitor progress = new ProgressMonitor(parent, "Searching...", null, 0, searchItems.size()); progress.setMillisToDecideToPopup(100); - long startTime = System.currentTimeMillis(); + DebugTimer.getInstance().timerReset(); for (int i = 0; i < searchItems.size(); i++) { StructEntry entry = searchItems.get(i); if (entry instanceof State || entry instanceof Transition || entry instanceof AbstractCode) { @@ -50,7 +52,7 @@ public void run() { return; } } - System.out.println("Search completed: " + (System.currentTimeMillis() - startTime) + "ms."); + Logger.info(DebugTimer.getInstance().getTimerFormatted("Search completed")); hitFrame.setVisible(true); } diff --git a/src/org/infinity/search/DialogSearcher.java b/src/org/infinity/search/DialogSearcher.java index ba6596cea..878b584b8 100644 --- a/src/org/infinity/search/DialogSearcher.java +++ b/src/org/infinity/search/DialogSearcher.java @@ -41,6 +41,7 @@ import org.infinity.resource.dlg.AbstractCode; import org.infinity.resource.dlg.Action; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; public final class DialogSearcher extends AbstractSearcher implements Runnable, ActionListener { private final ChildFrame inputFrame; @@ -192,14 +193,11 @@ protected Runnable newWorker(ResourceEntry entry) { s = decompiler.getSource(); } else { synchronized (System.err) { - System.err.println("Error(s) compiling " + entry.toString() + " - " + searchEntry.getName()); + Logger.error("Error(s) compiling {} - {}", entry.toString(), searchEntry.getName()); } } } catch (Exception ex) { - synchronized (System.err) { - System.err.println("Exception (de)compiling " + entry.toString() + " - " + searchEntry.getName()); - ex.printStackTrace(); - } + Logger.error(ex, "Exception (de)compiling {} - {}", entry.toString(), searchEntry.getName()); } if (s == null) { s = ""; diff --git a/src/org/infinity/search/ReferenceSearcher.java b/src/org/infinity/search/ReferenceSearcher.java index 1ce3087b3..3992f01c5 100644 --- a/src/org/infinity/search/ReferenceSearcher.java +++ b/src/org/infinity/search/ReferenceSearcher.java @@ -34,6 +34,7 @@ import org.infinity.resource.other.EffResource; import org.infinity.resource.sav.SavResource; import org.infinity.resource.text.PlainTextResource; +import org.tinylog.Logger; public final class ReferenceSearcher extends AbstractReferenceSearcher { /** Optional alternate name to search for. */ @@ -57,7 +58,7 @@ public ReferenceSearcher(ResourceEntry targetEntry, String[] fileTypes, Componen } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -127,8 +128,7 @@ private void searchDialog(ResourceEntry entry, AbstractStruct dialog) { } } } catch (Exception e) { - System.out.println("Exception in " + dialog.getName() + " - " + sourceCode.getName()); - e.printStackTrace(); + Logger.error(e, "Exception in {} - {}", dialog.getName(), sourceCode.getName()); } } else if (o instanceof AbstractStruct) { searchDialog(entry, (AbstractStruct) o); @@ -193,7 +193,7 @@ private void searchScript(ResourceEntry entry, BcsResource bcsfile) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -312,7 +312,7 @@ private void searchText(ResourceEntry entry, PlainTextResource text) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/search/SearchFrame.java b/src/org/infinity/search/SearchFrame.java index a51f24003..7714646fb 100644 --- a/src/org/infinity/search/SearchFrame.java +++ b/src/org/infinity/search/SearchFrame.java @@ -50,6 +50,7 @@ import org.infinity.resource.bcs.BcsResource; import org.infinity.resource.key.ResourceEntry; import org.infinity.util.Misc; +import org.tinylog.Logger; public final class SearchFrame extends ChildFrame implements ActionListener, ListSelectionListener, Runnable { // private static final SearchFrame SEARCH_FRAME = null; @@ -303,7 +304,7 @@ public void run() { String text = tfield.getText(); regex = Pattern.compile(text, isCase ? 0 : Pattern.CASE_INSENSITIVE); } catch (PatternSyntaxException e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(this, "Regular expression error:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); return; diff --git a/src/org/infinity/search/SearchResource.java b/src/org/infinity/search/SearchResource.java index 0153fa850..8ad4d2cfb 100644 --- a/src/org/infinity/search/SearchResource.java +++ b/src/org/infinity/search/SearchResource.java @@ -100,6 +100,7 @@ import org.infinity.util.Threading; import org.infinity.util.io.StreamUtils; import org.infinity.util.tuples.Couple; +import org.tinylog.Logger; public class SearchResource extends ChildFrame implements ActionListener, PropertyChangeListener, Runnable { private static final String[] OPTION_PANELS = { "ARE", "CRE", "EFF", "ITM", "PRO", "SPL", "STO", "VVC" }; @@ -129,7 +130,7 @@ public Void doInBackground() { try { init(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -239,10 +240,10 @@ public void run() { try { threadPool.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException e) { - e.printStackTrace(); + Logger.error(e); } } catch (Exception e) { - // ignored + Logger.trace(e); } // preparing results for output @@ -262,7 +263,7 @@ public void run() { } } } finally { - DebugTimer.getInstance().timerShow("Extended Search", DebugTimer.TimeFormat.MILLISECONDS); + Logger.info(DebugTimer.getInstance().getTimerFormatted("Extended Search")); blocker.setBlocked(false); bSearch.setEnabled(true); clBottomBar.show(pBottomBar, "buttons"); @@ -5781,7 +5782,7 @@ public void popupMenuWillBecomeVisible(PopupMenuEvent e) { setSelectedItem(item); } } catch (BadLocationException ble) { - ble.printStackTrace(); + Logger.error(ble); } } @@ -5912,7 +5913,7 @@ private void setText(String text) { super.remove(0, getLength()); super.insertString(0, text, null); } catch (BadLocationException e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/search/SongReferenceSearcher.java b/src/org/infinity/search/SongReferenceSearcher.java index 0d401cbab..b0a3ce94d 100644 --- a/src/org/infinity/search/SongReferenceSearcher.java +++ b/src/org/infinity/search/SongReferenceSearcher.java @@ -26,6 +26,7 @@ import org.infinity.util.IdsMap; import org.infinity.util.IdsMapCache; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Performs search of the specified song in the {@link AreResource areas}, {@link BcsResource scripts} and @@ -103,7 +104,7 @@ private void searchBcs(ResourceEntry entry, BcsResource bcs) { String text = decompiler.decompile(); searchText(entry, null, text); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/search/StringReferenceSearcher.java b/src/org/infinity/search/StringReferenceSearcher.java index 8e935af87..8a6a79fa2 100644 --- a/src/org/infinity/search/StringReferenceSearcher.java +++ b/src/org/infinity/search/StringReferenceSearcher.java @@ -25,6 +25,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.resource.sav.SavResource; import org.infinity.resource.text.PlainTextResource; +import org.tinylog.Logger; /** Performs search of the specified string reference in other resources. */ public final class StringReferenceSearcher extends AbstractReferenceSearcher { @@ -101,8 +102,7 @@ private void searchDialog(ResourceEntry entry, AbstractStruct dialog) { } } } catch (Exception e) { - System.out.println("Exception in " + dialog.getName() + " - " + sourceCode.getName()); - e.printStackTrace(); + Logger.error(e, "Exception in {} - {}", dialog.getName(), sourceCode.getName()); } } else if (o instanceof AbstractStruct) { searchDialog(entry, (AbstractStruct) o); @@ -141,7 +141,7 @@ private void searchScript(ResourceEntry entry, BcsResource bcsfile) { } } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/search/TextResourceSearcher.java b/src/org/infinity/search/TextResourceSearcher.java index 8dc6bf83a..d3a520a26 100644 --- a/src/org/infinity/search/TextResourceSearcher.java +++ b/src/org/infinity/search/TextResourceSearcher.java @@ -32,6 +32,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.TextResource; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; public final class TextResourceSearcher extends AbstractSearcher implements Runnable, ActionListener { private final ChildFrame inputFrame; @@ -177,9 +178,7 @@ protected Runnable newWorker(ResourceEntry entry) { } } } catch (IOException e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } advanceProgress(); diff --git a/src/org/infinity/search/advanced/AdvancedSearch.java b/src/org/infinity/search/advanced/AdvancedSearch.java index f1c28fcf4..eeec7bdc5 100644 --- a/src/org/infinity/search/advanced/AdvancedSearch.java +++ b/src/org/infinity/search/advanced/AdvancedSearch.java @@ -78,6 +78,7 @@ import org.infinity.util.Misc; import org.infinity.util.SimpleListModel; import org.infinity.util.Threading; +import org.tinylog.Logger; public class AdvancedSearch extends ChildFrame implements Runnable { /** Indicates how to evaluate filter matches against a resource. */ @@ -175,7 +176,7 @@ public Void doInBackground() { try { init(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return null; } @@ -570,7 +571,7 @@ public void run() { try { threadPool.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException e) { - e.printStackTrace(); + Logger.error(e); } } catch (Exception e) { // ignored @@ -596,7 +597,7 @@ public void run() { lResultsStatus.setText(String.format("(%d match%s in %d resource%s found)", found.size(), found.size() == 1 ? "" : "es", resourceCount, resourceCount == 1 ? "" : "s")); } finally { - DebugTimer.getInstance().timerShow("Advanced Search", DebugTimer.TimeFormat.MILLISECONDS); + Logger.info(DebugTimer.getInstance().getTimerFormatted("Advanced Search")); blocker.setBlocked(false); bSearch.setEnabled(true); clBottomBar.show(pBottomBar, STATUS_BUTTONS); @@ -676,7 +677,7 @@ private boolean importConfig(File xmlFile) { filterList.setSelectedIndex(0); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return false; } return true; @@ -688,7 +689,7 @@ private boolean exportConfig(File xmlFile) { return XmlConfig.Export(xmlFile, cbResourceTypes.getSelectedItem().toString(), getSelectedFilterMode(), getSearchOptions()); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); return false; } } diff --git a/src/org/infinity/search/advanced/AdvancedSearchWorker.java b/src/org/infinity/search/advanced/AdvancedSearchWorker.java index 9eda495d5..f9ecd1730 100644 --- a/src/org/infinity/search/advanced/AdvancedSearchWorker.java +++ b/src/org/infinity/search/advanced/AdvancedSearchWorker.java @@ -24,6 +24,7 @@ import org.infinity.resource.StructEntry; import org.infinity.resource.key.ResourceEntry; import org.infinity.search.ReferenceHitFrame; +import org.tinylog.Logger; /** * Worker class for performing a full match against a resource entry. @@ -203,7 +204,7 @@ private void collapseGroupFilters(Map, Set> groupCache iter.remove(); } } else { - System.err.println("Skipping unidentified group match"); + Logger.warn("Skipping unidentified group match"); iter.remove(); } } diff --git a/src/org/infinity/search/advanced/FilterInput.java b/src/org/infinity/search/advanced/FilterInput.java index f54b115fc..184e73a58 100644 --- a/src/org/infinity/search/advanced/FilterInput.java +++ b/src/org/infinity/search/advanced/FilterInput.java @@ -71,6 +71,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.resource.ui.ResourceListModel; import org.infinity.util.DataString; +import org.tinylog.Logger; /** * Input dialog for a advanced search filter definition. @@ -921,7 +922,7 @@ private void signalAwait(String name, int timeoutMs) { } signal.await(timeoutMs, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/search/advanced/XmlConfig.java b/src/org/infinity/search/advanced/XmlConfig.java index dc42e07a5..3b7166c41 100644 --- a/src/org/infinity/search/advanced/XmlConfig.java +++ b/src/org/infinity/search/advanced/XmlConfig.java @@ -27,6 +27,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.tinylog.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -151,7 +152,7 @@ public static boolean Export(OutputStream xmlOut, String resourceType, AdvancedS try { builder = domFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { - e.printStackTrace(); + Logger.error(e); return false; } Document document = builder.newDocument(); @@ -318,7 +319,7 @@ public static boolean Export(OutputStream xmlOut, String resourceType, AdvancedS StreamResult sr = new StreamResult(xmlOut); transformer.transform(domSource, sr); } catch (TransformerException e) { - e.printStackTrace(); + Logger.error(e); return false; } @@ -386,17 +387,17 @@ public static XmlConfig Import(InputStream xmlIn) throws IOException, ParserConf builder.setErrorHandler(new ErrorHandler() { @Override public void warning(SAXParseException exception) throws SAXException { - exception.printStackTrace(); + Logger.error(exception); } @Override public void fatalError(SAXParseException exception) throws SAXException { - exception.printStackTrace(); + Logger.error(exception); } @Override public void error(SAXParseException exception) throws SAXException { - exception.printStackTrace(); + Logger.error(exception); } }); @@ -1028,7 +1029,7 @@ private int parseNumber(String text) throws NumberFormatException { // sb.append(c); // isEntity = true; // } catch (NumberFormatException e) { - // e.printStackTrace(); + // Logger.error(e); // } // } // } diff --git a/src/org/infinity/tinylog.License.txt b/src/org/infinity/tinylog.License.txt new file mode 100644 index 000000000..f433b1a53 --- /dev/null +++ b/src/org/infinity/tinylog.License.txt @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/src/org/infinity/updater/UpdateInfo.java b/src/org/infinity/updater/UpdateInfo.java index 2f2f0c433..1405a9eb2 100644 --- a/src/org/infinity/updater/UpdateInfo.java +++ b/src/org/infinity/updater/UpdateInfo.java @@ -28,6 +28,7 @@ import org.infinity.util.tuples.Couple; import org.json.JSONArray; import org.json.JSONObject; +import org.tinylog.Logger; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; @@ -570,7 +571,7 @@ private void parseJson(String jsonString) throws Exception { reactions = new Reactions(root.getJSONObject(key)); break; default: - System.out.printf("Release parser: Skipping unknown key \"%s\"\n", key); + Logger.info("Release parser: Skipping unknown key \"{}\"", key); } } @@ -722,7 +723,7 @@ private User(JSONObject jsonUser) throws Exception { siteAdmin = root.getBoolean(key); break; default: - System.out.printf("User parser: Skipping unknown key \"%s\"\n", key); + Logger.info("User parser: Skipping unknown key \"{}\"", key); } } @@ -870,7 +871,7 @@ private Asset(JSONObject jsonAsset) throws Exception { browserDownloadUrl = new URL(root.getString(key)); break; default: - System.out.printf("Asset parser: Skipping unknown key \"%s\"\n", key); + Logger.info("Asset parser: Skipping unknown key \"{}\"", key); } } @@ -972,7 +973,7 @@ private Reactions(JSONObject jsonReactions) throws Exception { eyes = root.getInt(key); break; default: - System.out.printf("Reactions parser: Skipping unknown key \"%s\"\n", key); + Logger.info("Reactions parser: Skipping unknown key \"{}\"", key); } } diff --git a/src/org/infinity/updater/Updater.java b/src/org/infinity/updater/Updater.java index 77a0521f9..1354a595a 100644 --- a/src/org/infinity/updater/Updater.java +++ b/src/org/infinity/updater/Updater.java @@ -30,6 +30,7 @@ import org.infinity.NearInfinity; import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; +import org.tinylog.Logger; /** * Provides functions for checking, downloading and updating new versions of Near Infinity. @@ -545,7 +546,7 @@ public void loadUpdateSettings() { try { autoCheckDate = Utils.getDateTimeFromString(dateTime); } catch (DateTimeParseException e) { - System.out.println("DateTimeParseException: " + e.getMessage()); + Logger.warn("DateTimeParseException: {}", e.getMessage()); autoCheckDate = OffsetDateTime.now(); } diff --git a/src/org/infinity/updater/Utils.java b/src/org/infinity/updater/Utils.java index 561b86ee0..9296c070f 100644 --- a/src/org/infinity/updater/Utils.java +++ b/src/org/infinity/updater/Utils.java @@ -46,6 +46,7 @@ import org.infinity.util.LauncherUtils; import org.infinity.util.io.FileEx; +import org.tinylog.Logger; /** * Generic collection of updater-related methods. @@ -187,7 +188,7 @@ public static String generateMD5Hash(InputStream is) { return sb.toString(); } catch (NoSuchAlgorithmException | IOException ioe) { - ioe.printStackTrace(); + Logger.error(ioe); } } return ""; diff --git a/src/org/infinity/util/CharsetDetector.java b/src/org/infinity/util/CharsetDetector.java index c7f1f53d4..7473879ff 100644 --- a/src/org/infinity/util/CharsetDetector.java +++ b/src/org/infinity/util/CharsetDetector.java @@ -16,6 +16,7 @@ import org.infinity.resource.Profile; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * This class provides methods to determine character sets and conversions for selected games and languages. @@ -190,7 +191,7 @@ public static String guessCharset(boolean detect) { } ch.close(); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/util/CreMapCache.java b/src/org/infinity/util/CreMapCache.java index 70deb28f3..04a024ada 100644 --- a/src/org/infinity/util/CreMapCache.java +++ b/src/org/infinity/util/CreMapCache.java @@ -19,6 +19,7 @@ import org.infinity.resource.are.AreResource; import org.infinity.resource.cre.CreResource; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; /** * Maintains a list of script names to CRE resource mappings. @@ -166,10 +167,10 @@ private static void initialize() { try { threadPool.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException e) { - e.printStackTrace(); + Logger.error(e); } } catch (Exception e) { - // ignored + Logger.trace(e); } if (statusBar != null && statusBar.getMessage().startsWith(message)) { @@ -196,9 +197,7 @@ public void run() { try { CreResource.addScriptName(SCRIPT_NAMES_CRE, entry); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } } @@ -215,9 +214,7 @@ public void run() { try { AreResource.addScriptNames(SCRIPT_NAMES_ARE, entry.getResourceBuffer()); } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } } @@ -250,9 +247,7 @@ public void run() { } } } catch (Exception e) { - synchronized (System.err) { - e.printStackTrace(); - } + Logger.error(e); } } } diff --git a/src/org/infinity/util/DebugTimer.java b/src/org/infinity/util/DebugTimer.java index 0b82f8eac..4011f8143 100644 --- a/src/org/infinity/util/DebugTimer.java +++ b/src/org/infinity/util/DebugTimer.java @@ -58,7 +58,11 @@ public String toString(long nanos) { /** Static class instance for global access to the timer. */ private static final DebugTimer INSTANCE = new DebugTimer(); - /** Provides access to the global instance of the {@code Debugging} class. */ + /** + * Provides access to the global instance of the {@code DebugTimer} class. + * + *

The global {@code DebugTimer} instance defines {@link TimeFormat#MILLISECONDS} as default.

+ */ public static synchronized DebugTimer getInstance() { return INSTANCE; } @@ -68,7 +72,7 @@ public static synchronized DebugTimer getInstance() { /** Creates a new {@code Debugging} object with the default time format {@link TimeFormat#MILLISECONDS}. */ public DebugTimer() { - this(null); + this(TimeFormat.MILLISECONDS); } /** @@ -88,29 +92,49 @@ public synchronized DebugTimer timerReset() { } /** - * Shows the elapsed time in the default time format and resets timer. + * Prints the elapsed time in the default time format. * - * @param message Display an optional message + * @return A formatted string of the elapsed time. */ - public DebugTimer timerShow(String message) { - return timerShow(message, getDefaultTimeFormat()); + public String getTimerFormatted() { + return getTimerFormatted(null, getDefaultTimeFormat()); } /** - * Shows the elapsed time in the specified time format. + * Prints the elapsed time in the specified time format. * - * @param message Display an optional message - * @param format The temporal resolution of the elapsed time + * @param format The temporal resolution of the elapsed time. + * @return A formatted string of the elapsed time. + */ + public String getTimerFormatted(TimeFormat format) { + return getTimerFormatted(null, format); + } + + /** + * Prints the elapsed time in the default time format with an optional message. + * + * @param message Optional message to show. Specify {@code null} or an empty string to omit this message. + * @return A formatted string with optional message and elapsed time. */ - public DebugTimer timerShow(String message, TimeFormat format) { + public String getTimerFormatted(String message) { + return getTimerFormatted(message, getDefaultTimeFormat()); + } + + /** + * Prints the elapsed time in the specified time format with an optional message. + * + * @param message Optional message to show. Specify {@code null} or an empty string to omit this message. + * @param format The temporal resolution of the elapsed time. + * @return A formatted string with optional message and elapsed time. + */ + public String getTimerFormatted(String message, TimeFormat format) { final long timeDiff = timerGetRaw(); format = getTimeFormat(format); if (message != null && !message.isEmpty()) { - System.out.println("[" + message + "] " + format.toString(timeDiff)); + return "[" + message + "] " + format.toString(timeDiff); } else { - System.out.println(format.toString(timeDiff)); + return format.toString(timeDiff); } - return this; } /** @@ -142,9 +166,16 @@ public TimeFormat getDefaultTimeFormat() { * Defines a new default {@link TimeFormat} for use with the non-parameterized methods for getting the * timer value. * + *

Note: The time format cannot be modified for the global {@code DebugTimer} instance + * and throws a {@link UnsupportedOperationException}.

+ * * @param newTimeFormat new default {@link TimeFormat}. + * @throws UnsupportedOperationException if this method is invoked by the global {@link DebugTimer} instance. */ public void setDefaultTimeFormat(TimeFormat newTimeFormat) { + if (this == INSTANCE) { + throw new UnsupportedOperationException("Default time format cannot be modified for the global instance"); + } this.defaultFormat = (newTimeFormat != null) ? newTimeFormat : TimeFormat.MILLISECONDS; } diff --git a/src/org/infinity/util/IdsMap.java b/src/org/infinity/util/IdsMap.java index 338144beb..0475def61 100644 --- a/src/org/infinity/util/IdsMap.java +++ b/src/org/infinity/util/IdsMap.java @@ -34,7 +34,7 @@ public IdsMap(ResourceEntry entry) throws Exception { parse2DA(); } // } catch (Exception e) { -// e.printStackTrace(); +// Logger.error(e); // } } diff --git a/src/org/infinity/util/IdsMapCache.java b/src/org/infinity/util/IdsMapCache.java index 2fb87a3d3..91f6a0dfd 100644 --- a/src/org/infinity/util/IdsMapCache.java +++ b/src/org/infinity/util/IdsMapCache.java @@ -16,6 +16,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.bcs.ScriptInfo; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; public class IdsMapCache { /** Maps upper-cased name of IDS resource to parsed resource. */ @@ -53,7 +54,7 @@ public static synchronized IdsMap get(String name) { if (name.equals("ATTSTYLE.IDS")) { entry = ResourceFactory.getResourceEntry("ATTSTYL.IDS"); } else { - System.err.println("Could not find " + name); + Logger.warn("Could not find {}", name); } } if (entry != null) { @@ -61,7 +62,7 @@ public static synchronized IdsMap get(String name) { retVal = new IdsMap(entry); CACHE.put(name, retVal); } catch (Exception e) { - System.err.println(e.getMessage()); + Logger.warn("{}: {}", e.getClass().getSimpleName(), e.getMessage()); } } } diff --git a/src/org/infinity/util/IniMap.java b/src/org/infinity/util/IniMap.java index dda362d4e..262cd46bf 100644 --- a/src/org/infinity/util/IniMap.java +++ b/src/org/infinity/util/IniMap.java @@ -14,6 +14,7 @@ import org.infinity.resource.key.ResourceEntry; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Parses Infinity Engine INI files. @@ -215,7 +216,7 @@ private static String readResource(ResourceEntry entry) { final ByteBuffer bb = entry.getResourceBuffer(); return StreamUtils.readString(bb, bb.limit(), Misc.CHARSET_DEFAULT); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } return null; diff --git a/src/org/infinity/util/IniMapCache.java b/src/org/infinity/util/IniMapCache.java index 15d2329fd..28edbaf89 100644 --- a/src/org/infinity/util/IniMapCache.java +++ b/src/org/infinity/util/IniMapCache.java @@ -9,6 +9,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.key.ResourceEntry; +import org.tinylog.Logger; public class IniMapCache { private static final HashMap MAP = new HashMap<>(); @@ -35,7 +36,7 @@ public static IniMap get(String name, boolean ignoreComments) { if (entry != null) { retVal = get(entry, ignoreComments); } else { - System.err.println("Could not find " + name); + Logger.warn("Could not find {}", name); } } return retVal; diff --git a/src/org/infinity/util/IniMapEntry.java b/src/org/infinity/util/IniMapEntry.java index 01be7f56f..bb627a6b7 100644 --- a/src/org/infinity/util/IniMapEntry.java +++ b/src/org/infinity/util/IniMapEntry.java @@ -11,6 +11,7 @@ import java.util.regex.PatternSyntaxException; import org.infinity.datatype.StringRef; +import org.tinylog.Logger; public class IniMapEntry { /** Regular expression that can be used to split position values in {@link #splitValues(String, String)}. */ @@ -108,7 +109,7 @@ public static String[] splitValues(String value, String pattern) { results.add(value.substring(matcher.start(), matcher.end())); } } catch (PatternSyntaxException e) { - e.printStackTrace(); + Logger.error(e); } retVal = new String[results.size()]; for (int i = 0; i < results.size(); i++) { @@ -138,7 +139,7 @@ public static int[] splitObjectValue(String value) { try { retVal[i] = Integer.parseInt(results.get(i)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -165,7 +166,7 @@ public static int[] splitPositionValue(String value) { try { retVal[i] = Integer.parseInt(results.get(i)); } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/util/LauncherUtils.java b/src/org/infinity/util/LauncherUtils.java index 368c52eae..bf2da40f0 100644 --- a/src/org/infinity/util/LauncherUtils.java +++ b/src/org/infinity/util/LauncherUtils.java @@ -12,6 +12,8 @@ import java.net.URL; import java.nio.file.Path; +import org.tinylog.Logger; + /** * A helper class for launching default applications associated with the specified file or URL arguments. */ @@ -140,7 +142,7 @@ private static boolean xdgOpen(String arg) { p.waitFor(); retVal = true; } catch (IOException | InterruptedException e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/util/MassExporter.java b/src/org/infinity/util/MassExporter.java index 90c1b5628..7e7547663 100644 --- a/src/org/infinity/util/MassExporter.java +++ b/src/org/infinity/util/MassExporter.java @@ -86,6 +86,7 @@ import org.infinity.util.io.FileEx; import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; public final class MassExporter extends ChildFrame implements ActionListener, ListSelectionListener, DocumentListener, Runnable { private static final String FMT_PROGRESS = "Processing resource %d/%d"; @@ -301,7 +302,7 @@ public void actionPerformed(ActionEvent event) { try { pattern = getPattern(); } catch (IllegalArgumentException e) { - e.printStackTrace(); + Logger.error(e); JOptionPane.showMessageDialog(this, e.getMessage(), "Pattern syntax error", JOptionPane.ERROR_MESSAGE); if (e instanceof PatternSyntaxException) { final int index = ((PatternSyntaxException)e).getIndex(); @@ -319,7 +320,7 @@ public void actionPerformed(ActionEvent event) { Files.createDirectories(outputPath); } catch (IOException e) { JOptionPane.showMessageDialog(this, "Unable to create target directory.", "Error", JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); + Logger.error(e); return; } setVisible(false); @@ -458,7 +459,7 @@ public void run() { } selectedFiles = null; } - DebugTimer.getInstance().timerShow("Mass export completed", DebugTimer.TimeFormat.MILLISECONDS); + Logger.info(DebugTimer.getInstance().getTimerFormatted("Mass export completed")); } // --------------------- End Interface Runnable --------------------- @@ -679,13 +680,13 @@ private void extractBamFrames(ResourceEntry entry, Path output) throws Exception Files.createDirectory(path); } catch (IOException e) { String msg = String.format("Error creating folder \"%s\". Skipping file \"%s\".", fileBase, fileName); - System.err.println(msg); + Logger.warn(msg); JOptionPane.showMessageDialog(NearInfinity.getInstance(), msg, "Error", JOptionPane.ERROR_MESSAGE); return; } } else if (!FileEx.create(path).isDirectory()) { String msg = String.format("Folder \"%s\" can not be created. Skipping file \"%s\".", fileBase, fileName); - System.err.println(msg); + Logger.warn(msg); JOptionPane.showMessageDialog(NearInfinity.getInstance(), msg, "Error", JOptionPane.ERROR_MESSAGE); return; } @@ -715,7 +716,7 @@ private void chrToCre(ResourceEntry entry, Path output) throws Exception { private void exportResource(ResourceEntry entry, Path output) throws Exception { if (entry != null && output != null) { - System.err.println("Converting " + entry.toString()); + Logger.info("Converting {}", entry.toString()); int[] info = entry.getResourceInfo(); int size = info[0]; if (info.length > 1) { @@ -812,8 +813,8 @@ private void export(ResourceEntry entry) { exportResource(entry, output); } } catch (Exception e) { - System.err.println("Error in resource: " + entry.toString()); - e.printStackTrace(); + Logger.error(e, "Error in resource: {}", entry); + } } diff --git a/src/org/infinity/util/StringTable.java b/src/org/infinity/util/StringTable.java index cf50767f3..c2b5aaaac 100644 --- a/src/org/infinity/util/StringTable.java +++ b/src/org/infinity/util/StringTable.java @@ -29,6 +29,7 @@ import org.infinity.updater.Utils; import org.infinity.util.io.FileEx; import org.infinity.util.io.StreamUtils; +import org.tinylog.Logger; /** * Provides operations for reading, writing and querying information about string tables. @@ -129,7 +130,7 @@ public static boolean setCharset(String cs) { retVal = true; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } @@ -712,7 +713,7 @@ public static boolean writeModified(Type type, ProgressCallback callback) { instance(type)._writeModified(callback); retVal = true; } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -783,7 +784,7 @@ public static boolean exportText(Type type, Path outFile, ProgressCallback callb instance(type)._exportText(outFile, callback); retVal = true; } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } return retVal; @@ -931,7 +932,7 @@ public static boolean exportTra(Path outFile, ProgressCallback callback) { writer.println(); } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); retVal = false; } finally { if (callback != null) { @@ -1016,7 +1017,7 @@ private int _getTranslatedIndex(int index) { entriesVirtual.put(index, strref); index = strref; } catch (NumberFormatException e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -1109,7 +1110,7 @@ private void _init() { entriesPending = numEntries; initialized = true; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -1160,7 +1161,7 @@ private StringEntry _loadEntry(FileChannel ch, int index) text = CharsetDetector.getLookup().decodeString(text); } } catch (IllegalArgumentException e) { - System.err.println("Error: Illegal offset " + ofsString + " for string entry " + index); + Logger.error("Error: Illegal offset {} for string entry {}", ofsString, index); text = ""; } } else { @@ -1222,7 +1223,7 @@ private void _ensureFullyLoaded() { } entriesPending = 0; } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -1242,7 +1243,7 @@ private void _ensureIndexIsLoaded(int index) { throw new Exception(); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } @@ -1646,7 +1647,7 @@ public void fillList(int index) { addField(e); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/util/StructClipboard.java b/src/org/infinity/util/StructClipboard.java index dd7b23487..f633c5103 100644 --- a/src/org/infinity/util/StructClipboard.java +++ b/src/org/infinity/util/StructClipboard.java @@ -21,6 +21,7 @@ import org.infinity.resource.cre.CreResource; import org.infinity.resource.itm.ItmResource; import org.infinity.resource.spl.SplResource; +import org.tinylog.Logger; public final class StructClipboard { public static final int CLIPBOARD_EMPTY = 0; @@ -178,7 +179,7 @@ public int paste(AbstractStruct targetStruct) { ++i; } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } return lastIndex; } @@ -200,7 +201,7 @@ public int pasteValue(AbstractStruct struct, int index) { struct.setField(index + i, newEntry); } } catch (CloneNotSupportedException e) { - e.printStackTrace(); + Logger.error(e); return 0; } return contents.size(); @@ -219,7 +220,7 @@ private void copy(AbstractStruct struct, int firstIndex, int lastIndex, boolean contents.add(entry.clone()); } } catch (CloneNotSupportedException e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/util/Table2da.java b/src/org/infinity/util/Table2da.java index fdc2a99f8..5c030d2b5 100644 --- a/src/org/infinity/util/Table2da.java +++ b/src/org/infinity/util/Table2da.java @@ -10,6 +10,7 @@ import org.infinity.resource.ResourceFactory; import org.infinity.resource.key.ResourceEntry; import org.infinity.resource.text.PlainTextResource; +import org.tinylog.Logger; /** * Stores content of a 2DA resource as table. @@ -187,7 +188,7 @@ private void init(ResourceEntry entry) { defaultValue = new Entry(this, "0", 1, 0); } } catch (Exception e) { - e.printStackTrace(); + Logger.error(e); } } diff --git a/src/org/infinity/util/io/DlcManager.java b/src/org/infinity/util/io/DlcManager.java index 407136aa8..cee51db46 100644 --- a/src/org/infinity/util/io/DlcManager.java +++ b/src/org/infinity/util/io/DlcManager.java @@ -16,6 +16,7 @@ import org.infinity.util.io.zip.DlcFileSystem; import org.infinity.util.io.zip.DlcFileSystemProvider; +import org.tinylog.Logger; /** * Manages available DLCs used by the current game. @@ -106,7 +107,7 @@ private Path _queryKey(Path path) { return key; } } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } } } diff --git a/src/org/infinity/util/io/FileManager.java b/src/org/infinity/util/io/FileManager.java index 90f55aef3..184ae60ec 100644 --- a/src/org/infinity/util/io/FileManager.java +++ b/src/org/infinity/util/io/FileManager.java @@ -18,6 +18,8 @@ import java.util.Locale; import java.util.Objects; +import org.tinylog.Logger; + /** * Central hub for accessing game-related I/O resources. @@ -336,7 +338,7 @@ private static Path queryPath(List rootPaths, String[] paths, boolean must break; } } catch (IllegalArgumentException e) { -// e.printStackTrace(); + Logger.trace(e); } } } diff --git a/src/org/infinity/util/io/StreamUtils.java b/src/org/infinity/util/io/StreamUtils.java index b771501cb..b4cead272 100644 --- a/src/org/infinity/util/io/StreamUtils.java +++ b/src/org/infinity/util/io/StreamUtils.java @@ -23,6 +23,7 @@ import java.util.zip.ZipOutputStream; import org.infinity.util.Misc; +import org.tinylog.Logger; /** * Collection of useful stream- and buffer-based operations. @@ -215,7 +216,7 @@ public static int copyBytes(ByteBuffer src, int srcOffset, ByteBuffer dst, int d bufTmp.limit(bufTmp.position() + maxLength); dst.put(bufTmp); } catch (Throwable t) { - t.printStackTrace(); + Logger.error(t); } finally { src.position(srcPos); dst.position(dstPos); @@ -783,7 +784,7 @@ public static void createZip(Path sourceDir, Path zipFile, boolean includeFolder Files.copy(path, zos); zos.closeEntry(); } catch (IOException e) { - e.printStackTrace(); + Logger.error(e); } }); } diff --git a/src/org/infinity/util/io/zip/ZipCoder.java b/src/org/infinity/util/io/zip/ZipCoder.java index 67d944d09..71e78573b 100644 --- a/src/org/infinity/util/io/zip/ZipCoder.java +++ b/src/org/infinity/util/io/zip/ZipCoder.java @@ -44,6 +44,8 @@ import java.nio.charset.CodingErrorAction; import java.util.Arrays; +import org.tinylog.Logger; + /** * Utility class for zipfile name and comment decoding and encoding. */ @@ -139,7 +141,7 @@ static ZipCoder get(String csn) { try { return new ZipCoder(Charset.forName(csn)); } catch (Throwable t) { - t.printStackTrace(); + Logger.error(t); } return new ZipCoder(Charset.defaultCharset()); } diff --git a/src/tinylog.properties b/src/tinylog.properties new file mode 100644 index 000000000..217bf6ccd --- /dev/null +++ b/src/tinylog.properties @@ -0,0 +1,5 @@ +writer = console +writer.level = debug +writer.format = {level}: {message} +writer.stream = err@WARN +writingthread = true