aboutsummaryrefslogtreecommitdiff
path: root/src/log.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-12-16 15:12:51 +0100
committerGitHub <noreply@github.com>2020-12-16 15:12:51 +0100
commit5e077729274f5d28e137e1a41f7d3350146614ef (patch)
treed1ef799526f06828328b58ce8ee92c028f723b6a /src/log.cpp
parent8b1ef9504d0bcfbd8433df943e307bbd1aa30c4f (diff)
parenta27c0255e7b8e6aab1b91e49fd7870d1ee4e1a80 (diff)
downloadPROJ-5e077729274f5d28e137e1a41f7d3350146614ef.tar.gz
PROJ-5e077729274f5d28e137e1a41f7d3350146614ef.zip
Merge pull request #2487 from rouault/error_mgt_improvements
Error management: revise error codes and expose them to the public API
Diffstat (limited to 'src/log.cpp')
-rw-r--r--src/log.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/log.cpp b/src/log.cpp
index c343e65b..c50b0ebc 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -96,3 +96,93 @@ void pj_log( PJ_CONTEXT *ctx, int level, const char *fmt, ... )
pj_vlog( ctx, level, fmt, args );
va_end( args );
}
+
+
+
+/***************************************************************************************/
+PJ_LOG_LEVEL proj_log_level (PJ_CONTEXT *ctx, PJ_LOG_LEVEL log_level) {
+/****************************************************************************************
+ Set logging level 0-3. Higher number means more debug info. 0 turns it off
+****************************************************************************************/
+ PJ_LOG_LEVEL previous;
+ if (nullptr==ctx)
+ ctx = pj_get_default_ctx();
+ if (nullptr==ctx)
+ return PJ_LOG_TELL;
+ previous = static_cast<PJ_LOG_LEVEL>(abs (ctx->debug_level));
+ if (PJ_LOG_TELL==log_level)
+ return previous;
+ ctx->debug_level = log_level;
+ return previous;
+}
+
+/*****************************************************************************/
+static std::string add_short_name_prefix(const PJ* P, const char* fmt)
+/*****************************************************************************/
+{
+ if( P->short_name == nullptr )
+ return fmt;
+ std::string ret(P->short_name);
+ ret += ": ";
+ ret += fmt;
+ return ret;
+}
+
+/*****************************************************************************/
+void proj_log_error (const PJ *P, const char *fmt, ...) {
+/******************************************************************************
+ For reporting the most severe events.
+******************************************************************************/
+ va_list args;
+ va_start( args, fmt );
+ pj_vlog (pj_get_ctx ((PJ*)P), PJ_LOG_ERROR , add_short_name_prefix(P, fmt).c_str(), args);
+ va_end( args );
+}
+
+
+/*****************************************************************************/
+void proj_log_debug (PJ *P, const char *fmt, ...) {
+/******************************************************************************
+ For reporting debugging information.
+******************************************************************************/
+ va_list args;
+ va_start( args, fmt );
+ pj_vlog (pj_get_ctx (P), PJ_LOG_DEBUG , add_short_name_prefix(P, fmt).c_str(), args);
+ va_end( args );
+}
+
+/*****************************************************************************/
+void proj_context_log_debug (PJ_CONTEXT *ctx, const char *fmt, ...) {
+/******************************************************************************
+ For reporting debugging information.
+******************************************************************************/
+ va_list args;
+ va_start( args, fmt );
+ pj_vlog (ctx, PJ_LOG_DEBUG , fmt, args);
+ va_end( args );
+}
+
+/*****************************************************************************/
+void proj_log_trace (PJ *P, const char *fmt, ...) {
+/******************************************************************************
+ For reporting embarrassingly detailed debugging information.
+******************************************************************************/
+ va_list args;
+ va_start( args, fmt );
+ pj_vlog (pj_get_ctx (P), PJ_LOG_TRACE , add_short_name_prefix(P, fmt).c_str(), args);
+ va_end( args );
+}
+
+
+/*****************************************************************************/
+void proj_log_func (PJ_CONTEXT *ctx, void *app_data, PJ_LOG_FUNCTION logf) {
+/******************************************************************************
+ Put a new logging function into P's context. The opaque object app_data is
+ passed as first arg at each call to the logger
+******************************************************************************/
+ if (nullptr==ctx)
+ ctx = pj_get_default_ctx ();
+ ctx->logger_app_data = app_data;
+ if (nullptr!=logf)
+ ctx->logger = logf;
+}