Creating an instance of the Client class has a side effect - it creates a new logging StreamHandler and attaches it to the package-level logger. Creating multiple client instances adds duplicate handlers, causing duplicate log lines. This is unexpected, inconvenient and even somewhat dangerous, as it can result in overwhelmed log collection systems and memory leaks.
Since the client object is not meant to be a singleton (indeed, it's not currently possible to use it that way^1), the constructor should not have side effects.
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
INFO:okta-sdk-python:Hello from Okta logger
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
INFO:okta-sdk-python:Hello from Okta logger
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
INFO:okta-sdk-python:Hello from Okta logger
Actual result
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
INFO:okta-sdk-python:Hello from Okta logger
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
INFO:okta-sdk-python:Hello from Okta logger
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
2023-08-31 12:39:10,527 - okta-sdk-python - test - INFO - Hello from Okta logger
INFO:okta-sdk-python:Hello from Okta logger
Okta client version: 2.9.3
Summary
Creating an instance of the Client class has a side effect - it creates a new logging StreamHandler and attaches it to the package-level logger. Creating multiple client instances adds duplicate handlers, causing duplicate log lines. This is unexpected, inconvenient and even somewhat dangerous, as it can result in overwhelmed log collection systems and memory leaks. Since the client object is not meant to be a singleton (indeed, it's not currently possible to use it that way^1), the constructor should not have side effects.
Test script
Expected result
Actual result