-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy paththreshold_logging.py
More file actions
40 lines (31 loc) · 1.28 KB
/
threshold_logging.py
File metadata and controls
40 lines (31 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from datetime import timedelta
import logging
import traceback
import sys
import couchbase
from couchbase.cluster import Cluster
from couchbase.options import ClusterOptions, ClusterTracingOptions
from couchbase.auth import PasswordAuthenticator
from couchbase.exceptions import CouchbaseException
# NOTE: for simple test to see output, drop the threshold
# ex: tracing_threshold_kv=timedelta(microseconds=1)
# configure logging
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
# setup couchbase logging
logger = logging.getLogger()
couchbase.configure_logging(logger.name, level=logger.level)
# tag::threshold_logging_config[]
tracing_opts = ClusterTracingOptions(
tracing_threshold_queue_flush_interval=timedelta(seconds=5),
tracing_threshold_queue_size=10,
tracing_threshold_kv=timedelta(milliseconds=500))
auth = PasswordAuthenticator("Administrator", "password")
cluster_opts = ClusterOptions(authenticator=auth, tracing_options=tracing_opts)
cluster = Cluster.connect("couchbase://your-ip", cluster_opts)
# end::threshold_logging_config[]
collection = cluster.bucket("beer-sample").default_collection()
for _ in range(100):
try:
collection.get("21st_amendment_brewery_cafe")
except CouchbaseException:
logger.error(traceback.format_exc())