Skip to content

Commit

Permalink
do get max log level
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin Ho authored and Colin Ho committed Aug 23, 2024
1 parent 2836921 commit a2971c8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion daft/daft.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ class PyDaftPlanningConfig:
def build_type() -> str: ...
def version() -> str: ...
def refresh_logger() -> None: ...
def test_logging() -> None: ...
def get_max_log_level() -> str: ...
def __getattr__(name) -> Any: ...
def io_glob(
path: str,
Expand Down
1 change: 1 addition & 0 deletions daft/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def setup_debug_logger(
):
logging.basicConfig(level="DEBUG")
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)

if daft_only:
for handler in root_logger.handlers:
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ pub mod pylib {
}

#[pyfunction]
pub fn test_logging() {
log::debug!("DEBUG from rust");
log::info!("INFO from rust");
log::warn!("WARN from rust");
log::error!("ERROR from rust");
pub fn get_max_log_level() -> &'static str {
log::max_level().as_str()
}

#[pyfunction]
Expand Down Expand Up @@ -122,7 +119,7 @@ pub mod pylib {
m.add_wrapped(wrap_pyfunction!(version))?;
m.add_wrapped(wrap_pyfunction!(build_type))?;
m.add_wrapped(wrap_pyfunction!(refresh_logger))?;
m.add_wrapped(wrap_pyfunction!(test_logging))?;
m.add_wrapped(wrap_pyfunction!(get_max_log_level))?;
Ok(())
}
}
37 changes: 23 additions & 14 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,39 @@
import pytest


def test_logger_initialization(caplog):
def test_logger_initialization():
import daft

daft.daft.test_logging()
rust_level = daft.daft.get_max_log_level()

assert len(caplog.records) == 2
assert caplog.records[0].levelname == "WARNING"
assert caplog.records[1].levelname == "ERROR"
assert rust_level == "WARN"


def test_debug_logger():
import daft
from daft.logging import setup_debug_logger

setup_debug_logger()
rust_level = daft.daft.get_max_log_level()
assert rust_level == "DEBUG"


@pytest.mark.parametrize(
"level, expected",
[
(logging.DEBUG, 4),
(logging.INFO, 3),
(logging.WARNING, 2),
(logging.ERROR, 1),
(logging.DEBUG, "DEBUG"),
(logging.INFO, "INFO"),
(logging.WARNING, "WARN"),
(logging.ERROR, "ERROR"),
],
)
def test_refresh_logger(level, expected, caplog):
def test_refresh_logger(level, expected):
import logging

import daft

caplog.set_level(level)
daft.refresh_logger()
logging.getLogger().setLevel(level)
daft.daft.refresh_logger()

daft.daft.test_logging()
assert len(caplog.records) == expected
rust_level = daft.daft.get_max_log_level()
assert rust_level == expected

0 comments on commit a2971c8

Please sign in to comment.