Skip to content

Commit f96a87d

Browse files
authored
chore: Replace print statements with logger (#2452)
Signed-off-by: iron-prog <dt915725@gmail.com>
1 parent 3b976da commit f96a87d

15 files changed

Lines changed: 279 additions & 35 deletions

src/hiero_sdk_python/account/account_records_query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import traceback
5+
import logging
66

77
from hiero_sdk_python.account.account_id import AccountId
88
from hiero_sdk_python.channels import _Channel
@@ -16,6 +16,9 @@
1616
from hiero_sdk_python.transaction.transaction_record import TransactionRecord
1717

1818

19+
logger = logging.getLogger(__name__)
20+
21+
1922
class AccountRecordsQuery(Query):
2023
"""
2124
A query to retrieve records about a specific Account.
@@ -76,8 +79,7 @@ def _make_request(self) -> query_pb2.Query:
7679

7780
return query
7881
except Exception as e:
79-
print(f"Exception in _make_request: {e}")
80-
traceback.print_exc()
82+
logger.error("Exception in _make_request: %s", e, exc_info=True)
8183
raise
8284

8385
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/client/network.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import logging
56
import secrets
67
import time
78
from typing import Any
@@ -15,6 +16,9 @@
1516
from hiero_sdk_python.node import _Node
1617

1718

19+
logger = logging.getLogger(__name__)
20+
21+
1822
class Network:
1923
"""Manages the network configuration for connecting to the Hedera network."""
2024

@@ -188,7 +192,7 @@ def _fetch_nodes_from_mirror_node(self) -> list[_Node]:
188192
"""
189193
base_url: str | None = self.MIRROR_NODE_URLS.get(self.network)
190194
if not base_url:
191-
print(f"No known mirror node URL for network='{self.network}'. Skipping fetch.")
195+
logger.warning("No known mirror node URL for network='%s'. Skipping fetch.", self.network)
192196
return []
193197

194198
url: str = f"{base_url}/api/v1/network/nodes?limit=100&order=desc"
@@ -209,7 +213,10 @@ def _fetch_nodes_from_mirror_node(self) -> list[_Node]:
209213

210214
return nodes
211215
except requests.RequestException as e:
212-
print(f"Error fetching nodes from mirror node API: {e}")
216+
logger.error("Error fetching nodes from mirror node API: %s", e)
217+
return []
218+
except (ValueError, KeyError, TypeError, IndexError, AttributeError) as e:
219+
logger.error("Error parsing mirror node API response: %s", e, exc_info=True)
213220
return []
214221

215222
def _fetch_nodes_from_default_nodes(self) -> list[_Node]:

src/hiero_sdk_python/contract/contract_bytecode_query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import traceback
5+
import logging
66

77
from hiero_sdk_python.channels import _Channel
88
from hiero_sdk_python.client.client import Client
@@ -19,6 +19,9 @@
1919
from hiero_sdk_python.query.query import Query
2020

2121

22+
logger = logging.getLogger(__name__)
23+
24+
2225
class ContractBytecodeQuery(Query):
2326
"""
2427
A query to retrieve the bytecode of a specific Contract.
@@ -80,8 +83,7 @@ def _make_request(self) -> query_pb2.Query:
8083

8184
return query
8285
except Exception as e:
83-
print(f"Exception in _make_request: {e}")
84-
traceback.print_exc()
86+
logger.error("Exception in _make_request: %s", e, exc_info=True)
8587
raise
8688

8789
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/contract/contract_call_query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from __future__ import annotations
66

7-
import traceback
7+
import logging
88

99
from hiero_sdk_python.account.account_id import AccountId
1010
from hiero_sdk_python.channels import _Channel
@@ -23,6 +23,9 @@
2323
from hiero_sdk_python.query.query import Query
2424

2525

26+
logger = logging.getLogger(__name__)
27+
28+
2629
class ContractCallQuery(Query):
2730
"""
2831
A query to call a contract on the network.
@@ -160,8 +163,7 @@ def _make_request(self) -> query_pb2.Query:
160163

161164
return query
162165
except Exception as e:
163-
print(f"Exception in _make_request: {e}")
164-
traceback.print_exc()
166+
logger.error("Exception in _make_request: %s", e, exc_info=True)
165167
raise
166168

167169
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/contract/contract_info_query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import traceback
5+
import logging
66

77
from hiero_sdk_python.channels import _Channel
88
from hiero_sdk_python.client.client import Client
@@ -18,6 +18,9 @@
1818
from hiero_sdk_python.query.query import Query
1919

2020

21+
logger = logging.getLogger(__name__)
22+
23+
2124
class ContractInfoQuery(Query):
2225
"""
2326
A query to retrieve information about a specific Contract.
@@ -76,8 +79,7 @@ def _make_request(self) -> query_pb2.Query:
7679

7780
return query
7881
except Exception as e:
79-
print(f"Exception in _make_request: {e}")
80-
traceback.print_exc()
82+
logger.error("Exception in _make_request: %s", e, exc_info=True)
8183
raise
8284

8385
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/file/file_contents_query.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import logging
6+
57
from hiero_sdk_python.channels import _Channel
68
from hiero_sdk_python.client.client import Client
79
from hiero_sdk_python.executable import _Method
@@ -15,6 +17,9 @@
1517
from hiero_sdk_python.query.query import Query
1618

1719

20+
logger = logging.getLogger(__name__)
21+
22+
1823
class FileContentsQuery(Query):
1924
"""
2025
A query to retrieve the contents of a specific File.
@@ -76,7 +81,7 @@ def _make_request(self) -> query_pb2.Query:
7681

7782
return query
7883
except Exception as e:
79-
print(f"Exception in _make_request: {e}")
84+
logger.error("Exception in _make_request: %s", e, exc_info=True)
8085
raise
8186

8287
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/file/file_info_query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import traceback
5+
import logging
66

77
from hiero_sdk_python.channels import _Channel
88
from hiero_sdk_python.client.client import Client
@@ -14,6 +14,9 @@
1414
from hiero_sdk_python.query.query import Query
1515

1616

17+
logger = logging.getLogger(__name__)
18+
19+
1720
class FileInfoQuery(Query):
1821
"""
1922
A query to retrieve information about a specific File.
@@ -75,8 +78,7 @@ def _make_request(self) -> query_pb2.Query:
7578

7679
return query
7780
except Exception as e:
78-
print(f"Exception in _make_request: {e}")
79-
traceback.print_exc()
81+
logger.error("Exception in _make_request: %s", e, exc_info=True)
8082
raise
8183

8284
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/query/account_balance_query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import traceback
3+
import logging
44
from typing import Any
55

66
from hiero_sdk_python.account.account_balance import AccountBalance
@@ -13,6 +13,9 @@
1313
from hiero_sdk_python.query.query import Query
1414

1515

16+
logger = logging.getLogger(__name__)
17+
18+
1619
class CryptoGetAccountBalanceQuery(Query):
1720
"""
1821
A query to retrieve the balance of a specific account from the Hedera network.
@@ -110,8 +113,7 @@ def _make_request(self) -> query_pb2.Query:
110113

111114
return query
112115
except Exception as e:
113-
print(f"Exception in _make_request: {e}")
114-
traceback.print_exc()
116+
logger.error("Exception in _make_request: %s", e, exc_info=True)
115117
raise
116118

117119
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/query/account_info_query.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import logging
4+
35
from hiero_sdk_python.account.account_id import AccountId
46
from hiero_sdk_python.account.account_info import AccountInfo
57
from hiero_sdk_python.channels import _Channel
@@ -8,6 +10,9 @@
810
from hiero_sdk_python.query.query import Query
911

1012

13+
logger = logging.getLogger(__name__)
14+
15+
1116
class AccountInfoQuery(Query):
1217
"""
1318
A query to retrieve information about a specific Account.
@@ -67,7 +72,7 @@ def _make_request(self):
6772

6873
return query
6974
except Exception as e:
70-
print(f"Exception in _make_request: {e}")
75+
logger.error("Exception in _make_request: %s", e, exc_info=True)
7176
raise
7277

7378
def _get_method(self, channel: _Channel) -> _Method:

src/hiero_sdk_python/query/token_info_query.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import logging
4+
35
from hiero_sdk_python.channels import _Channel
46
from hiero_sdk_python.client.client import Client
57
from hiero_sdk_python.executable import _Method
@@ -9,6 +11,9 @@
911
from hiero_sdk_python.tokens.token_info import TokenInfo
1012

1113

14+
logger = logging.getLogger(__name__)
15+
16+
1217
class TokenInfoQuery(Query):
1318
"""
1419
A query to retrieve information about a specific Token.
@@ -69,7 +74,7 @@ def _make_request(self) -> query_pb2.Query:
6974

7075
return query
7176
except Exception as e:
72-
print(f"Exception in _make_request: {e}")
77+
logger.error("Exception in _make_request: %s", e, exc_info=True)
7378
raise
7479

7580
def _get_method(self, channel: _Channel) -> _Method:

0 commit comments

Comments
 (0)