Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Use python logging level #2705

Merged
merged 6 commits into from
Aug 24, 2024
Merged

[BUG] Use python logging level #2705

merged 6 commits into from
Aug 24, 2024

Conversation

colin-ho
Copy link
Contributor

@colin-ho colin-ho commented Aug 22, 2024

Example script:

import daft
print("Only warnings and errors should print")
daft.daft.test_logging()

print("\nSetting logging level to debug, all messages should print")
from daft.logging import setup_debug_logger
setup_debug_logger()
daft.daft.test_logging()

Output:

Only warnings and errors should print
WARN from rust
ERROR from rust

Setting logging level to debug, all messages should print
DEBUG:daft.pylib:DEBUG from rust
INFO:daft.pylib:INFO from rust
WARNING:daft.pylib:WARN from rust
ERROR:daft.pylib:ERROR from rust

@github-actions github-actions bot added the bug Something isn't working label Aug 22, 2024
src/lib.rs Outdated
_ => LevelFilter::Error,
};

let logger = pyo3_log::Logger::default().filter(level_filter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only create the logger and install it on the first run.
Currently if the user calls refresh_logger in python it panics.

import daft
daft.refresh_logger()

# PanicException: called `Result::unwrap()` on an `Err` value: SetLoggerError(())

src/lib.rs Outdated

let logger = pyo3_log::Logger::default().filter(level_filter);
let handle = logger.install().unwrap();
LOG_RESET_HANDLE.get_or_init(|| handle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to put everything above in a function and then call that in the get_or_init

let func = || {
        use log::LevelFilter;
        let logging = py.import("logging")?;
        let python_log_level = logging
        ... 

        logger.install().unwrap()
}

LOG_RESET_HANDLE.get_or_init(func).reset();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will ensure that we only init once and that it's reset every time it's called

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also let's add a test for that

Copy link

codspeed-hq bot commented Aug 22, 2024

CodSpeed Performance Report

Merging #2705 will not alter performance

Comparing colin/logging (a2971c8) with main (3647b26)

Summary

✅ 10 untouched benchmarks

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Project coverage is 63.39%. Comparing base (b3f5260) to head (d109504).
Report is 4 commits behind head on main.

Files Patch % Lines
src/lib.rs 90.90% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2705      +/-   ##
==========================================
- Coverage   63.52%   63.39%   -0.13%     
==========================================
  Files         979      978       -1     
  Lines      112148   112180      +32     
==========================================
- Hits        71239    71119     -120     
- Misses      40909    41061     +152     
Files Coverage Δ
src/lib.rs 92.42% <90.90%> (-1.20%) ⬇️

... and 64 files with indirect coverage changes

src/lib.rs Outdated
@@ -63,13 +64,41 @@ pub mod pylib {
}

#[pyfunction]
pub fn refresh_logger() {
pub fn test_logging() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be cleaner to have this return the max log level instead as get_max_log_level()

@colin-ho colin-ho merged commit bf5c853 into main Aug 24, 2024
46 checks passed
@colin-ho colin-ho deleted the colin/logging branch August 24, 2024 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants