Skip to content

Commit

Permalink
getting it done
Browse files Browse the repository at this point in the history
Signed-off-by: Bentley Hensel <bentleyhensel@gmail.com>
  • Loading branch information
TheBoatyMcBoatFace committed Oct 7, 2023
1 parent 4692866 commit abbea6f
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 47 deletions.
76 changes: 76 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
# ------------------------------
Empty file added .env-template
Empty file.
14 changes: 3 additions & 11 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -29,4 +21,4 @@ def yeet_axes():


if __name__ == "__main__":
yeet_axes()
yeet_axes()
99 changes: 63 additions & 36 deletions app/utils/logger/logger.py
Original file line number Diff line number Diff line change
@@ -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():
"""
Expand All @@ -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")
Expand Down
74 changes: 74 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "rabbit-run"
version = "0.1.0"
description = "Large dataset processing tools, transfers, and functionality"
authors = ["Bentley Hensel <bentleyhensel@gmail.com>"]
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"

0 comments on commit abbea6f

Please sign in to comment.