File tree 1 file changed +12
-6
lines changed
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 3
3
"""
4
4
5
5
# Standard library
6
+ import logging
6
7
import os .path
7
8
import re
8
9
import sys
9
- import traceback
10
10
import warnings
11
11
12
12
# Third-party
24
24
# Set the current working directory
25
25
CWD = os .path .dirname (os .path .abspath (__file__ ))
26
26
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
+
27
35
28
36
def tags_frequency (csv_path , column_names ):
29
37
"""
@@ -495,15 +503,13 @@ def main():
495
503
496
504
497
505
if __name__ == "__main__" :
498
- # Exception handling
499
506
try :
500
507
main ()
501
508
except SystemExit as e :
502
509
sys .exit (e .code )
503
510
except KeyboardInterrupt :
504
- print ( "INFO (130) Halted via KeyboardInterrupt.", file = sys . stderr )
511
+ logger . info ( " Halted via KeyboardInterrupt." )
505
512
sys .exit (130 )
506
513
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 )
You can’t perform that action at this time.
0 commit comments