Skip to content

Commit

Permalink
BUG: Set default PROJ log level to ERROR
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Feb 16, 2021
1 parent 93bca99 commit 6c1a55e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Change Log
* Use `proj_context_errno_string` in PROJ 8+ due to deprecation (issue #760)
* BUG: Allow transformations with empty arrays (issue #766)
* BUG: support numpy objects in CRS.from_cf (issue #773)
* BUG: Set default PROJ log level to ERROR (pull #774)

3.0.0
-----
Expand Down
4 changes: 4 additions & 0 deletions pyproj/_datadir.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ _LOGGER.addHandler(logging.NullHandler())
# default to False is the safest mode
# as it supports multithreading
_USE_GLOBAL_CONTEXT = strtobool(os.environ.get("PYPROJ_GLOBAL_CONTEXT", "OFF"))
# used to ensure not changed if set
_PROJ_DEBUG = os.environ.get("PROJ_DEBUG")
# static user data directory to prevent core dumping
# see: https://github.com/pyproj4/pyproj/issues/678
cdef const char* _USER_DATA_DIR = proj_context_get_user_writable_directory(NULL, False)
Expand Down Expand Up @@ -126,6 +128,8 @@ cdef void pyproj_context_initialize(PJ_CONTEXT* context) except *:
"""
Setup the context for pyproj
"""
if _PROJ_DEBUG is None:
proj_log_level(context, PJ_LOG_ERROR)
proj_log_func(context, NULL, pyproj_log_function)
proj_context_use_proj4_init_rules(context, 1)
proj_context_set_autoclose_database(context, not _USE_GLOBAL_CONTEXT)
Expand Down
1 change: 1 addition & 0 deletions pyproj/proj.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cdef extern from "proj.h":
PJ_LOG_TELL = 4
ctypedef void (*PJ_LOG_FUNCTION)(void *, int, const char *)
void proj_log_func (PJ_CONTEXT *ctx, void *app_data, PJ_LOG_FUNCTION logf)
PJ_LOG_LEVEL proj_log_level (PJ_CONTEXT *ctx, PJ_LOG_LEVEL log_level)

int proj_errno (const PJ *P) nogil
int proj_context_errno (PJ_CONTEXT *ctx)
Expand Down
7 changes: 5 additions & 2 deletions test/test_datadir.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from pyproj.enums import PJType
from pyproj.exceptions import CRSError
from test.conftest import proj_env
from test.conftest import PROJ_GTE_8, proj_env


@contextmanager
Expand Down Expand Up @@ -237,7 +237,10 @@ def test_proj_debug_logging(capsys):
assert "PROJ_TRACE" not in captured.err
assert "PROJ_DEBUG" in captured.err
else:
assert captured.err == ""
if PROJ_GTE_8:
assert "PROJ_ERROR" in captured.err
else:
assert captured.err == ""


def test_proj_debug_logging__error(capsys):
Expand Down

0 comments on commit 6c1a55e

Please sign in to comment.