Skip to content

Commit 25f7722

Browse files
authored
Merge pull request OSGeo#3835 from rouault/fix_3832
PROJ_DEBUG: make ON an alias of 2, and OFF of 1 (fixes OSGeo#3832)
2 parents 25367b6 + ef78412 commit 25f7722

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

docs/source/usage/environmentvars.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,17 @@ done by setting the variable with no content::
6969

7070
.. envvar:: PROJ_DEBUG
7171

72-
Set the debug level of PROJ. The default debug level is zero, which results
73-
in no debug output when using PROJ. A number from 1-3, with 3 being the most
74-
verbose setting.
72+
Set the debug level of PROJ.
73+
74+
The following levels are available:
75+
- ``0``: no message.
76+
- ``1``: error messages only (default).
77+
- ``2``: same as 1, with debug messages.
78+
- ``3``: same as 2, with verbose messages.
79+
- ``4``: same as 3, with very verbose messages.
80+
81+
Starting with PROJ 9.3, ``ON`` can be used as an alias for ``2``,
82+
and ``OFF`` as an alias for ``1``.
7583

7684
.. envvar:: PROJ_NETWORK
7785

src/ctx.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <new>
3636

3737
#include "filemanager.hpp"
38+
#include "proj/internal/internal.hpp"
3839
#include "proj/internal/io_internal.hpp"
3940
#include "proj_experimental.h"
4041
#include "proj_internal.h"
@@ -88,11 +89,25 @@ pj_ctx pj_ctx::createDefault() {
8889

8990
const char *projDebug = getenv("PROJ_DEBUG");
9091
if (projDebug != nullptr) {
91-
const int debugLevel = atoi(projDebug);
92-
if (debugLevel >= -PJ_LOG_TRACE)
93-
ctx.debug_level = debugLevel;
94-
else
95-
ctx.debug_level = PJ_LOG_TRACE;
92+
if (NS_PROJ::internal::ci_equal(projDebug, "ON")) {
93+
ctx.debug_level = PJ_LOG_DEBUG;
94+
} else if (NS_PROJ::internal::ci_equal(projDebug, "OFF")) {
95+
ctx.debug_level = PJ_LOG_ERROR;
96+
} else if (projDebug[0] == '-' ||
97+
(projDebug[0] >= '0' && projDebug[0] <= '9')) {
98+
const int debugLevel = atoi(projDebug);
99+
// Negative debug levels mean that we first start logging when errno
100+
// is set Cf
101+
// https://github.com/OSGeo/PROJ/commit/1c1d04b45d76366f54e104f9346879fd48bfde8e
102+
// This isn't documented for now. Not totally sure we really want
103+
// that...
104+
if (debugLevel >= -PJ_LOG_TRACE)
105+
ctx.debug_level = debugLevel;
106+
else
107+
ctx.debug_level = PJ_LOG_TRACE;
108+
} else {
109+
fprintf(stderr, "Invalid value for PROJ_DEBUG: %s\n", projDebug);
110+
}
96111
}
97112

98113
return ctx;

src/grids.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,19 +3462,19 @@ static PJ_LP pj_hgrid_apply_internal(PJ_CONTEXT *ctx, PJ_LP in,
34623462
toltol)); /* prob. slightly faster than hypot() */
34633463

34643464
if (i == 0) {
3465-
/* If we had access to a context, this should go through pj_log, and we
3466-
* should set ctx->errno */
3467-
if (getenv("PROJ_DEBUG"))
3468-
fprintf(stderr,
3469-
"Inverse grid shift iterator failed to converge.\n");
3465+
pj_log(ctx, PJ_LOG_TRACE,
3466+
"Inverse grid shift iterator failed to converge.\n");
3467+
proj_context_errno_set(ctx, PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID);
34703468
t.lam = t.phi = HUGE_VAL;
34713469
return t;
34723470
}
34733471

34743472
/* and again: pj_log and ctx->errno */
3475-
if (del.lam == HUGE_VAL && getenv("PROJ_DEBUG"))
3476-
fprintf(stderr, "Inverse grid shift iteration failed, presumably at "
3477-
"grid edge.\nUsing first approximation.\n");
3473+
if (del.lam == HUGE_VAL) {
3474+
pj_log(ctx, PJ_LOG_TRACE,
3475+
"Inverse grid shift iteration failed, presumably at "
3476+
"grid edge.\nUsing first approximation.\n");
3477+
}
34783478

34793479
in.lam = adjlon(t.lam + extent->west);
34803480
in.phi = t.phi + extent->south;

0 commit comments

Comments
 (0)