Repository: mgpai22/ergpy (language: python)

Issue:
Merge `issue/11/logging` into `dev`
✨ Add a logs package: format the logging and set the logging level to info (for now)
✅ Add a test for the logs feature
🩹 fix the issue about connecting to testnet

fix #11
link #21 


Discussion / hints:

Fix patch:
diff --git a/ergpy/logs.py b/ergpy/logs.py
new file mode 100644
index 0000000..ef32cae
--- /dev/null
+++ b/ergpy/logs.py
@@ -0,0 +1,22 @@
+"""
+Logging utility
+===============
+
+Utility functions to simplify logging
+
+AUTHOR
+    rafidini@GitHub
+
+CREATED AT
+    Sun. 18 Sep. 2022
+"""
+# External packages
+import logging
+
+# Constants
+LOG_FORMAT: str = '%(asctime)s %(levelname)s - [ergpy] - %(message)s'
+
+# Functions
+def setup_logs_env():
+    logging.root.setLevel(logging.INFO)
+    logging.basicConfig(format=LOG_FORMAT)
diff --git a/examples/example_7_utility_logging.py b/examples/example_7_utility_logging.py
new file mode 100644
index 0000000..00751d8
--- /dev/null
+++ b/examples/example_7_utility_logging.py
@@ -0,0 +1,57 @@
+"""
+Example no.7
+============
+
+Example on how to use logging utility
+
+AUTHOR
+    rafidini@GitHub
+
+CREATED AT
+    Sun. 18 Jun. 2022
+"""
+# Packages
+from ergpy import appkit, helper_functions
+from ergpy.logs import setup_logs_env, logging
+
+# Constants
+NODE_URL: str = "https://pai-net.mempoolnode.live"
+API_URL: str = "https://api.mempoolnode.live"
+
+# Main
+def main():
+    # Initiate instance
+    ergo = appkit.ErgoAppKit(node_url=NODE_URL, api_url=API_URL)
+    logging.info(f"Connecting to node url: {NODE_URL}")
+
+    # Transaction data
+    wallet_mnemonic = "decline reward asthma enter three clean borrow repeat identify wisdom horn pull entire adapt neglect"
+    receiver_addresses = ["3WwdXmYP39DLmDWJ6grH9ArXbWuCt2uGAh46VTfeGPrHKJJY6cSJ"]
+    amount = [0.22]
+    tx = ""
+
+    # Begin transaction
+    try:
+        logging.info("simple_send in progress...")
+        tx = helper_functions.simple_send(ergo=ergo, amount=amount, wallet_mnemonic=wallet_mnemonic,
+                                          receiver_addresses=receiver_addresses, base64reduced=True)
+        logging.info("simple_send done")
+    except Exception as e:
+        logging.error("Error: %s", e)
+    finally:
+        logging.info("JVM shutdown in progress...")
+        logging.info("JVM shutdown done")
+
+    # Save trasaction
+    data = f'Transaction: {str(tx)}'
+    logging.info(data)
+    outfile = 'demo.text'
+    with open(outfile, 'w') as file:
+        file.write(data)
+    logging.info(f"Wrote to file: {outfile}")
+    helper_functions.exit()
+
+if __name__ == "__main__":
+    setup_logs_env()
+    main()
+


Test patch:
diff --git a/tests/integration/test_helper_functions.py b/tests/integration/test_helper_functions.py
index b41a9e4..c7cc521 100644
--- a/tests/integration/test_helper_functions.py
+++ b/tests/integration/test_helper_functions.py
@@ -32,9 +32,8 @@ def test_get_wallet_address():
 
     # Call function
     logging.info('BEGIN get_wallet_address')
-    actual: str = \
-    json.loads(helper_functions.get_wallet_address(ergo=ergo, amount=amount, wallet_mnemonic=wallet_mnemonic))[0]
-    logging.info('END get_wallet_address')
+    actual: str = helper_functions.get_wallet_address(ergo=ergo, amount=amount, wallet_mnemonic=wallet_mnemonic)[0]
+    logging.info(f'END get_wallet_address')
 
     assert actual == expected