Collecting Information & Logging
Logging.
The Python SDK allows logging via the standard logging
module, or via the LCB_LOGLEVEL
environment variable.
Enabling Logging
import logging
import sys
import couchbase
from couchbase.cluster import Cluster, ClusterOptions
from couchbase_core.cluster import PasswordAuthenticator
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
couchbase.enable_logging()
cluster = Cluster('couchbase://localhost/default',ClusterOptions(PasswordAuthenticator("default","password")))
bucket=cluster.bucket("fred")
coll=bucket.default_collection()
coll.upsert('key', ['value'])
Log Levels
Increase the log level for greater verbosity (more information) in the logs:
-
0 is
LCB_LOG_FATAL
— fatal errors, the library cannot proceed. -
1 is
LCB_LOG_ERROR
— error messages, usually libcouchbase having to re-initialize the connection instance. -
2 is
LCB_LOG_WARN
— error notifications. -
3 is
LCB_LOG_INFO
— useful notices, not often. -
4 is
LCB_LOG_DEBUG
— diagnostic information, required to investigate problems. -
5 is
LCB_LOG_TRACE
— the most verbose level.
Log Redaction
Redacting logs is a two-stage process.
If you want to redact client logs (for example before handing them off to the Couchbase Support team) you first need to enable log redaction in your application.
This is done through the ClusterOptions
to the Cluster object, setting log_redaction
to True
.
Once the SDK writes the logs with the tags to a file, you can then use the
cblogredaction
tool to obfuscate the log.
-
You may wish to read more on Log Redaction in the Server docs.