From 78a285016df7a84b2e42eb8835f5c4bd7f8a9691 Mon Sep 17 00:00:00 2001 From: benne238 Date: Wed, 10 Mar 2021 13:31:59 -0500 Subject: [PATCH] implementation of logging and error handling --- setup.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 76e8ca3..4999ca0 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,49 @@ -import setuptools +import setuptools, logging from pathlib import Path from os import environ from dotenv import load_dotenv +# Configure the logger +logger_name = "webqueueapi_install_log" +logger = logging.getLogger(logger_name) +logger.setLevel(logging.DEBUG) + +# See Formatting Details: https://docs.python.org/3/library/logging.html#logrecord-attributes +# Example: Jan 28 2021 12:19:28 venv-manager : [INFO] Message +log_message_format = "%(asctime)s %(name)s : [%(levelname)s] %(message)s" +# See Time Formatting Details: https://docs.python.org/3.6/library/time.html#time.strftime +# Example: Jan 28 2021 12:19:28 +log_time_format = "%b %d %Y %H:%M:%S" +log_formatter = logging.Formatter(log_message_format, log_time_format) + +# Configure output to stdout +stream_handler = logging.StreamHandler() +stream_handler.setFormatter(log_formatter) +stream_handler.setLevel(logging.INFO) +logger.addHandler(stream_handler) + +# Configure out to logfile, located in '/tmp/webqueueapi install log.log' +log_file_path = path.abspath("/tmp/" + logger_name + '.log') +file_handler = logging.FileHandler(log_file_path) +file_handler.setFormatter(log_formatter) +logger.addHandler(file_handler) + +# Define and load the package version file current_dir = Path(__file__).parent version_file_path = Path(current_dir, "VERSION") load_dotenv(version_file_path) +# Get the version from the package version file VERSION = environ.get("VERSION") +if (VERSION == None or VERSION == ""): + logger.error("VERSION has no value: exiting") + exit() + python_ldap_version = "3.3.1" +logger.debug("Attempting to install webqueue-api package") + setuptools.setup( name="webqueue-api", version=VERSION, @@ -38,4 +71,6 @@ "mkdocs-material", "mkautodoc" ] -) \ No newline at end of file +) + +logger.info("webqueue-api package installed sucessfully") \ No newline at end of file