Skip to content

Commit 3916bf1

Browse files
committed
deviantart_scratch logging added
1 parent 63b86dd commit 3916bf1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

deviantart/deviantart_scratcher.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# Standard library
88
import datetime as dt
9+
import logging
910
import os
1011
import sys
1112
import traceback
@@ -37,6 +38,12 @@
3738
API_KEYS = os.getenv("GOOGLE_API_KEYS").split(",")
3839
PSE_KEY = os.getenv("PSE_KEY")
3940

41+
# Set up logging
42+
logging.basicConfig(
43+
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
44+
)
45+
logger = logging.getLogger(__name__)
46+
4047

4148
def get_license_list():
4249
"""
@@ -82,7 +89,7 @@ def get_request_url(license):
8289
)
8390
except Exception as e:
8491
if isinstance(e, IndexError):
85-
print("Depleted all API Keys provided", file=sys.stderr)
92+
logger.error("Depleted all API Keys provided")
8693
else:
8794
raise e
8895

@@ -122,9 +129,7 @@ def get_response_elems(license):
122129
# If quota limit exceeded, switch to the next API key
123130
global API_KEYS_IND
124131
API_KEYS_IND += 1
125-
print(
126-
"Changing API KEYS due to depletion of quota", file=sys.stderr
127-
)
132+
logger.error("Changing API KEYS due to depletion of quota")
128133
return get_response_elems(license)
129134
else:
130135
raise e
@@ -177,9 +182,9 @@ def main():
177182
except SystemExit as e:
178183
sys.exit(e.code)
179184
except KeyboardInterrupt:
180-
print("INFO (130) Halted via KeyboardInterrupt.", file=sys.stderr)
185+
logger.info("Halted via KeyboardInterrupt.")
181186
sys.exit(130)
182187
except Exception:
183-
print("ERROR (1) Unhandled exception:", file=sys.stderr)
184-
print(traceback.print_exc(), file=sys.stderr)
188+
logger.exception("Unhandled exception:")
189+
logger.exception(traceback.print_exc())
185190
sys.exit(1)

0 commit comments

Comments
 (0)