From 5fa157c9a247f0a8a659d2d0baf1ed0aae66a2b3 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 20 Sep 2024 11:03:33 -0400 Subject: [PATCH] log stack traces at warn or error level --- .../main/java/haveno/apitest/ApiTestMain.java | 2 +- build.gradle | 1 + .../src/main/java/haveno/common/app/Log.java | 2 +- .../java/haveno/common/file/FileUtil.java | 8 ++--- .../java/haveno/common/setup/CommonSetup.java | 9 ++---- .../haveno/common/taskrunner/TaskRunner.java | 6 ++-- .../java/haveno/common/util/Utilities.java | 3 +- .../haveno/core/api/CoreDisputesService.java | 5 ++- .../haveno/core/api/CoreTradesService.java | 4 ++- .../haveno/core/api/XmrConnectionService.java | 12 ++++--- .../haveno/core/app/HavenoExecutable.java | 10 +++--- .../java/haveno/core/app/HavenoSetup.java | 3 +- .../main/java/haveno/core/app/TorSetup.java | 6 ++-- .../app/misc/ExecutableForAppWithP2p.java | 5 ++- .../haveno/core/offer/OpenOfferManager.java | 8 ++--- .../haveno/core/provider/fee/FeeProvider.java | 3 +- .../core/provider/price/PriceProvider.java | 3 +- .../core/support/dispute/DisputeManager.java | 12 ++++--- .../dispute/DisputeSummaryVerification.java | 4 +-- .../arbitration/ArbitrationManager.java | 7 ++-- .../main/java/haveno/core/trade/Trade.java | 9 ++---- .../java/haveno/core/trade/TradeManager.java | 12 +++---- .../ArbitratorProcessDepositRequest.java | 7 ++-- .../tasks/ArbitratorProcessReserveTx.java | 4 ++- ...eResendDisputeClosedMessageWithPayout.java | 2 +- .../ProcessDepositsConfirmedMessage.java | 2 +- .../core/trade/protocol/tasks/TradeTask.java | 2 +- .../haveno/core/xmr/wallet/XmrWalletBase.java | 4 ++- .../core/xmr/wallet/XmrWalletService.java | 32 +++++++++---------- .../windows/DisputeSummaryWindow.java | 3 +- .../portfolio/pendingtrades/TradeSubView.java | 3 +- .../haveno/desktop/main/shared/ChatView.java | 13 +++----- .../haveno/network/Socks5ProxyProvider.java | 4 +-- .../java/haveno/network/p2p/P2PService.java | 9 +++--- .../p2p/mailbox/MailboxMessageList.java | 3 +- .../p2p/mailbox/MailboxMessageService.java | 6 ++-- .../network/p2p/network/Connection.java | 11 +++---- .../p2p/network/LocalhostNetworkNode.java | 3 +- .../haveno/network/p2p/network/Server.java | 5 ++- .../network/p2p/storage/P2PDataStorage.java | 3 +- .../p2p/storage/persistence/StoreService.java | 3 +- .../java/haveno/seednode/SeedNodeMain.java | 2 +- 42 files changed, 117 insertions(+), 138 deletions(-) diff --git a/apitest/src/main/java/haveno/apitest/ApiTestMain.java b/apitest/src/main/java/haveno/apitest/ApiTestMain.java index 4da4b92061..ad383ff1ef 100644 --- a/apitest/src/main/java/haveno/apitest/ApiTestMain.java +++ b/apitest/src/main/java/haveno/apitest/ApiTestMain.java @@ -78,7 +78,7 @@ public class ApiTestMain { } catch (Throwable ex) { err.println("Fault: An unexpected error occurred. " + - "Please file a report at https://haveno.exchange/issues"); + "Please file a report at https://github.com/haveno-dex/haveno/issues"); ex.printStackTrace(err); exit(EXIT_FAILURE); } diff --git a/build.gradle b/build.gradle index 22657efd6f..bcd7d082b0 100644 --- a/build.gradle +++ b/build.gradle @@ -334,6 +334,7 @@ configure(project(':p2p')) { implementation "com.google.protobuf:protobuf-java:$protobufVersion" implementation "org.fxmisc.easybind:easybind:$easybindVersion" implementation "org.slf4j:slf4j-api:$slf4jVersion" + implementation "org.apache.commons:commons-lang3:$langVersion" implementation("com.github.haveno-dex.netlayer:tor.external:$netlayerVersion") { exclude(module: 'slf4j-api') } diff --git a/common/src/main/java/haveno/common/app/Log.java b/common/src/main/java/haveno/common/app/Log.java index d02870c990..67ca2ab9ed 100644 --- a/common/src/main/java/haveno/common/app/Log.java +++ b/common/src/main/java/haveno/common/app/Log.java @@ -91,7 +91,7 @@ public class Log { errorTriggeringPolicy.start(); ThresholdFilter thresholdFilter = new ThresholdFilter(); - thresholdFilter.setLevel("ERROR"); + thresholdFilter.setLevel("WARN"); thresholdFilter.start(); errorAppender.setRollingPolicy(errorRollingPolicy); diff --git a/common/src/main/java/haveno/common/file/FileUtil.java b/common/src/main/java/haveno/common/file/FileUtil.java index 449faea64b..27058f3025 100644 --- a/common/src/main/java/haveno/common/file/FileUtil.java +++ b/common/src/main/java/haveno/common/file/FileUtil.java @@ -68,8 +68,7 @@ public class FileUtil { pruneBackup(backupFileDir, numMaxBackupFiles); } catch (IOException e) { - log.error("Backup key failed: " + e.getMessage()); - e.printStackTrace(); + log.error("Backup key failed: {}\n", e.getMessage(), e); } } } @@ -97,7 +96,7 @@ public class FileUtil { try { FileUtils.deleteDirectory(backupFileDir); } catch (IOException e) { - e.printStackTrace(); + log.error("Delete backup key failed: {}\n", e.getMessage(), e); } } @@ -173,8 +172,7 @@ public class FileUtil { } } } catch (Throwable t) { - log.error(t.toString()); - t.printStackTrace(); + log.error("Could not delete file, error={}\n", t.getMessage(), t); throw new IOException(t); } } diff --git a/common/src/main/java/haveno/common/setup/CommonSetup.java b/common/src/main/java/haveno/common/setup/CommonSetup.java index f606d3b534..0c929b3ae4 100644 --- a/common/src/main/java/haveno/common/setup/CommonSetup.java +++ b/common/src/main/java/haveno/common/setup/CommonSetup.java @@ -69,11 +69,7 @@ public class CommonSetup { "The system tray is not supported on the current platform.".equals(throwable.getMessage())) { log.warn(throwable.getMessage()); } else { - log.error("Uncaught Exception from thread " + Thread.currentThread().getName()); - log.error("throwableMessage= " + throwable.getMessage()); - log.error("throwableClass= " + throwable.getClass()); - log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable)); - throwable.printStackTrace(); + log.error("Uncaught Exception from thread {}, error={}\n", Thread.currentThread().getName(), throwable.getMessage(), throwable); UserThread.execute(() -> uncaughtExceptionHandler.handleUncaughtException(throwable, false)); } }; @@ -113,8 +109,7 @@ public class CommonSetup { if (!pathOfCodeSource.endsWith("classes")) log.info("Path to Haveno jar file: " + pathOfCodeSource); } catch (URISyntaxException e) { - log.error(e.toString()); - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); } } } diff --git a/common/src/main/java/haveno/common/taskrunner/TaskRunner.java b/common/src/main/java/haveno/common/taskrunner/TaskRunner.java index e49b4ccd91..087ffce702 100644 --- a/common/src/main/java/haveno/common/taskrunner/TaskRunner.java +++ b/common/src/main/java/haveno/common/taskrunner/TaskRunner.java @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; +import org.apache.commons.lang3.exception.ExceptionUtils; + @Slf4j public class TaskRunner { private final Queue>> tasks = new LinkedBlockingQueue<>(); @@ -67,8 +69,8 @@ public class TaskRunner { log.info("Run task: " + currentTask.getSimpleName()); currentTask.getDeclaredConstructor(TaskRunner.class, sharedModelClass).newInstance(this, sharedModel).run(); } catch (Throwable throwable) { - throwable.printStackTrace(); - handleErrorMessage("Error at taskRunner: " + throwable.getMessage()); + log.error(ExceptionUtils.getStackTrace(throwable)); + handleErrorMessage("Error at taskRunner, error=" + throwable.getMessage()); } } else { resultHandler.handleResult(); diff --git a/common/src/main/java/haveno/common/util/Utilities.java b/common/src/main/java/haveno/common/util/Utilities.java index b4afe417e8..240ea49ee9 100644 --- a/common/src/main/java/haveno/common/util/Utilities.java +++ b/common/src/main/java/haveno/common/util/Utilities.java @@ -331,8 +331,7 @@ public class Utilities { clipboard.setContent(clipboardContent); } } catch (Throwable e) { - log.error("copyToClipboard failed " + e.getMessage()); - e.printStackTrace(); + log.error("copyToClipboard failed: {}\n", e.getMessage(), e); } } diff --git a/core/src/main/java/haveno/core/api/CoreDisputesService.java b/core/src/main/java/haveno/core/api/CoreDisputesService.java index 7edbed9b01..f193287edc 100644 --- a/core/src/main/java/haveno/core/api/CoreDisputesService.java +++ b/core/src/main/java/haveno/core/api/CoreDisputesService.java @@ -52,6 +52,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Optional; + +import org.apache.commons.lang3.exception.ExceptionUtils; + import lombok.extern.slf4j.Slf4j; @@ -204,7 +207,7 @@ public class CoreDisputesService { throw new IllegalStateException(errMessage, err); }); } catch (Exception e) { - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); throw new IllegalStateException(e.getMessage() == null ? ("Error resolving dispute for trade " + trade.getId()) : e.getMessage()); } } diff --git a/core/src/main/java/haveno/core/api/CoreTradesService.java b/core/src/main/java/haveno/core/api/CoreTradesService.java index 16fa22a8db..431ab9a652 100644 --- a/core/src/main/java/haveno/core/api/CoreTradesService.java +++ b/core/src/main/java/haveno/core/api/CoreTradesService.java @@ -66,6 +66,8 @@ import java.util.List; import java.util.Optional; import java.util.function.Consumer; import lombok.extern.slf4j.Slf4j; + +import org.apache.commons.lang3.exception.ExceptionUtils; import org.bitcoinj.core.Coin; @Singleton @@ -161,7 +163,7 @@ class CoreTradesService { errorMessageHandler ); } catch (Exception e) { - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); errorMessageHandler.handleErrorMessage(e.getMessage()); } } diff --git a/core/src/main/java/haveno/core/api/XmrConnectionService.java b/core/src/main/java/haveno/core/api/XmrConnectionService.java index 4465fd2a35..2541fb9fc5 100644 --- a/core/src/main/java/haveno/core/api/XmrConnectionService.java +++ b/core/src/main/java/haveno/core/api/XmrConnectionService.java @@ -41,6 +41,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; + +import org.apache.commons.lang3.exception.ExceptionUtils; + import javafx.beans.property.IntegerProperty; import javafx.beans.property.LongProperty; import javafx.beans.property.ObjectProperty; @@ -464,7 +467,7 @@ public final class XmrConnectionService { log.info(getClass() + ".onAccountOpened() called"); initialize(); } catch (Exception e) { - e.printStackTrace(); + log.error("Error initializing connection service after account opened, error={}\n", e.getMessage(), e); throw new RuntimeException(e); } } @@ -622,8 +625,7 @@ public final class XmrConnectionService { log.info("Starting local node"); xmrLocalNode.startMoneroNode(); } catch (Exception e) { - log.warn("Unable to start local monero node: " + e.getMessage()); - e.printStackTrace(); + log.error("Unable to start local monero node, error={}\n", e.getMessage(), e); } } } @@ -721,8 +723,8 @@ public final class XmrConnectionService { // log error message periodically if (lastLogPollErrorTimestamp == null || System.currentTimeMillis() - lastLogPollErrorTimestamp > HavenoUtils.LOG_POLL_ERROR_PERIOD_MS) { - log.warn("Failed to fetch daemon info, trying to switch to best connection: " + e.getMessage()); - if (DevEnv.isDevMode()) e.printStackTrace(); + log.warn("Failed to fetch daemon info, trying to switch to best connection, error={}", e.getMessage()); + if (DevEnv.isDevMode()) log.error(ExceptionUtils.getStackTrace(e)); lastLogPollErrorTimestamp = System.currentTimeMillis(); } diff --git a/core/src/main/java/haveno/core/app/HavenoExecutable.java b/core/src/main/java/haveno/core/app/HavenoExecutable.java index e213bdd688..aa25b12dc6 100644 --- a/core/src/main/java/haveno/core/app/HavenoExecutable.java +++ b/core/src/main/java/haveno/core/app/HavenoExecutable.java @@ -124,7 +124,7 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven System.exit(EXIT_FAILURE); } catch (Throwable ex) { System.err.println("fault: An unexpected error occurred. " + - "Please file a report at https://haveno.exchange/issues"); + "Please file a report at https://github.com/haveno-dex/haveno/issues"); ex.printStackTrace(System.err); System.exit(EXIT_FAILURE); } @@ -201,8 +201,7 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven startApplication(); } } catch (InterruptedException | ExecutionException e) { - log.error("An error occurred: {}", e.getMessage()); - e.printStackTrace(); + log.error("An error occurred: {}\n", e.getMessage(), e); } }); } @@ -362,7 +361,7 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven try { ThreadUtils.awaitTasks(tasks, tasks.size(), 90000l); // run in parallel with timeout } catch (Exception e) { - e.printStackTrace(); + log.error("Failed to notify all services to prepare for shutdown: {}\n", e.getMessage(), e); } injector.getInstance(TradeManager.class).shutDown(); @@ -397,8 +396,7 @@ public abstract class HavenoExecutable implements GracefulShutDownHandler, Haven }); }); } catch (Throwable t) { - log.error("App shutdown failed with exception {}", t.toString()); - t.printStackTrace(); + log.error("App shutdown failed with exception: {}\n", t.getMessage(), t); completeShutdown(resultHandler, EXIT_FAILURE, systemExit); } } diff --git a/core/src/main/java/haveno/core/app/HavenoSetup.java b/core/src/main/java/haveno/core/app/HavenoSetup.java index 0d1ee2b996..2c2e95fd3b 100644 --- a/core/src/main/java/haveno/core/app/HavenoSetup.java +++ b/core/src/main/java/haveno/core/app/HavenoSetup.java @@ -376,8 +376,7 @@ public class HavenoSetup { moneroWalletRpcFile.setExecutable(true); } } catch (Exception e) { - e.printStackTrace(); - log.warn("Failed to install Monero binaries: " + e.toString()); + log.warn("Failed to install Monero binaries: {}\n", e.getMessage(), e); } } diff --git a/core/src/main/java/haveno/core/app/TorSetup.java b/core/src/main/java/haveno/core/app/TorSetup.java index d878464af2..c28e509ecc 100644 --- a/core/src/main/java/haveno/core/app/TorSetup.java +++ b/core/src/main/java/haveno/core/app/TorSetup.java @@ -28,6 +28,9 @@ import java.io.File; import java.io.IOException; import java.nio.file.Paths; import javax.annotation.Nullable; + +import org.apache.commons.lang3.exception.ExceptionUtils; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -48,8 +51,7 @@ public class TorSetup { if (resultHandler != null) resultHandler.run(); } catch (IOException e) { - e.printStackTrace(); - log.error(e.toString()); + log.error(ExceptionUtils.getStackTrace(e)); if (errorMessageHandler != null) errorMessageHandler.handleErrorMessage(e.toString()); } diff --git a/core/src/main/java/haveno/core/app/misc/ExecutableForAppWithP2p.java b/core/src/main/java/haveno/core/app/misc/ExecutableForAppWithP2p.java index 8086d563d1..725ccd877c 100644 --- a/core/src/main/java/haveno/core/app/misc/ExecutableForAppWithP2p.java +++ b/core/src/main/java/haveno/core/app/misc/ExecutableForAppWithP2p.java @@ -123,7 +123,7 @@ public abstract class ExecutableForAppWithP2p extends HavenoExecutable { try { ThreadUtils.awaitTasks(tasks, tasks.size(), 120000l); // run in parallel with timeout } catch (Exception e) { - e.printStackTrace(); + log.error("Error awaiting tasks to complete: {}\n", e.getMessage(), e); } JsonFileManager.shutDownAllInstances(); @@ -177,8 +177,7 @@ public abstract class ExecutableForAppWithP2p extends HavenoExecutable { }, 1); } } catch (Throwable t) { - log.debug("App shutdown failed with exception"); - t.printStackTrace(); + log.info("App shutdown failed with exception: {}\n", t.getMessage(), t); PersistenceManager.flushAllDataToDiskAtShutdown(() -> { resultHandler.handleResult(); log.info("Graceful shutdown resulted in an error. Exiting now."); diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index aa561f127d..4824579dbf 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -977,7 +977,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // handle result resultHandler.handleResult(null); } catch (Exception e) { - if (!openOffer.isCanceled()) e.printStackTrace(); + if (!openOffer.isCanceled()) log.error("Error processing pending offer: {}\n", e.getMessage(), e); errorMessageHandler.handleErrorMessage(e.getMessage()); } }).start(); @@ -1365,9 +1365,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe }); result = true; } catch (Exception e) { - e.printStackTrace(); errorMessage = "Exception at handleSignOfferRequest " + e.getMessage(); - log.error(errorMessage); + log.error(errorMessage + "\n", e); } finally { sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), result, errorMessage); } @@ -1519,8 +1518,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe result = true; } catch (Throwable t) { errorMessage = "Exception at handleRequestIsOfferAvailableMessage " + t.getMessage(); - log.error(errorMessage); - t.printStackTrace(); + log.error(errorMessage + "\n", t); } finally { sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), result, errorMessage); } diff --git a/core/src/main/java/haveno/core/provider/fee/FeeProvider.java b/core/src/main/java/haveno/core/provider/fee/FeeProvider.java index 30d140f83e..18838cee38 100644 --- a/core/src/main/java/haveno/core/provider/fee/FeeProvider.java +++ b/core/src/main/java/haveno/core/provider/fee/FeeProvider.java @@ -59,8 +59,7 @@ public class FeeProvider extends HttpClientProvider { map.put(Config.BTC_TX_FEE, btcTxFee); map.put(Config.BTC_MIN_TX_FEE, btcMinTxFee); } catch (Throwable t) { - log.error(t.toString()); - t.printStackTrace(); + log.error("Error getting fees: {}\n", t.getMessage(), t); } return new Tuple2<>(tsMap, map); } diff --git a/core/src/main/java/haveno/core/provider/price/PriceProvider.java b/core/src/main/java/haveno/core/provider/price/PriceProvider.java index 871151a9e1..17bef33abb 100644 --- a/core/src/main/java/haveno/core/provider/price/PriceProvider.java +++ b/core/src/main/java/haveno/core/provider/price/PriceProvider.java @@ -68,8 +68,7 @@ public class PriceProvider extends HttpClientProvider { long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec")); marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true)); } catch (Throwable t) { - log.error(t.toString()); - t.printStackTrace(); + log.error("Error getting all prices: {}\n", t.getMessage(), t); } }); diff --git a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java index 192516b59f..bd124fda1f 100644 --- a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java +++ b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java @@ -83,6 +83,9 @@ import monero.wallet.model.MoneroTxConfig; import monero.wallet.model.MoneroTxWallet; import javax.annotation.Nullable; + +import org.apache.commons.lang3.exception.ExceptionUtils; + import java.math.BigInteger; import java.security.KeyPair; import java.time.Instant; @@ -523,7 +526,7 @@ public abstract class DisputeManager> extends Sup DisputeValidation.validateSenderNodeAddress(dispute, message.getSenderNodeAddress(), config); //DisputeValidation.testIfDisputeTriesReplay(dispute, disputeList.getList()); } catch (DisputeValidation.ValidationException e) { - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); validationExceptions.add(e); throw e; } @@ -532,9 +535,9 @@ public abstract class DisputeManager> extends Sup try { DisputeValidation.validatePaymentAccountPayload(dispute); // TODO: add field to dispute details: valid, invalid, missing } catch (Exception e) { - e.printStackTrace(); - log.warn(e.getMessage()); + log.error(ExceptionUtils.getStackTrace(e)); trade.prependErrorMessage(e.getMessage()); + throw e; } // get sender @@ -606,9 +609,8 @@ public abstract class DisputeManager> extends Sup } } } catch (Exception e) { - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); errorMessage = e.getMessage(); - log.warn(errorMessage); if (trade != null) trade.setErrorMessage(errorMessage); } diff --git a/core/src/main/java/haveno/core/support/dispute/DisputeSummaryVerification.java b/core/src/main/java/haveno/core/support/dispute/DisputeSummaryVerification.java index a2f2f2f281..5fbd64dba5 100644 --- a/core/src/main/java/haveno/core/support/dispute/DisputeSummaryVerification.java +++ b/core/src/main/java/haveno/core/support/dispute/DisputeSummaryVerification.java @@ -71,7 +71,7 @@ public class DisputeSummaryVerification { disputeAgent = arbitratorManager.getDisputeAgentByNodeAddress(nodeAddress).orElse(null); checkNotNull(disputeAgent, "Dispute agent is null"); } catch (Throwable e) { - e.printStackTrace(); + log.error("Error verifying signature: {}\n", e.getMessage(), e); throw new IllegalArgumentException(Res.get("support.sigCheck.popup.invalidFormat")); } @@ -93,7 +93,7 @@ public class DisputeSummaryVerification { throw new IllegalArgumentException(Res.get("support.sigCheck.popup.failed")); } } catch (Throwable e) { - e.printStackTrace(); + log.error("Error verifying signature with agent pub key ring: {}\n", e.getMessage(), e); throw new IllegalArgumentException(Res.get("support.sigCheck.popup.invalidFormat")); } } diff --git a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java index 8082aad475..719ac46284 100644 --- a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java +++ b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java @@ -94,6 +94,8 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import org.apache.commons.lang3.exception.ExceptionUtils; + import static com.google.common.base.Preconditions.checkNotNull; @Slf4j @@ -355,7 +357,7 @@ public final class ArbitrationManager extends DisputeManager { completeAux(); }, (errMessage, err) -> { - err.printStackTrace(); + log.error("Failed to close dispute ticket for trade {}: {}\n", trade.getId(), errMessage, err); failed(err); }); ticketClosed = true; diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java index a43c667d22..c11df74fae 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java @@ -70,7 +70,7 @@ public class ProcessDepositsConfirmedMessage extends TradeTask { try { trade.importMultisigHex(); } catch (Exception e) { - e.printStackTrace(); + log.warn("Error importing multisig hex on deposits confirmed for trade " + trade.getId() + ": " + e.getMessage() + "\n", e); } }); } diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/TradeTask.java b/core/src/main/java/haveno/core/trade/protocol/tasks/TradeTask.java index 231e54824a..293b74f99d 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/TradeTask.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/TradeTask.java @@ -61,7 +61,7 @@ public abstract class TradeTask extends Task { @Override protected void failed(Throwable t) { - t.printStackTrace(); + log.error("Trade task failed, error={}\n", t.getMessage(), t); appendExceptionToErrorMessage(t); trade.setErrorMessage(errorMessage); processModel.getTradeManager().requestPersistence(); diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletBase.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletBase.java index 0cbc41b234..877eb387a2 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletBase.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletBase.java @@ -6,6 +6,8 @@ import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.exception.ExceptionUtils; + import haveno.common.Timer; import haveno.common.UserThread; import haveno.core.api.XmrConnectionService; @@ -106,7 +108,7 @@ public class XmrWalletBase { height = wallet.getHeight(); // can get read timeout while syncing } catch (Exception e) { log.warn("Error getting wallet height while syncing with progress: " + e.getMessage()); - if (wallet != null && !isShutDownStarted) e.printStackTrace(); + if (wallet != null && !isShutDownStarted) log.warn(ExceptionUtils.getStackTrace(e)); // stop polling and release latch syncProgressError = e; diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 55b09682bd..1a9ead3597 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -818,7 +818,7 @@ public class XmrWalletService extends XmrWalletBase { MoneroFeeEstimate feeEstimates = getDaemon().getFeeEstimate(); BigInteger baseFeeEstimate = feeEstimates.getFees().get(2); // get elevated fee per kB BigInteger qmask = feeEstimates.getQuantizationMask(); - log.info("Monero base fee estimate={}, qmask={}: " + baseFeeEstimate, qmask); + log.info("Monero base fee estimate={}, qmask={}", baseFeeEstimate, qmask); // get tx base fee BigInteger baseFee = baseFeeEstimate.multiply(BigInteger.valueOf(txWeight)); @@ -922,8 +922,7 @@ public class XmrWalletService extends XmrWalletBase { try { ThreadUtils.awaitTask(shutDownTask, SHUTDOWN_TIMEOUT_MS); } catch (Exception e) { - log.warn("Error shutting down {}: {}", getClass().getSimpleName(), e.getMessage()); - e.printStackTrace(); + log.warn("Error shutting down {}: {}\n", getClass().getSimpleName(), e.getMessage(), e); // force close wallet forceCloseMainWallet(); @@ -945,8 +944,7 @@ public class XmrWalletService extends XmrWalletBase { List unusedAddressEntries = getUnusedAddressEntries(); if (!unusedAddressEntries.isEmpty()) return xmrAddressEntryList.swapAvailableToAddressEntryWithOfferId(unusedAddressEntries.get(0), context, offerId); } catch (Exception e) { - log.warn("Error getting new address entry based on incoming transactions"); - e.printStackTrace(); + log.warn("Error getting new address entry based on incoming transactions: {}\n", e.getMessage(), e); } // create new entry @@ -1172,8 +1170,7 @@ public class XmrWalletService extends XmrWalletBase { try { balanceListener.onBalanceChanged(balance); } catch (Exception e) { - log.warn("Failed to notify balance listener of change"); - e.printStackTrace(); + log.warn("Failed to notify balance listener of change: {}\n", e.getMessage(), e); } }); } @@ -1309,8 +1306,7 @@ public class XmrWalletService extends XmrWalletBase { try { doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS); } catch (Exception e) { - log.warn("Error initializing main wallet: " + e.getMessage()); - e.printStackTrace(); + log.warn("Error initializing main wallet: {}\n", e.getMessage(), e); HavenoUtils.setTopError(e.getMessage()); throw e; } @@ -1459,9 +1455,10 @@ public class XmrWalletService extends XmrWalletBase { log.info("Done creating full wallet " + config.getPath() + " in " + (System.currentTimeMillis() - time) + " ms"); return walletFull; } catch (Exception e) { - e.printStackTrace(); + String errorMsg = "Could not create wallet '" + config.getPath() + "': " + e.getMessage(); + log.warn(errorMsg + "\n", e); if (walletFull != null) forceCloseWallet(walletFull, config.getPath()); - throw new IllegalStateException("Could not create wallet '" + config.getPath() + "'"); + throw new IllegalStateException(errorMsg); } } @@ -1525,9 +1522,10 @@ public class XmrWalletService extends XmrWalletBase { log.info("Done opening full wallet " + config.getPath()); return walletFull; } catch (Exception e) { - e.printStackTrace(); + String errorMsg = "Could not open full wallet '" + config.getPath() + "': " + e.getMessage(); + log.warn(errorMsg + "\n", e); if (walletFull != null) forceCloseWallet(walletFull, config.getPath()); - throw new IllegalStateException("Could not open full wallet '" + config.getPath() + "'"); + throw new IllegalStateException(errorMsg); } } @@ -1557,7 +1555,7 @@ public class XmrWalletService extends XmrWalletBase { log.info("Done creating RPC wallet " + config.getPath() + " in " + (System.currentTimeMillis() - time) + " ms"); return walletRpc; } catch (Exception e) { - e.printStackTrace(); + log.warn("Could not create wallet '" + config.getPath() + "': " + e.getMessage() + "\n", e); if (walletRpc != null) forceCloseWallet(walletRpc, config.getPath()); throw new IllegalStateException("Could not create wallet '" + config.getPath() + "'. Please close Haveno, stop all monero-wallet-rpc processes in your task manager, and restart Haveno."); } @@ -1629,7 +1627,7 @@ public class XmrWalletService extends XmrWalletBase { log.info("Done opening RPC wallet " + config.getPath()); return walletRpc; } catch (Exception e) { - e.printStackTrace(); + log.warn("Could not open wallet '" + config.getPath() + "': " + e.getMessage() + "\n", e); if (walletRpc != null) forceCloseWallet(walletRpc, config.getPath()); throw new IllegalStateException("Could not open wallet '" + config.getPath() + "'. Please close Haveno, stop all monero-wallet-rpc processes in your task manager, and restart Haveno.\n\nError message: " + e.getMessage()); } @@ -1733,7 +1731,7 @@ public class XmrWalletService extends XmrWalletBase { wallet.changePassword(oldPassword, newPassword); saveMainWallet(); } catch (Exception e) { - e.printStackTrace(); + log.warn("Error changing main wallet password: " + e.getMessage() + "\n", e); throw e; } }); @@ -1916,7 +1914,7 @@ public class XmrWalletService extends XmrWalletBase { cacheWalletInfo(); requestSaveMainWallet(); } catch (Exception e) { - e.printStackTrace(); + log.warn("Error caching wallet info: " + e.getMessage() + "\n", e); } } } diff --git a/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java b/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java index 7a906ec7d9..997a724224 100644 --- a/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java +++ b/desktop/src/main/java/haveno/desktop/main/overlays/windows/DisputeSummaryWindow.java @@ -678,8 +678,7 @@ public class DisputeSummaryWindow extends Overlay { closeTicketButton.disableProperty().unbind(); hide(); }, (errMessage, err) -> { - log.error("Error closing dispute ticket: " + errMessage); - err.printStackTrace(); + log.error("Error closing dispute ticket: " + errMessage + "\n", err); new Popup().error(err.toString()).show(); }); } diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/TradeSubView.java b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/TradeSubView.java index eeee387774..cef43e795c 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/TradeSubView.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/TradeSubView.java @@ -153,8 +153,7 @@ public abstract class TradeSubView extends HBox { tradeStepView.setChatCallback(chatCallback); tradeStepView.activate(); } catch (Exception e) { - log.error("Creating viewClass {} caused an error {}", viewClass, e.getMessage()); - e.printStackTrace(); + log.error("Creating viewClass {} caused an error {}\n", viewClass, e.getMessage(), e); } } diff --git a/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java b/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java index 396d6026a1..236f8471e9 100644 --- a/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java +++ b/desktop/src/main/java/haveno/desktop/main/shared/ChatView.java @@ -65,6 +65,7 @@ import javafx.scene.text.TextAlignment; import javafx.geometry.Insets; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; @@ -565,12 +566,10 @@ public class ChatView extends AnchorPane { inputTextArea.setText(inputTextArea.getText() + "\n[" + Res.get("support.attachment") + " " + result.getName() + "]"); } } catch (java.io.IOException e) { - e.printStackTrace(); - log.error(e.getMessage()); + log.error(ExceptionUtils.getStackTrace(e)); } } catch (MalformedURLException e2) { - e2.printStackTrace(); - log.error(e2.getMessage()); + log.error(ExceptionUtils.getStackTrace(e2)); } } } else { @@ -593,8 +592,7 @@ public class ChatView extends AnchorPane { inputTextArea.setText(inputTextArea.getText() + "\n[" + Res.get("support.attachment") + " " + name + "]"); } } catch (Exception e) { - log.error(e.toString()); - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); } } @@ -629,8 +627,7 @@ public class ChatView extends AnchorPane { try (FileOutputStream fileOutputStream = new FileOutputStream(file.getAbsolutePath())) { fileOutputStream.write(attachment.getBytes()); } catch (IOException e) { - e.printStackTrace(); - System.out.println(e.getMessage()); + log.error("Error opening attachment: {}\n", e.getMessage(), e); } } } diff --git a/p2p/src/main/java/haveno/network/Socks5ProxyProvider.java b/p2p/src/main/java/haveno/network/Socks5ProxyProvider.java index 8bb3e1d418..f9c498f08e 100644 --- a/p2p/src/main/java/haveno/network/Socks5ProxyProvider.java +++ b/p2p/src/main/java/haveno/network/Socks5ProxyProvider.java @@ -24,6 +24,7 @@ import haveno.common.config.Config; import haveno.network.p2p.network.NetworkNode; import java.net.UnknownHostException; import javax.annotation.Nullable; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,8 +97,7 @@ public class Socks5ProxyProvider { try { return new Socks5Proxy(tokens[0], Integer.valueOf(tokens[1])); } catch (UnknownHostException e) { - log.error(e.getMessage()); - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); } } else { log.error("Incorrect format for socks5ProxyAddress. Should be: host:port.\n" + diff --git a/p2p/src/main/java/haveno/network/p2p/P2PService.java b/p2p/src/main/java/haveno/network/p2p/P2PService.java index a8028d0e2e..117ed4a494 100644 --- a/p2p/src/main/java/haveno/network/p2p/P2PService.java +++ b/p2p/src/main/java/haveno/network/p2p/P2PService.java @@ -57,6 +57,8 @@ import javafx.beans.property.ReadOnlyIntegerProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import lombok.Getter; + +import org.apache.commons.lang3.exception.ExceptionUtils; import org.fxmisc.easybind.EasyBind; import org.fxmisc.easybind.Subscription; import org.fxmisc.easybind.monadic.MonadicBinding; @@ -433,15 +435,12 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis @Override public void onFailure(@NotNull Throwable throwable) { - log.error(throwable.toString()); - throwable.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(throwable)); sendDirectMessageListener.onFault(throwable.toString()); } }, MoreExecutors.directExecutor()); } catch (CryptoException e) { - e.printStackTrace(); - log.error(message.toString()); - log.error(e.toString()); + log.error("Error sending encrypted direct message, message={}, error={}\n", message.toString(), e.getMessage(), e); sendDirectMessageListener.onFault(e.toString()); } } diff --git a/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageList.java b/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageList.java index a9d0494908..451d3e7e7f 100644 --- a/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageList.java +++ b/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageList.java @@ -63,8 +63,7 @@ public class MailboxMessageList extends PersistableList { try { return MailboxItem.fromProto(e, networkProtoResolver); } catch (ProtobufferException protobufferException) { - protobufferException.printStackTrace(); - log.error("Error at MailboxItem.fromProto: {}", protobufferException.toString()); + log.error("Error at MailboxItem.fromProto: {}", protobufferException.toString(), protobufferException); return null; } }) diff --git a/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageService.java b/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageService.java index 131b537217..c447b3fccf 100644 --- a/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageService.java +++ b/p2p/src/main/java/haveno/network/p2p/mailbox/MailboxMessageService.java @@ -335,8 +335,7 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD } }, MoreExecutors.directExecutor()); } catch (CryptoException e) { - log.error("sendEncryptedMessage failed"); - e.printStackTrace(); + log.error("sendEncryptedMessage failed: {}\n", e.getMessage(), e); sendMailboxMessageListener.onFault("sendEncryptedMailboxMessage failed " + e); } } @@ -644,8 +643,7 @@ public class MailboxMessageService implements HashMapChangedListener, PersistedD log.info("The mailboxEntry was already removed earlier."); } } catch (CryptoException e) { - e.printStackTrace(); - log.error("Could not remove ProtectedMailboxStorageEntry from network. Error: {}", e.toString()); + log.error("Could not remove ProtectedMailboxStorageEntry from network. Error: {}\n", e.toString(), e); } } diff --git a/p2p/src/main/java/haveno/network/p2p/network/Connection.java b/p2p/src/main/java/haveno/network/p2p/network/Connection.java index 92eddb0614..1a7f1b84df 100644 --- a/p2p/src/main/java/haveno/network/p2p/network/Connection.java +++ b/p2p/src/main/java/haveno/network/p2p/network/Connection.java @@ -91,6 +91,8 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import lombok.Getter; import lombok.extern.slf4j.Slf4j; + +import org.apache.commons.lang3.exception.ExceptionUtils; import org.jetbrains.annotations.Nullable; /** @@ -511,8 +513,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); } catch (Throwable t) { - log.error(t.getMessage()); - t.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(t)); } finally { stopped = true; ThreadUtils.execute(() -> doShutDown(closeConnectionReason, shutDownCompleteHandler), THREAD_ID); @@ -537,16 +538,14 @@ public class Connection implements HasCapabilities, Runnable, MessageListener { } catch (SocketException e) { log.trace("SocketException at shutdown might be expected {}", e.getMessage()); } catch (IOException e) { - log.error("Exception at shutdown. " + e.getMessage()); - e.printStackTrace(); + log.error("Exception at shutdown. {}\n", e.getMessage(), e); } finally { capabilitiesListeners.clear(); try { protoInputStream.close(); } catch (IOException e) { - log.error(e.getMessage()); - e.printStackTrace(); + log.error(ExceptionUtils.getStackTrace(e)); } Utilities.shutdownAndAwaitTermination(executorService, SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS); diff --git a/p2p/src/main/java/haveno/network/p2p/network/LocalhostNetworkNode.java b/p2p/src/main/java/haveno/network/p2p/network/LocalhostNetworkNode.java index 9254c9af20..26005988e2 100644 --- a/p2p/src/main/java/haveno/network/p2p/network/LocalhostNetworkNode.java +++ b/p2p/src/main/java/haveno/network/p2p/network/LocalhostNetworkNode.java @@ -76,8 +76,7 @@ public class LocalhostNetworkNode extends NetworkNode { try { startServer(new ServerSocket(servicePort)); } catch (IOException e) { - e.printStackTrace(); - log.error("Exception at startServer: " + e.getMessage()); + log.error("Exception at startServer: {}\n", e.getMessage(), e); } setupListeners.stream().forEach(SetupListener::onHiddenServicePublished); }, simulateTorDelayTorNode, TimeUnit.MILLISECONDS); diff --git a/p2p/src/main/java/haveno/network/p2p/network/Server.java b/p2p/src/main/java/haveno/network/p2p/network/Server.java index 9cf39f570d..437e3d2f88 100644 --- a/p2p/src/main/java/haveno/network/p2p/network/Server.java +++ b/p2p/src/main/java/haveno/network/p2p/network/Server.java @@ -97,11 +97,10 @@ class Server implements Runnable { } } catch (IOException e) { if (isServerActive()) - e.printStackTrace(); + log.error("Error executing server loop: {}\n", e.getMessage(), e); } } catch (Throwable t) { - log.error("Executing task failed. " + t.getMessage()); - t.printStackTrace(); + log.error("Executing task failed: {}\n", t.getMessage(), t); } } diff --git a/p2p/src/main/java/haveno/network/p2p/storage/P2PDataStorage.java b/p2p/src/main/java/haveno/network/p2p/storage/P2PDataStorage.java index a9c0f6ad16..40be21ef32 100644 --- a/p2p/src/main/java/haveno/network/p2p/storage/P2PDataStorage.java +++ b/p2p/src/main/java/haveno/network/p2p/storage/P2PDataStorage.java @@ -974,8 +974,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers broadcaster.broadcast(refreshTTLMessage, sender); } catch (IllegalArgumentException e) { - log.error("refreshTTL failed, missing data: {}", e.toString()); - e.printStackTrace(); + log.error("refreshTTL failed, missing data: {}\n", e.toString(), e); return false; } return true; diff --git a/p2p/src/main/java/haveno/network/p2p/storage/persistence/StoreService.java b/p2p/src/main/java/haveno/network/p2p/storage/persistence/StoreService.java index 6d9f3df16a..17c940add8 100644 --- a/p2p/src/main/java/haveno/network/p2p/storage/persistence/StoreService.java +++ b/p2p/src/main/java/haveno/network/p2p/storage/persistence/StoreService.java @@ -116,8 +116,7 @@ public abstract class StoreService { log.debug("Could not find resourceFile " + resourceFileName + ". That is expected if none is provided yet."); } catch (Throwable e) { log.error("Could not copy resourceFile " + resourceFileName + " to " + - destinationFile.getAbsolutePath() + ".\n" + e.getMessage()); - e.printStackTrace(); + destinationFile.getAbsolutePath() + ".\n", e); } } else { log.debug("No resource file was copied. {} exists already.", fileName); diff --git a/seednode/src/main/java/haveno/seednode/SeedNodeMain.java b/seednode/src/main/java/haveno/seednode/SeedNodeMain.java index 5659ab2e0b..455f180934 100644 --- a/seednode/src/main/java/haveno/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/haveno/seednode/SeedNodeMain.java @@ -75,7 +75,7 @@ public class SeedNodeMain extends ExecutableForAppWithP2p { seedNode = new SeedNode(); UserThread.execute(this::onApplicationLaunched); } catch (Exception e) { - e.printStackTrace(); + log.error("Error launching seed node: {}\n", e.toString(), e); } }); }