diff --git a/aws_project_costs/main.py b/aws_project_costs/main.py index 9688fa3..7880178 100644 --- a/aws_project_costs/main.py +++ b/aws_project_costs/main.py @@ -1,3 +1,4 @@ +import logging from argparse import ArgumentParser import yaml @@ -13,9 +14,12 @@ def main() -> None: ) parser.add_argument("--costs", required=True, help="Project costs CSV") parser.add_argument("--output", help="Output file") + parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output") args = parser.parse_args() + logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) + with open(args.config) as f: config = yaml.safe_load(f) diff --git a/aws_project_costs/project_costs.py b/aws_project_costs/project_costs.py index 9d96752..56e6d4b 100644 --- a/aws_project_costs/project_costs.py +++ b/aws_project_costs/project_costs.py @@ -1,10 +1,13 @@ import json +import logging from enum import Enum from operator import itemgetter from typing import Any, Hashable, Optional import pandas as pd +logger = logging.getLogger(__name__) + PROJECT_TAG = "Proj" @@ -86,6 +89,9 @@ def _shared_account( project_name = proj_tag_names_map[project_tag] elif "*" in proj_tag_names_map: project_name = proj_tag_names_map["*"] + logger.warn( + "Project tag %s not found, using %s", project_tag, project_name + ) else: raise ValueError(f"{project_tag} is not in proj-tag-names") rows.append( @@ -180,7 +186,7 @@ def analyse_costs_csv( for start in sorted(df["START"].unique()): month_costs = df[df["START"] == start] for accountname in month_costs["ACCOUNTNAME"].unique(): - # print(f"Processing {accountname} {start}") + logger.debug(f"Processing {accountname} {start}") try: acc_itemised_rows = allocate_costs( accountname=accountname, @@ -190,7 +196,9 @@ def analyse_costs_csv( ) itemised_rows.extend(sorted(acc_itemised_rows, key=itemgetter(1, 2, 0))) except Exception as e: - print(f"ERROR: Failed to analyse account {accountname} {start} {e}") + logger.error( + f"ERROR: Failed to analyse account {accountname} {start} {e}" + ) raise if output_csv_filename: