From 4fb1826b7aa82cf979112b440a52cd82ec2b0cc5 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Mon, 3 Mar 2025 16:12:49 -0700 Subject: [PATCH] feat: set python logging --- Cargo.lock | 15 ++++++++------- Cargo.toml | 11 ++++++----- src/cli.rs | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9476e9..bb0d7c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2669,7 +2669,7 @@ dependencies = [ [[package]] name = "pgstac" version = "0.3.0" -source = "git+https://github.com/stac-utils/stac-rs?branch=optional-tracing-cli#d3b89daebe52fc74017f68b8ac3a6c680ac0f964" +source = "git+https://github.com/stac-utils/stac-rs?branch=main#9365c4b5cb23300a4c0d34dccb6b56fc0ba30d1d" dependencies = [ "serde", "serde_json", @@ -3707,7 +3707,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "stac" version = "0.12.0" -source = "git+https://github.com/stac-utils/stac-rs?branch=optional-tracing-cli#d3b89daebe52fc74017f68b8ac3a6c680ac0f964" +source = "git+https://github.com/stac-utils/stac-rs?branch=main#9365c4b5cb23300a4c0d34dccb6b56fc0ba30d1d" dependencies = [ "arrow-array", "arrow-cast", @@ -3738,7 +3738,7 @@ dependencies = [ [[package]] name = "stac-api" version = "0.7.1" -source = "git+https://github.com/stac-utils/stac-rs?branch=optional-tracing-cli#d3b89daebe52fc74017f68b8ac3a6c680ac0f964" +source = "git+https://github.com/stac-utils/stac-rs?branch=main#9365c4b5cb23300a4c0d34dccb6b56fc0ba30d1d" dependencies = [ "async-stream", "chrono", @@ -3764,7 +3764,7 @@ dependencies = [ [[package]] name = "stac-cli" version = "0.5.3" -source = "git+https://github.com/stac-utils/stac-rs?branch=optional-tracing-cli#d3b89daebe52fc74017f68b8ac3a6c680ac0f964" +source = "git+https://github.com/stac-utils/stac-rs?branch=main#9365c4b5cb23300a4c0d34dccb6b56fc0ba30d1d" dependencies = [ "anyhow", "axum", @@ -3782,7 +3782,7 @@ dependencies = [ [[package]] name = "stac-derive" version = "0.2.0" -source = "git+https://github.com/stac-utils/stac-rs?branch=optional-tracing-cli#d3b89daebe52fc74017f68b8ac3a6c680ac0f964" +source = "git+https://github.com/stac-utils/stac-rs?branch=main#9365c4b5cb23300a4c0d34dccb6b56fc0ba30d1d" dependencies = [ "quote", "syn 2.0.99", @@ -3791,7 +3791,7 @@ dependencies = [ [[package]] name = "stac-duckdb" version = "0.1.1" -source = "git+https://github.com/stac-utils/stac-rs?branch=optional-tracing-cli#d3b89daebe52fc74017f68b8ac3a6c680ac0f964" +source = "git+https://github.com/stac-utils/stac-rs?branch=main#9365c4b5cb23300a4c0d34dccb6b56fc0ba30d1d" dependencies = [ "arrow", "chrono", @@ -3809,7 +3809,7 @@ dependencies = [ [[package]] name = "stac-server" version = "0.3.4" -source = "git+https://github.com/stac-utils/stac-rs?branch=optional-tracing-cli#d3b89daebe52fc74017f68b8ac3a6c680ac0f964" +source = "git+https://github.com/stac-utils/stac-rs?branch=main#9365c4b5cb23300a4c0d34dccb6b56fc0ba30d1d" dependencies = [ "axum", "bb8", @@ -3853,6 +3853,7 @@ dependencies = [ "stac-duckdb", "thiserror 2.0.12", "tokio", + "tracing", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fd0fa5d..27c2ade 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,19 +27,20 @@ serde_json = "1.0.138" stac = { features = [ "geoparquet-compression", "object-store-all", -], git = "https://github.com/stac-utils/stac-rs", branch = "optional-tracing-cli" } +], git = "https://github.com/stac-utils/stac-rs", branch = "main" } stac-api = { features = [ "client", "python", -], git = "https://github.com/stac-utils/stac-rs", branch = "optional-tracing-cli" } +], git = "https://github.com/stac-utils/stac-rs", branch = "main" } stac-cli = { git = "https://github.com/stac-utils/stac-rs", features = [ "pgstac", "duckdb", -], branch = "optional-tracing-cli" } -stac-duckdb = { git = "https://github.com/stac-utils/stac-rs", branch = "optional-tracing-cli" } -thiserror = "2.0.11" +], branch = "main" } +stac-duckdb = { git = "https://github.com/stac-utils/stac-rs", branch = "main" } +thiserror = "2.0.12" tokio = { version = "1.43.0", features = ["rt-multi-thread"] } pyo3-log = "0.12.1" +tracing = "0.1.41" [patch.crates-io] duckdb = { git = "https://github.com/duckdb/duckdb-rs", rev = "5eeb1f01c278790ce1e2d24045f0096e9e2528e4" } diff --git a/src/cli.rs b/src/cli.rs index 8cea8b9..5497207 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,11 @@ use clap::Parser; -use pyo3::{pyfunction, types::PyAnyMethods, PyResult, Python}; +use pyo3::{ + pyfunction, + types::{PyAnyMethods, PyDict}, + PyResult, Python, +}; use stac_cli::Stacrs; +use tracing::Level; #[pyfunction] pub fn main(py: Python<'_>) -> PyResult { @@ -9,6 +14,16 @@ pub fn main(py: Python<'_>) -> PyResult { .getattr("signal")? .call1((signal.getattr("SIGINT")?, signal.getattr("SIG_DFL")?))?; let args = Stacrs::parse_from(std::env::args_os().skip(1)); + let logging = py.import("logging")?; + let kwargs = PyDict::new(py); + kwargs.set_item( + "format", + "'%(levelname)s %(name)s %(asctime)-15s %(filename)s:%(lineno)d %(message)s'", + )?; + logging.getattr("basicConfig")?.call((), Some(&kwargs))?; + let logger = logging.getattr("getLogger")?.call0()?; + let level = args.log_level().unwrap_or(Level::INFO); + logger.call_method1("setLevel", (level.to_string(),))?; std::process::exit( tokio::runtime::Builder::new_multi_thread() .enable_all()