Collecting Information & Logging

    +
    Logging.

    The Python SDK allows logging via the standard logging module, or via the LCB_LOGLEVEL environment variable.

    Enabling Logging

    Python Logging Module
    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'])

    Environmental Settings

    In the command line environment, the LCB_LOGLEVEL variable is set as follows:

    GNU/Linux and Mac
    export LCB_LOGLEVEL=[0-5]
    Windows
    set LCB_LOGLEVEL=[0-5]

    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.