Skip to content

Commit

Permalink
data_analysis logger added
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMQaisar committed Mar 17, 2024
1 parent 61f7cc9 commit b3fb76c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions analyze/data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""

# Standard library
import logging
import os.path
import re
import sys
import traceback
import warnings

# Third-party
Expand All @@ -24,6 +24,14 @@
# Set the current working directory
CWD = os.path.dirname(os.path.abspath(__file__))

# Set up logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=[logging.FileHandler("logfile.log"), logging.StreamHandler()],
)
logger = logging.getLogger(__name__)


def tags_frequency(csv_path, column_names):
"""
Expand Down Expand Up @@ -495,15 +503,13 @@ def main():


if __name__ == "__main__":
# Exception handling
try:
main()
except SystemExit as e:
sys.exit(e.code)
except KeyboardInterrupt:
print("INFO (130) Halted via KeyboardInterrupt.", file=sys.stderr)
logger.info("Halted via KeyboardInterrupt.")
sys.exit(130)
except Exception:
print("ERROR (1) Unhandled exception:", file=sys.stderr)
print(traceback.print_exc(), file=sys.stderr)
sys.exit(1)
logger.exception("Unhandled exception:")
sys.exit(1)

0 comments on commit b3fb76c

Please sign in to comment.