]> git.mxchange.org Git - fba.git/blobdiff - fba/helpers/config.py
Continued:
[fba.git] / fba / helpers / config.py
index 1ae1a25e648a51991b1fc5b6298e7afd71b4b630..11ad9762825c9d6338df79ce40c853364a4fd9b5 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+import logging
 import json
+import sys
+
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
 
 with open("config.json") as f:
-    # DEBUG: print("DEBUG: Loading configuration file ...")
+    logger.debug("Loading configuration file ...")
     _config = json.loads(f.read())
+    _config["max_crawl_depth"] = min(_config["max_crawl_depth"], (sys.getrecursionlimit() - 50))
+    logger.debug("LOADED!")
 
 def get(key: str) -> any:
-    # DEBUG: print(f"DEBUG: key[{type(key)}]={key} - CALLED!")
+    logger.debug("key[%s]='%s' - CALLED!", type(key), key)
+
     if not isinstance(key, str):
-        raise ValueError(f"Parameter key[]='{type(key)}' is not 'str'")
+        raise ValueError(f"Parameter key[]='{type(key)}' is not of type 'str'")
     elif key == "":
         raise ValueError("Parameter 'key' is empty")
     elif not key in _config:
         raise KeyError(f"key='{key}' does not exist in _config array")
 
-    # DEBUG: print(f"DEBUG: _config[{key}]={_config[key]} - EXIT!")
+    logger.debug("_config[%s][%s]='%s' - EXIT!", key, type(_config[key]), _config[key] if not key.endswith("_api_key") else "***")
     return _config[key]