Skip to content

Commit e550cb7

Browse files
authored
test(kernel): verify unified file logging (#924)
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
1 parent b4828fb commit e550cb7

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/e2e/test_kernel_backend.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,51 @@ def test_cursor_row_limit(conn, row_limit):
205205
import logging
206206

207207

208+
def test_kernel_and_driver_logs_share_file(kernel_conn_params, tmp_path):
209+
"""A parent ``databricks.sql`` FileHandler captures both layers."""
210+
log_file = tmp_path / "unified.log"
211+
connector_logger = logging.getLogger("databricks.sql")
212+
original_level = connector_logger.level
213+
handler = logging.FileHandler(log_file, encoding="utf-8")
214+
handler.setLevel(logging.DEBUG)
215+
handler.setFormatter(logging.Formatter("%(name)s %(levelname)s %(message)s"))
216+
217+
connector_logger.setLevel(logging.DEBUG)
218+
connector_logger.addHandler(handler)
219+
220+
# Earlier tests in this module may already have populated pyo3-log's
221+
# effective-level cache. Reset it after changing the parent level so this
222+
# test behaves like a user configuring logging before connecting.
223+
reset_logging = getattr(_kernel_mod, "reset_logging", None)
224+
try:
225+
if reset_logging is not None:
226+
reset_logging()
227+
c = sql.connect(**kernel_conn_params)
228+
try:
229+
with c.cursor() as cur:
230+
cur.execute("SELECT 1 AS a")
231+
cur.fetchall()
232+
finally:
233+
c.close()
234+
finally:
235+
connector_logger.removeHandler(handler)
236+
connector_logger.setLevel(original_level)
237+
handler.flush()
238+
handler.close()
239+
if reset_logging is not None:
240+
reset_logging()
241+
242+
lines = log_file.read_text(encoding="utf-8").splitlines()
243+
assert any(
244+
line.startswith("databricks.sql.session ")
245+
and "Creating kernel-backed client for use_kernel=True" in line
246+
for line in lines
247+
), "expected a Python-driver record in the shared log file"
248+
assert any(
249+
line.startswith("databricks.sql.kernel ") for line in lines
250+
), "expected a Rust-kernel record in the shared log file"
251+
252+
208253
def test_kernel_logs_reach_python_logging(kernel_conn_params, caplog):
209254
"""A query at DEBUG produces records on the `databricks.sql.kernel`
210255
logger — proving the tracing -> log -> pyo3-log -> logging chain."""

0 commit comments

Comments
 (0)