Skip to content

Commit 0d9a7c8

Browse files
authored
Default proj log level to none (#77)
1 parent 42a16a1 commit 0d9a7c8

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

c/sedona-proj/src/proj.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ impl ProjContext {
130130
}
131131
}
132132

133+
/// Set the logging level for PROJ operations
134+
///
135+
/// `level` - Unsigned Integer value representing the log level:
136+
/// - PJ_LOG_LEVEL_PJ_LOG_NONE (0): No logging
137+
/// - PJ_LOG_LEVEL_PJ_LOG_ERROR (1): Error messages
138+
/// - PJ_LOG_LEVEL_PJ_LOG_DEBUG (2): Debug messages
139+
/// - PJ_LOG_LEVEL_PJ_LOG_TRACE (3): Trace
140+
/// - PJ_LOG_LEVEL_PJ_LOG_TELL (4): Tell
141+
pub(crate) fn set_log_level(&self, level: u32) -> Result<(), SedonaProjError> {
142+
unsafe {
143+
call_proj_api!(self.api, proj_log_level, self.inner, level);
144+
}
145+
Ok(())
146+
}
147+
133148
/// Set the path in which to look for PROJ data files
134149
///
135150
/// Most PROJ distributions come with a few small data files installed to a /share directory

c/sedona-proj/src/transform.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
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};
1719
use sedona_geometry::bounding_box::BoundingBox;
1820
use sedona_geometry::error::SedonaGeometryError;
1921
use sedona_geometry::interval::IntervalTrait;
@@ -22,9 +24,6 @@ use std::cell::RefCell;
2224
use std::path::PathBuf;
2325
use 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

3939
impl 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

Comments
 (0)