Skip to content

Adding example of logging and custom context #25

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import os
import ldclient
## uncomment the next line to enable debug logging
## import sys
from ldclient import Context
from ldclient.config import Config
from threading import Event
from halo import Halo

## uncomment the next two lines to enable debug logging
## logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
## logging.getLogger("launchdarkly_sdk").setLevel(logging.DEBUG)

# Set sdk_key to your LaunchDarkly SDK key.
sdk_key = os.getenv('LAUNCHDARKLY_SDK_KEY')
Expand Down Expand Up @@ -65,6 +69,14 @@ def flag_value_change_listener(self, flag_change):
context = \
Context.builder('example-user-key').kind('user').name('Sandy').build()

# If you want to try a custom context, uncomment the next six lines
#org_context = Context.builder("org-acme-123").kind("organization") \
# .set("name", "Acme Corp") \
# .set("industry", "retail") \
# .set("region", "EMEA") \
# .set("subscriptionTier", "enterprise") \
# .build()

flag_value = ldclient.get().variation(feature_flag_key, context, False)
show_evaluation_result(feature_flag_key, flag_value)

Expand Down