Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate log lines when creating multiple client instances #372

Open
v-yarotsky opened this issue Aug 31, 2023 · 0 comments
Open

Duplicate log lines when creating multiple client instances #372

v-yarotsky opened this issue Aug 31, 2023 · 0 comments

Comments

@v-yarotsky
Copy link

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 way1), the constructor should not have side effects.

Test script

import logging
from okta.client import Client as OktaClient

config = {
    "orgUrl": "https://example.com",
    "token": "foo",
    "logging": {
        "enabled": True,
    },
}


def make_client_and_run():
    OktaClient(config)
    logging.getLogger("okta-sdk-python").info("Hello from Okta logger")


def main():
    logging.info("Creating client #1")
    make_client_and_run()

    logging.info("Creating client #2")
    make_client_and_run()

    logging.info("Creating client #3")
    make_client_and_run()


main()

Expected 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
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

Footnotes

  1. https://github.com/okta/okta-sdk-python/issues/363

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant