From 4a7eff0118ef6f40c8755be63e4feb93806f8a51 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 16 Dec 2021 10:44:10 +0200 Subject: [PATCH] Log traceback to file in debug mode. --- basicswap/basicswap.py | 26 +++++++++++++------------- basicswap/http_server.py | 8 ++++---- basicswap/network.py | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 5508b5b..7da9ca3 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -577,7 +577,7 @@ class BasicSwap(BaseApp): time.sleep(4) # Extra time to settle return self.log.error('stopDaemon %s', str(ex)) - traceback.print_exc() + self.log.error(traceback.format_exc()) raise ValueError('Could not stop {}'.format(str(coin))) def stopDaemons(self): @@ -3383,7 +3383,7 @@ class BasicSwap(BaseApp): except Exception as ex: self.log.error('process_XMR_SWAP_A_LOCK_tx_spend %s', str(ex)) if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) finally: session.close() session.remove() @@ -3438,7 +3438,7 @@ class BasicSwap(BaseApp): except Exception as ex: self.log.error('process_XMR_SWAP_A_LOCK_REFUND_tx_spend %s', str(ex)) if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) finally: session.close() session.remove() @@ -3570,7 +3570,7 @@ class BasicSwap(BaseApp): self.log.warning('Unknown event type: %d', row.event_type) except Exception as ex: if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) self.log.error('checkEvents failed: {}'.format(str(ex))) if self.debug: @@ -4226,7 +4226,7 @@ class BasicSwap(BaseApp): session.remove() except Exception as ex: if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) self.setBidError(bid.bid_id, bid, str(ex), xmr_swap=xmr_swap) def watchXmrSwap(self, bid, offer, xmr_swap): @@ -4300,7 +4300,7 @@ class BasicSwap(BaseApp): self.saveBidInSession(bid_id, bid, session, xmr_swap) except Exception as ex: if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) def sendXmrBidCoinALockTx(self, bid_id, session): # Send coin A lock tx and MSG4F L -> F @@ -4685,7 +4685,7 @@ class BasicSwap(BaseApp): self.saveBid(bid_id, bid, xmr_swap=xmr_swap) except Exception as ex: if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) self.setBidError(bid_id, bid, str(ex)) def processXmrBidLockSpendTx(self, msg): @@ -4725,7 +4725,7 @@ class BasicSwap(BaseApp): self.saveBid(bid_id, bid, xmr_swap=xmr_swap) except Exception as ex: if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) self.setBidError(bid_id, bid, str(ex)) # Update copy of bid in swaps_in_progress @@ -4791,7 +4791,7 @@ class BasicSwap(BaseApp): ensure(v, 'verifyTxOtVES failed for chain a lock tx leader esig') except Exception as ex: if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) self.setBidError(bid_id, bid, str(ex)) self.swaps_in_progress[bid_id] = (bid, offer) return @@ -4834,7 +4834,7 @@ class BasicSwap(BaseApp): except Exception as ex: self.log.error('processMsg %s', str(ex)) if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) finally: self.mxDB.release() @@ -4871,7 +4871,7 @@ class BasicSwap(BaseApp): except Exception as ex: self.log.error('smsg zmq %s', str(ex)) if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) self.mxDB.acquire() try: @@ -4885,7 +4885,7 @@ class BasicSwap(BaseApp): to_remove.append((bid_id, v[0], v[1])) except Exception as ex: if self.debug: - traceback.print_exc() + self.log.error('checkBidState %s', traceback.format_exc()) if self.is_transient_error(ex): self.log.warning('checkBidState %s %s', bid_id.hex(), str(ex)) self.logBidEvent(bid_id, EventLogTypes.SYSTEM_WARNING, 'No connection to daemon', session=None) @@ -4920,7 +4920,7 @@ class BasicSwap(BaseApp): except Exception as ex: self.log.error('update %s', str(ex)) if self.debug: - traceback.print_exc() + self.log.error(traceback.format_exc()) finally: self.mxDB.release() diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 2751aa6..4f64379 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -827,7 +827,7 @@ class HttpHandler(BaseHTTPRequestHandler): swap_client.setBidDebugInd(bytes.fromhex(sent_bid_id), debugind) except Exception as ex: if self.server.swap_client.debug is True: - traceback.print_exc() + self.server.swap_client.log.error(traceback.format_exc()) messages.append('Error: Send bid failed: ' + str(ex)) show_bid_form = True @@ -1297,7 +1297,7 @@ class HttpHandler(BaseHTTPRequestHandler): return func(self, url_split, post_string, is_json) except Exception as ex: if self.server.swap_client.debug is True: - traceback.print_exc() + self.server.swap_client.log.error(traceback.format_exc()) return js_error(self, str(ex)) if len(url_split) > 1 and url_split[1] == 'static': @@ -1318,7 +1318,7 @@ class HttpHandler(BaseHTTPRequestHandler): except Exception as ex: self.putHeaders(status_code, 'text/html') if self.server.swap_client.debug is True: - traceback.print_exc() + self.server.swap_client.log.error(traceback.format_exc()) return self.page_error(str(ex)) try: @@ -1361,7 +1361,7 @@ class HttpHandler(BaseHTTPRequestHandler): return self.page_index(url_split) except Exception as ex: if self.server.swap_client.debug is True: - traceback.print_exc() + self.server.swap_client.log.error(traceback.format_exc()) return self.page_error(str(ex)) def do_GET(self): diff --git a/basicswap/network.py b/basicswap/network.py index a22b580..aad5401 100644 --- a/basicswap/network.py +++ b/basicswap/network.py @@ -204,7 +204,7 @@ def msg_thread(cls): except Exception as e: logging.warning('process message error %s', str(e)) if cls._sc.debug: - traceback.print_exc() + logging.error(traceback.format_exc()) if processed is False: time.sleep(timeout)