diff --git a/c/sedona-proj/src/proj.rs b/c/sedona-proj/src/proj.rs index c57af5948..269570629 100644 --- a/c/sedona-proj/src/proj.rs +++ b/c/sedona-proj/src/proj.rs @@ -130,6 +130,21 @@ impl ProjContext { } } + /// Set the logging level for PROJ operations + /// + /// `level` - Unsigned Integer value representing the log level: + /// - PJ_LOG_LEVEL_PJ_LOG_NONE (0): No logging + /// - PJ_LOG_LEVEL_PJ_LOG_ERROR (1): Error messages + /// - PJ_LOG_LEVEL_PJ_LOG_DEBUG (2): Debug messages + /// - PJ_LOG_LEVEL_PJ_LOG_TRACE (3): Trace + /// - PJ_LOG_LEVEL_PJ_LOG_TELL (4): Tell + pub(crate) fn set_log_level(&self, level: u32) -> Result<(), SedonaProjError> { + unsafe { + call_proj_api!(self.api, proj_log_level, self.inner, level); + } + Ok(()) + } + /// Set the path in which to look for PROJ data files /// /// Most PROJ distributions come with a few small data files installed to a /share directory diff --git a/c/sedona-proj/src/transform.rs b/c/sedona-proj/src/transform.rs index f3bb45116..3ed71cbc8 100644 --- a/c/sedona-proj/src/transform.rs +++ b/c/sedona-proj/src/transform.rs @@ -14,6 +14,8 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. +use crate::error::SedonaProjError; +use crate::proj::{Proj, ProjContext}; use sedona_geometry::bounding_box::BoundingBox; use sedona_geometry::error::SedonaGeometryError; use sedona_geometry::interval::IntervalTrait; @@ -22,9 +24,6 @@ use std::cell::RefCell; use std::path::PathBuf; use std::rc::Rc; -use crate::error::SedonaProjError; -use crate::proj::{Proj, ProjContext}; - /// Builder for a [ProjCrsEngine] /// /// API for specifying various engine parameters. More parameters may @@ -34,6 +33,7 @@ pub struct ProjCrsEngineBuilder { shared_library: Option, database_path: Option, search_paths: Option>, + log_level: Option, } impl ProjCrsEngineBuilder { @@ -82,6 +82,25 @@ impl ProjCrsEngineBuilder { } } + /// Set the PROJ log level + /// + /// Set the verbosity of PROJ logging. The default is no logging, + /// however errors will still be propagated through the error + /// handling. + /// + /// Log level constants are defined in proj_sys: + /// - PJ_LOG_LEVEL_PJ_LOG_NONE (0): No logging + /// - PJ_LOG_LEVEL_PJ_LOG_ERROR (1): Error messages + /// - PJ_LOG_LEVEL_PJ_LOG_DEBUG (2): Debug messages + /// - PJ_LOG_LEVEL_PJ_LOG_TRACE (3): Trace + /// - PJ_LOG_LEVEL_PJ_LOG_TELL (4): Tell + pub fn with_log_level(self, log_level: u32) -> Self { + Self { + log_level: Some(log_level), + ..self + } + } + /// Build a [ProjCrsEngine] with the specified options pub fn build(&self) -> Result { let mut ctx = if let Some(shared_library) = self.shared_library.clone() { @@ -102,6 +121,13 @@ impl ProjCrsEngineBuilder { ctx.set_search_paths(&string_vec)?; } + if let Some(log_level) = &self.log_level { + ctx.set_log_level(*log_level)?; + } else { + // Default log level to none + ctx.set_log_level(0)?; + } + Ok(ProjCrsEngine { ctx: Rc::new(ctx) }) } }