Skip to content

Commit b9260a1

Browse files
authored
feat: set python logging (#70)
Man it's hard to test the CLI locally.
1 parent acc8f8c commit b9260a1

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

Cargo.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ serde_json = "1.0.138"
2727
stac = { features = [
2828
"geoparquet-compression",
2929
"object-store-all",
30-
], git = "https://github.com/stac-utils/stac-rs", branch = "optional-tracing-cli" }
30+
], git = "https://github.com/stac-utils/stac-rs", branch = "main" }
3131
stac-api = { features = [
3232
"client",
3333
"python",
34-
], git = "https://github.com/stac-utils/stac-rs", branch = "optional-tracing-cli" }
34+
], git = "https://github.com/stac-utils/stac-rs", branch = "main" }
3535
stac-cli = { git = "https://github.com/stac-utils/stac-rs", features = [
3636
"pgstac",
3737
"duckdb",
38-
], branch = "optional-tracing-cli" }
39-
stac-duckdb = { git = "https://github.com/stac-utils/stac-rs", branch = "optional-tracing-cli" }
40-
thiserror = "2.0.11"
38+
], branch = "main" }
39+
stac-duckdb = { git = "https://github.com/stac-utils/stac-rs", branch = "main" }
40+
thiserror = "2.0.12"
4141
tokio = { version = "1.43.0", features = ["rt-multi-thread"] }
4242
pyo3-log = "0.12.1"
43+
tracing = "0.1.41"
4344

4445
[patch.crates-io]
4546
duckdb = { git = "https://github.com/duckdb/duckdb-rs", rev = "5eeb1f01c278790ce1e2d24045f0096e9e2528e4" }

src/cli.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use clap::Parser;
2-
use pyo3::{pyfunction, types::PyAnyMethods, PyResult, Python};
2+
use pyo3::{
3+
pyfunction,
4+
types::{PyAnyMethods, PyDict},
5+
PyResult, Python,
6+
};
37
use stac_cli::Stacrs;
8+
use tracing::Level;
49

510
#[pyfunction]
611
pub fn main(py: Python<'_>) -> PyResult<i64> {
@@ -9,6 +14,16 @@ pub fn main(py: Python<'_>) -> PyResult<i64> {
914
.getattr("signal")?
1015
.call1((signal.getattr("SIGINT")?, signal.getattr("SIG_DFL")?))?;
1116
let args = Stacrs::parse_from(std::env::args_os().skip(1));
17+
let logging = py.import("logging")?;
18+
let kwargs = PyDict::new(py);
19+
kwargs.set_item(
20+
"format",
21+
"'%(levelname)s %(name)s %(asctime)-15s %(filename)s:%(lineno)d %(message)s'",
22+
)?;
23+
logging.getattr("basicConfig")?.call((), Some(&kwargs))?;
24+
let logger = logging.getattr("getLogger")?.call0()?;
25+
let level = args.log_level().unwrap_or(Level::INFO);
26+
logger.call_method1("setLevel", (level.to_string(),))?;
1227
std::process::exit(
1328
tokio::runtime::Builder::new_multi_thread()
1429
.enable_all()

0 commit comments

Comments
 (0)