Skip to content

Commit ef78412

Browse files
committed
PROJ_DEBUG: make ON an alias of 2, and OFF of 1 (fixes OSGeo#3832)
and emits a stderr message when the value specified isn't understood
1 parent 1b14212 commit ef78412

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
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;

0 commit comments

Comments
 (0)