-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace print statements with logging (#4)
* Replace print statements with logging - defaults to only console logging - defaults to WARNING level - configurable with: `export APP_LOG_LEVEL=[INFO|DEBUG]` * Merge awoods-logging into logging (#3) * linter for box reader after logging * comment out diff cover remove socket * skip processing of files where n value is not 1 * tests with 65% cvg * add in github actions install of diff cover globally * update paths for diff cover * test diff cover install and check path * uncomment diff cover test * uncomment diff cover test 2 * new coverage test * full test coverage * flake8 passes all files * check flake8 version * mod flake8 command for 120 line length * add additional test coverage, stops early if not 85 --------- Co-authored-by: kim pham <[email protected]>
- Loading branch information
Showing
9 changed files
with
559 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
*~ | ||
*.swp | ||
|
||
logs/ | ||
|
||
input/* | ||
output/* | ||
.coverage | ||
coverage.* | ||
|
||
|
||
dist/* | ||
*/*.egg-info/* | ||
__pycache__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
boto3==1.35.39 | ||
botocore==1.35.39 | ||
flake8==7.1.1 | ||
jmespath==1.0.1 | ||
jpylyzer==2.2.1 | ||
mccabe==0.7.0 | ||
project-paths==1.1.1 | ||
pycodestyle==2.12.1 | ||
pyflakes==3.2.0 | ||
python-dateutil==2.9.0.post0 | ||
s3transfer==0.10.3 | ||
setuptools==73.0.1 | ||
six==1.16.0 | ||
toml==0.10.2 | ||
urllib3==2.2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import logging | ||
from logging.handlers import TimedRotatingFileHandler | ||
import os | ||
from datetime import datetime | ||
|
||
LOG_FILE_BACKUP_COUNT = int(os.getenv('LOG_FILE_BACKUP_COUNT', '30')) | ||
LOG_ROTATION = "midnight" | ||
|
||
timestamp = datetime.today().strftime('%Y-%m-%d') | ||
|
||
|
||
def configure_logger(name): # pragma: no cover | ||
log_level = os.getenv("APP_LOG_LEVEL", "WARNING") | ||
log_dir = os.getenv("LOG_DIR", "logs/") | ||
# create log directory if it doesn't exist | ||
if not os.path.exists(log_dir): | ||
os.makedirs(log_dir) | ||
|
||
log_file_path = os.path.join(log_dir, "jp2_remediator.log") | ||
formatter = logging.Formatter( | ||
'%(levelname)s - %(asctime)s - %(name)s - %(message)s') | ||
|
||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(formatter) | ||
|
||
logger = logging.getLogger(name) | ||
logger.addHandler(console_handler) | ||
# Defaults to console logging | ||
if os.getenv("CONSOLE_LOGGING_ONLY", "true") == "false": | ||
# make log_file_path if it doesn't exist | ||
# os.makedirs(log_file_path, exist_ok=True) | ||
file_handler = TimedRotatingFileHandler( | ||
filename=log_file_path, | ||
when=LOG_ROTATION, | ||
backupCount=LOG_FILE_BACKUP_COUNT | ||
) | ||
file_handler.setFormatter(formatter) | ||
logger.addHandler(file_handler) | ||
|
||
logger.setLevel(log_level) | ||
return logger |
Oops, something went wrong.