Skip to content

Commit b3fb76c

Browse files
committed
data_analysis logger added
1 parent 61f7cc9 commit b3fb76c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

analyze/data_analysis.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"""
44

55
# Standard library
6+
import logging
67
import os.path
78
import re
89
import sys
9-
import traceback
1010
import warnings
1111

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

27+
# Set up logging
28+
logging.basicConfig(
29+
level=logging.INFO,
30+
format="%(asctime)s - %(levelname)s - %(message)s",
31+
handlers=[logging.FileHandler("logfile.log"), logging.StreamHandler()],
32+
)
33+
logger = logging.getLogger(__name__)
34+
2735

2836
def tags_frequency(csv_path, column_names):
2937
"""
@@ -495,15 +503,13 @@ def main():
495503

496504

497505
if __name__ == "__main__":
498-
# Exception handling
499506
try:
500507
main()
501508
except SystemExit as e:
502509
sys.exit(e.code)
503510
except KeyboardInterrupt:
504-
print("INFO (130) Halted via KeyboardInterrupt.", file=sys.stderr)
511+
logger.info("Halted via KeyboardInterrupt.")
505512
sys.exit(130)
506513
except Exception:
507-
print("ERROR (1) Unhandled exception:", file=sys.stderr)
508-
print(traceback.print_exc(), file=sys.stderr)
509-
sys.exit(1)
514+
logger.exception("Unhandled exception:")
515+
sys.exit(1)

0 commit comments

Comments
 (0)