Skip to content

Commit

Permalink
implementation of logging and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
benne238 committed Mar 10, 2021
1 parent 1f4d856 commit 78a2850
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -38,4 +71,6 @@
"mkdocs-material",
"mkautodoc"
]
)
)

logger.info("webqueue-api package installed sucessfully")

0 comments on commit 78a2850

Please sign in to comment.