1414// KIND, either express or implied. See the License for the
1515// specific language governing permissions and limitations
1616// under the License.
17+ use crate :: error:: SedonaProjError ;
18+ use crate :: proj:: { Proj , ProjContext } ;
1719use sedona_geometry:: bounding_box:: BoundingBox ;
1820use sedona_geometry:: error:: SedonaGeometryError ;
1921use sedona_geometry:: interval:: IntervalTrait ;
@@ -22,9 +24,6 @@ use std::cell::RefCell;
2224use std:: path:: PathBuf ;
2325use std:: rc:: Rc ;
2426
25- use crate :: error:: SedonaProjError ;
26- use crate :: proj:: { Proj , ProjContext } ;
27-
2827/// Builder for a [ProjCrsEngine]
2928///
3029/// API for specifying various engine parameters. More parameters may
@@ -34,6 +33,7 @@ pub struct ProjCrsEngineBuilder {
3433 shared_library : Option < PathBuf > ,
3534 database_path : Option < PathBuf > ,
3635 search_paths : Option < Vec < PathBuf > > ,
36+ log_level : Option < u32 > ,
3737}
3838
3939impl ProjCrsEngineBuilder {
@@ -82,6 +82,25 @@ impl ProjCrsEngineBuilder {
8282 }
8383 }
8484
85+ /// Set the PROJ log level
86+ ///
87+ /// Set the verbosity of PROJ logging. The default is no logging,
88+ /// however errors will still be propagated through the error
89+ /// handling.
90+ ///
91+ /// Log level constants are defined in proj_sys:
92+ /// - PJ_LOG_LEVEL_PJ_LOG_NONE (0): No logging
93+ /// - PJ_LOG_LEVEL_PJ_LOG_ERROR (1): Error messages
94+ /// - PJ_LOG_LEVEL_PJ_LOG_DEBUG (2): Debug messages
95+ /// - PJ_LOG_LEVEL_PJ_LOG_TRACE (3): Trace
96+ /// - PJ_LOG_LEVEL_PJ_LOG_TELL (4): Tell
97+ pub fn with_log_level ( self , log_level : u32 ) -> Self {
98+ Self {
99+ log_level : Some ( log_level) ,
100+ ..self
101+ }
102+ }
103+
85104 /// Build a [ProjCrsEngine] with the specified options
86105 pub fn build ( & self ) -> Result < ProjCrsEngine , SedonaProjError > {
87106 let mut ctx = if let Some ( shared_library) = self . shared_library . clone ( ) {
@@ -102,6 +121,13 @@ impl ProjCrsEngineBuilder {
102121 ctx. set_search_paths ( & string_vec) ?;
103122 }
104123
124+ if let Some ( log_level) = & self . log_level {
125+ ctx. set_log_level ( * log_level) ?;
126+ } else {
127+ // Default log level to none
128+ ctx. set_log_level ( 0 ) ?;
129+ }
130+
105131 Ok ( ProjCrsEngine { ctx : Rc :: new ( ctx) } )
106132 }
107133}
0 commit comments