diff options
| author | Thomas Knudsen <busstoptaktik@users.noreply.github.com> | 2017-11-28 18:34:02 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-28 18:34:02 +1300 |
| commit | 1c1d04b45d76366f54e104f9346879fd48bfde8e (patch) | |
| tree | 28b9812adef7549676de8bd48f8c8aa44eb7adfb /src | |
| parent | 8c6fe8b673c9876e7301d4a890403a931540c17c (diff) | |
| download | PROJ-1c1d04b45d76366f54e104f9346879fd48bfde8e.tar.gz PROJ-1c1d04b45d76366f54e104f9346879fd48bfde8e.zip | |
Enable selective debug printout through negative PROJ_DEBUG values (#689)
* Enable selective debug printout through negative PROJ_DEBUG values
Diffstat (limited to 'src')
| -rw-r--r-- | src/pj_ctx.c | 2 | ||||
| -rw-r--r-- | src/pj_internal.c | 2 | ||||
| -rw-r--r-- | src/pj_log.c | 11 | ||||
| -rw-r--r-- | src/proj_api.h | 5 |
4 files changed, 15 insertions, 5 deletions
diff --git a/src/pj_ctx.c b/src/pj_ctx.c index 326249ac..fc52f300 100644 --- a/src/pj_ctx.c +++ b/src/pj_ctx.c @@ -84,7 +84,7 @@ projCtx pj_get_default_ctx() if( getenv("PROJ_DEBUG") != NULL ) { - if( atoi(getenv("PROJ_DEBUG")) > 0 ) + if( atoi(getenv("PROJ_DEBUG")) >= -PJ_LOG_DEBUG_MINOR ) default_context.debug_level = atoi(getenv("PROJ_DEBUG")); else default_context.debug_level = PJ_LOG_DEBUG_MINOR; diff --git a/src/pj_internal.c b/src/pj_internal.c index efa9bd1f..8a5d2d15 100644 --- a/src/pj_internal.c +++ b/src/pj_internal.c @@ -183,7 +183,7 @@ enum proj_log_level proj_log_level (PJ_CONTEXT *ctx, enum proj_log_level log_lev ctx = pj_get_default_ctx(); if (0==ctx) return PJ_LOG_TELL; - previous = ctx->debug_level; + previous = abs (ctx->debug_level); if (PJ_LOG_TELL==log_level) return previous; ctx->debug_level = log_level; diff --git a/src/pj_log.c b/src/pj_log.c index 2525d050..bab5f078 100644 --- a/src/pj_log.c +++ b/src/pj_log.c @@ -51,8 +51,17 @@ void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args ) { char *msg_buf; + int debug_level = ctx->debug_level; + int shutup_unless_errno_set = debug_level < 0; - if( level > ctx->debug_level ) + /* For negative debug levels, we first start logging when errno is set */ + if (ctx->last_errno==0 && shutup_unless_errno_set) + return; + + if (debug_level < 0) + debug_level = -debug_level; + + if( level > debug_level ) return; msg_buf = (char *) malloc(100000); diff --git a/src/proj_api.h b/src/proj_api.h index b57d9f38..50999b71 100644 --- a/src/proj_api.h +++ b/src/proj_api.h @@ -72,15 +72,16 @@ extern "C" { #ifndef PROJ_H extern char const pj_release[]; /* global release id string */ extern int pj_errno; /* global error return code */ +#endif -/* In proj.h these macros are replaced by the enumeration pj_log_level */ +#ifndef PROJ_INTERNAL_H +/* replaced by enum proj_log_level in proj_internal.h */ #define PJ_LOG_NONE 0 #define PJ_LOG_ERROR 1 #define PJ_LOG_DEBUG_MAJOR 2 #define PJ_LOG_DEBUG_MINOR 3 #endif - #ifdef PROJ_API_H_NOT_INVOKED_AS_PRIMARY_API /* These make the function declarations below conform with classic proj */ typedef PJ *projPJ; /* projPJ is a pointer to PJ */ |
