Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROJ_DEBUG: make ON an alias of 2, and OFF of 1 (fixes #3832) #3835

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions docs/source/usage/environmentvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,17 @@ done by setting the variable with no content::

.. envvar:: PROJ_DEBUG

Set the debug level of PROJ. The default debug level is zero, which results
in no debug output when using PROJ. A number from 1-3, with 3 being the most
verbose setting.
Set the debug level of PROJ.

The following levels are available:
- ``0``: no message.
- ``1``: error messages only (default).
- ``2``: same as 1, with debug messages.
- ``3``: same as 2, with verbose messages.
- ``4``: same as 3, with very verbose messages.

Starting with PROJ 9.3, ``ON`` can be used as an alias for ``2``,
and ``OFF`` as an alias for ``1``.

.. envvar:: PROJ_NETWORK

Expand Down
25 changes: 20 additions & 5 deletions src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <new>

#include "filemanager.hpp"
#include "proj/internal/internal.hpp"
#include "proj/internal/io_internal.hpp"
#include "proj_experimental.h"
#include "proj_internal.h"
Expand Down Expand Up @@ -88,11 +89,25 @@ pj_ctx pj_ctx::createDefault() {

const char *projDebug = getenv("PROJ_DEBUG");
if (projDebug != nullptr) {
const int debugLevel = atoi(projDebug);
if (debugLevel >= -PJ_LOG_TRACE)
ctx.debug_level = debugLevel;
else
ctx.debug_level = PJ_LOG_TRACE;
if (NS_PROJ::internal::ci_equal(projDebug, "ON")) {
ctx.debug_level = PJ_LOG_DEBUG;
} else if (NS_PROJ::internal::ci_equal(projDebug, "OFF")) {
ctx.debug_level = PJ_LOG_ERROR;
rouault marked this conversation as resolved.
Show resolved Hide resolved
} else if (projDebug[0] == '-' ||
(projDebug[0] >= '0' && projDebug[0] <= '9')) {
const int debugLevel = atoi(projDebug);
// Negative debug levels mean that we first start logging when errno
// is set Cf
// https://github.com/OSGeo/PROJ/commit/1c1d04b45d76366f54e104f9346879fd48bfde8e
// This isn't documented for now. Not totally sure we really want
// that...
if (debugLevel >= -PJ_LOG_TRACE)
ctx.debug_level = debugLevel;
else
ctx.debug_level = PJ_LOG_TRACE;
} else {
fprintf(stderr, "Invalid value for PROJ_DEBUG: %s\n", projDebug);
}
}

return ctx;
Expand Down
16 changes: 8 additions & 8 deletions src/grids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3462,19 +3462,19 @@ static PJ_LP pj_hgrid_apply_internal(PJ_CONTEXT *ctx, PJ_LP in,
toltol)); /* prob. slightly faster than hypot() */

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

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

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