Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pyo3/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ changes go in the root `NEXT_CHANGELOG.md`.
### Added

### Changed
- Log records below every Python logger's level are now dropped before they reach the Python logging bridge, which cuts client CPU per query. Levels set before a `Session` is created take effect without `reset_logging()`. A level raised while a session is open applies from the next `Session` or `reset_logging()` call, for every logger (before, loggers that had not logged yet picked it up on their own). A level assigned directly (`logger.level = ...`) instead of with `setLevel()` needs `reset_logging()`.

### Updated

Expand Down
19 changes: 14 additions & 5 deletions pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ fn init_logging(py: Python<'_>) -> bool {
logging::init_logging(py)
}

/// Clear cached logger levels so a Python-side logging reconfiguration
/// applied *after* the first kernel log (e.g. raising
/// `databricks.sql.kernel` to DEBUG mid-session) takes effect.
/// Re-read the Python logger levels and clear cached ones so a Python-side
/// logging reconfiguration applied *after* the first kernel log (e.g.
/// raising `databricks.sql.kernel` to DEBUG mid-session) takes effect.
/// Levels set before a `Session` is created apply without this call.
#[pyfunction]
fn reset_logging() {
logging::reset_logging();
fn reset_logging(py: Python<'_>) {
logging::reset_logging(py);
}

/// The level below which kernel log records are dropped before reaching
/// Python (`"WARN"`, `"DEBUG"`, ...). Private; for tests.
#[pyfunction]
fn _log_max_level() -> &'static str {
logging::max_level_name()
}

#[pymodule]
Expand All @@ -89,6 +97,7 @@ fn databricks_sql_kernel(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<result_stream::ResultStream>()?;
m.add_function(wrap_pyfunction!(init_logging, m)?)?;
m.add_function(wrap_pyfunction!(reset_logging, m)?)?;
m.add_function(wrap_pyfunction!(_log_max_level, m)?)?;

// Install the log bridge at module import so *any* consumer of the
// bare wheel (the connector, integration tests, custom embedders)
Expand Down
Loading
Loading