Configure the Python SDK to route C++ logs through Python's logging system. This is the programmatic alternative to using PYCBC_LOG_LEVEL environment variable. It allows integration with your application's existing logging configuration. Note: This configures C++ SDK logs only. Py
(name, level=logging.INFO, parent_logger=None)
| 179 | |
| 180 | |
| 181 | def configure_logging(name, level=logging.INFO, parent_logger=None): |
| 182 | """ |
| 183 | Configure the Python SDK to route C++ logs through Python's logging system. |
| 184 | |
| 185 | This is the programmatic alternative to using PYCBC_LOG_LEVEL environment variable. |
| 186 | It allows integration with your application's existing logging configuration. |
| 187 | |
| 188 | Note: This configures C++ SDK logs only. Python-side SDK components (threshold |
| 189 | logging, metrics, transactions) use separate loggers under the 'couchbase' hierarchy. |
| 190 | |
| 191 | To also capture threshold logging reports and other Python SDK logs, configure |
| 192 | the 'couchbase' logger: |
| 193 | |
| 194 | Example: |
| 195 | import logging |
| 196 | from couchbase import configure_logging |
| 197 | |
| 198 | # Configure C++ logs to route through Python |
| 199 | configure_logging('my_app', level=logging.DEBUG) |
| 200 | |
| 201 | # Also capture Python SDK logs (threshold, metrics, transactions, etc.) |
| 202 | couchbase_logger = logging.getLogger('couchbase') |
| 203 | couchbase_logger.addHandler(your_handler) |
| 204 | couchbase_logger.setLevel(logging.INFO) |
| 205 | |
| 206 | Args: |
| 207 | name: Name for the logger |
| 208 | level: Python logging level (default: logging.INFO) |
| 209 | parent_logger: Optional parent logger |
| 210 | |
| 211 | Raises: |
| 212 | RuntimeError: If PYCBC_LOG_LEVEL environment variable is already set. |
| 213 | Cannot use both configuration methods simultaneously. |
| 214 | """ |
| 215 | if parent_logger: |
| 216 | name = f'{parent_logger.name}.{name}' |
| 217 | logger = logging.getLogger(name) |
| 218 | if _PYCBC_LOGGER.is_console_logger() or _PYCBC_LOGGER.is_file_logger(): |
| 219 | raise RuntimeError(('Cannot create logger. Another logger has already been ' |
| 220 | 'initialized. Make sure the PYCBC_LOG_LEVEL and PYCBC_LOG_FILE env ' |
| 221 | 'variable are not set if using configure_logging.')) |
| 222 | _PYCBC_LOGGER.configure_logging_sink(logger, level) |
| 223 | logger.debug(get_metadata(as_str=True)) |
| 224 | |
| 225 | |
| 226 | def enable_protocol_logger_to_save_network_traffic_to_file(filename: str) -> None: |
no test coverage detected