File tree 3 files changed +36
-14
lines changed
3 files changed +36
-14
lines changed Original file line number Diff line number Diff line change 13
13
"""
14
14
15
15
# Standard library
16
+ import logging
16
17
import sys
17
- import traceback
18
18
19
19
# Third-party
20
20
import pandas as pd
21
21
22
+ # Set up logging
23
+ logging .basicConfig (
24
+ level = logging .INFO ,
25
+ format = "%(asctime)s - %(levelname)s - %(message)s" ,
26
+ handlers = [logging .FileHandler ("logfile.log" ), logging .StreamHandler ()],
27
+ )
28
+ logger = logging .getLogger (__name__ )
29
+
22
30
23
31
def drop_empty_column (csv_path , new_csv_path ):
24
32
"""
@@ -95,9 +103,8 @@ def main():
95
103
except SystemExit as e :
96
104
sys .exit (e .code )
97
105
except KeyboardInterrupt :
98
- print ( "INFO (130) Halted via KeyboardInterrupt.", file = sys . stderr )
106
+ logger . info ( " Halted via KeyboardInterrupt." )
99
107
sys .exit (130 )
100
108
except Exception :
101
- print ("ERROR (1) Unhandled exception:" , file = sys .stderr )
102
- print (traceback .print_exc (), file = sys .stderr )
103
- sys .exit (1 )
109
+ logger .exception ("Unhandled exception:" )
110
+ sys .exit (1 )
Original file line number Diff line number Diff line change 5
5
6
6
# Standard library
7
7
import json
8
+ import logging
8
9
import os
9
10
import os .path
10
11
import sys
11
- import traceback
12
12
13
13
# Third-party
14
14
import flickrapi
20
20
dotenv_path = os .path .join (os .path .dirname (CWD ), ".env" )
21
21
load_dotenv (dotenv_path )
22
22
23
+ # Set up logging
24
+ logging .basicConfig (
25
+ level = logging .INFO ,
26
+ format = "%(asctime)s - %(levelname)s - %(message)s" ,
27
+ handlers = [logging .FileHandler ("logfile.log" ), logging .StreamHandler ()],
28
+ )
29
+ logger = logging .getLogger (__name__ )
30
+
23
31
24
32
def main ():
25
33
# Initialize Flickr API instance
@@ -47,9 +55,8 @@ def main():
47
55
except SystemExit as e :
48
56
sys .exit (e .code )
49
57
except KeyboardInterrupt :
50
- print ( "INFO (130) Halted via KeyboardInterrupt.", file = sys . stderr )
58
+ logger . info ( " Halted via KeyboardInterrupt." )
51
59
sys .exit (130 )
52
60
except Exception :
53
- print ("ERROR (1) Unhandled exception:" , file = sys .stderr )
54
- print (traceback .print_exc (), file = sys .stderr )
55
- sys .exit (1 )
61
+ logger .exception ("Unhandled exception:" )
62
+ sys .exit (1 )
Original file line number Diff line number Diff line change 9
9
10
10
# Standard library
11
11
import json
12
+ import logging
12
13
import os
13
14
import os .path
14
15
import sys
15
16
import time
16
- import traceback
17
17
18
18
# Third-party
19
19
import flickrapi
29
29
# Global variable: Number of retries for error handling
30
30
RETRIES = 0
31
31
32
+ # Set up logging
33
+ logging .basicConfig (
34
+ level = logging .INFO ,
35
+ format = "%(asctime)s - %(levelname)s - %(message)s" ,
36
+ handlers = [logging .FileHandler ("logfile.log" ), logging .StreamHandler ()],
37
+ )
38
+ logger = logging .getLogger (__name__ )
39
+
32
40
33
41
def to_df (datalist , namelist ):
34
42
"""
@@ -305,18 +313,18 @@ def main():
305
313
306
314
307
315
if __name__ == "__main__" :
316
+ RETRIES = 0 # Initialize RETRIES counter
308
317
while True :
309
318
try :
310
319
main ()
311
320
except SystemExit as e :
312
321
sys .exit (e .code )
313
322
except KeyboardInterrupt :
314
- print ( "INFO (130) Halted via KeyboardInterrupt.", file = sys . stderr )
323
+ logger . info ( " Halted via KeyboardInterrupt." )
315
324
sys .exit (130 )
316
325
except Exception :
317
326
RETRIES += 1
318
- print ("ERROR (1) Unhandled exception:" , file = sys .stderr )
319
- print (traceback .print_exc (), file = sys .stderr )
327
+ logger .exception ("Unhandled exception:" )
320
328
if RETRIES <= 20 :
321
329
continue
322
330
else :
You can’t perform that action at this time.
0 commit comments