From abbea6f9b1658870dbf7b16498acf221c011526b Mon Sep 17 00:00:00 2001 From: Bentley Hensel Date: Sat, 7 Oct 2023 10:37:07 -0400 Subject: [PATCH] getting it done Signed-off-by: Bentley Hensel --- .editorconfig | 76 +++++++++++++++++++++++++++++ .env-template | 0 app/main.py | 14 ++---- app/utils/logger/logger.py | 99 ++++++++++++++++++++++++-------------- poetry.lock | 74 ++++++++++++++++++++++++++++ pyproject.toml | 18 +++++++ 6 files changed, 234 insertions(+), 47 deletions(-) create mode 100644 .editorconfig create mode 100644 .env-template create mode 100644 poetry.lock create mode 100644 pyproject.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9b7f0d8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,76 @@ +# .editorconfig +# ------------------------------ +# Editor Configuration +# ------------------------------ + +# Top-most EditorConfig file +root = true + +# ------------------------------ +# Global Settings +# ------------------------------ + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +# ------------------------------ +# Language Specific Settings +# ------------------------------ + +# Python +[*.py] +charset = utf-8 +indent_style = space +indent_size = 4 +max_line_length = 79 + +# Rust +[*.rs] +indent_style = space +indent_size = 4 + +# R +[*.R] +indent_style = space +indent_size = 2 + +# JavaScript and CSS +[*.{js,css}] +brace_style = allman +indent_style = space +indent_size = 4 + +# HTML +[*.html] +indent_style = space +indent_size = 2 + +# SQL +[*.sql] +indent_style = space +indent_size = 2 + +# YAML +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +# Dockerfile +[Dockerfile] +indent_style = space +indent_size = 2 + +# Makefile +[Makefile] +indent_style = tab + +# Markdown +[*.md] +max_line_length = 120 + +# ------------------------------ +# Additional Specific Settings +# ------------------------------ diff --git a/.env-template b/.env-template new file mode 100644 index 0000000..e69de29 diff --git a/app/main.py b/app/main.py index c5d4f29..724c232 100644 --- a/app/main.py +++ b/app/main.py @@ -1,20 +1,12 @@ -# main.py -# Relative Path: app/main.py -""" -# Main Controller of GovA11y Data Processing - -""" +# app/main.py import time import sys import os +from .utils import logger sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from app.processes import execute_axes from app.database import fetch_unprocessed_rules, mark_axe_rule_as_processed -# rule_id = 15 -# 1363 - - def yeet_axes(): while True: rules_to_process = fetch_unprocessed_rules() @@ -29,4 +21,4 @@ def yeet_axes(): if __name__ == "__main__": - yeet_axes() \ No newline at end of file + yeet_axes() diff --git a/app/utils/logger/logger.py b/app/utils/logger/logger.py index fa45d9e..5d2a278 100644 --- a/app/utils/logger/logger.py +++ b/app/utils/logger/logger.py @@ -1,47 +1,62 @@ -""" -logger.py -Relative Path: app/utils/logger/logger.py - -This module provides configuration for the logging system. - -Author: TheBoatyMcBoatFace -""" - +# app/utils/logger/logger.py import logging +import os import time -from logging.handlers import TimedRotatingFileHandler -from rich.logging import RichHandler +from logging.handlers import TimedRotatingFileHandler, RotatingFileHandler +import json +# Logger Name and Level +LOGGER_NAME = "LoggyMcLogFace" +LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO").upper() +LOG_VERBOSE = True if LOG_LEVEL == "DEBUG" else os.environ.get("LOG_VERBOSE", "False").lower() == "true" -logger_name = "GovA11y" -level = 'DEBUG' +if LOG_VERBOSE: + FMT_STREAM = "%(asctime)s.%(msecs)03d %(levelname)-8s [%(filename)s:%(funcName)s:%(lineno)d] %(message)s" + datefmt = '%Y-%m-%d %H:%M:%S' +else: + FMT_STREAM = " %(levelname)-8s %(message)s" + datefmt = None # Set up logger: -logger = logging.getLogger(__name__) - -# the handler determines where the logs go: stdout/file -shell_handler = shell_handler = RichHandler(markup=True) -filename = f"logs/{logger_name}-{time.strftime('%Y-%m-%d')}.log" -file_handler = TimedRotatingFileHandler(filename=filename, when="midnight", interval=1, backupCount=30) - -logger.setLevel(logging.DEBUG) -shell_handler.setLevel(logging.DEBUG) -file_handler.setLevel(logging.DEBUG) - -# the formatter determines what our logs will look like -fmt_shell = '%(message)s' -fmt_file = '%(asctime)s %(levelname)s [%(filename)s:%(funcName)s:%(lineno)d] %(message)s' - -shell_formatter = logging.Formatter(fmt_shell) -file_formatter = logging.Formatter(fmt_file) - -# here we hook everything together +logger = logging.getLogger(LOGGER_NAME) +logger.setLevel(LOG_LEVEL) + +# Create the logs directory if it doesn't exist +if not os.path.exists("logs"): + os.makedirs("logs") + +# Handlers +filename = f"logs/{LOGGER_NAME}-{time.strftime('%Y-%m-%d')}.log" + +# Timed Rotating File Handler +timed_file_handler = TimedRotatingFileHandler(filename=filename, when="midnight", interval=1, backupCount=30) +timed_file_handler.setLevel(LOG_LEVEL) + +# Size-based Rotating File Handler +size_file_handler = RotatingFileHandler(filename=filename, maxBytes=5*1024*1024, backupCount=3) # 5MB per file +size_file_handler.setLevel(LOG_LEVEL) + +shell_handler = logging.StreamHandler() +shell_handler.setLevel(LOG_LEVEL) + +# Formatters +shell_formatter = logging.Formatter(FMT_STREAM, datefmt=datefmt) +json_formatter = logging.Formatter(json.dumps({ + "time": "%(asctime)s.%(msecs)03d", + "level": "%(levelname)-8s", + "file": "%(filename)s", + "function": "%(funcName)s", + "line": "%(lineno)d", + "message": "%(message)s" +})) +size_file_handler.setFormatter(json_formatter) +timed_file_handler.setFormatter(json_formatter) shell_handler.setFormatter(shell_formatter) -file_handler.setFormatter(file_formatter) +# Add handlers to logger logger.addHandler(shell_handler) -logger.addHandler(file_handler) - +logger.addHandler(timed_file_handler) +logger.addHandler(size_file_handler) def configure_logger(): """ @@ -50,10 +65,22 @@ def configure_logger(): This function reconfigures the logger with the predefined settings. """ global logger - logger = logging.getLogger(logger_name) + logger = logging.getLogger(LOGGER_NAME) +def log_exception(exc_type, exc_value, exc_traceback): + """ + Logs an exception with its traceback. + """ + logger.error( + "Uncaught exception", + exc_info=(exc_type, exc_value, exc_traceback) + ) +# Log statements for testing purposes if __name__ == "__main__": + import sys + sys.excepthook = log_exception + logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..c5f973c --- /dev/null +++ b/poetry.lock @@ -0,0 +1,74 @@ +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "packaging" +version = "23.2" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, +] + +[[package]] +name = "pluggy" +version = "1.3.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, + {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "pytest" +version = "7.4.2" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.4.2-py3-none-any.whl", hash = "sha256:1d881c6124e08ff0a1bb75ba3ec0bfd8b5354a01c194ddd5a0a870a48d99b002"}, + {file = "pytest-7.4.2.tar.gz", hash = "sha256:a766259cfab564a2ad52cb1aae1b881a75c3eb7e34ca3779697c23ed47c47069"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[metadata] +lock-version = "2.0" +python-versions = "^3.11" +content-hash = "b0d5b834150d6369acf5574d31fe9130043ea989811c47c7b2829741ce009e4f" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7a30b1b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "rabbit-run" +version = "0.1.0" +description = "Large dataset processing tools, transfers, and functionality" +authors = ["Bentley Hensel "] +license = "agpl-3" +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.11" + + +[tool.poetry.group.dev.dependencies] +pytest = "^7.4.2" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"