Skip to content

Commit bdf325b

Browse files
committed
more logging issues
1 parent e6848a7 commit bdf325b

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

‎hapiclient/log.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def configure_logging(logging):
2626
has_user_handlers = any(
2727
not getattr(handler, _INTERNAL_HANDLER_ATTR, False)
2828
for handler in _logger.handlers
29-
)
29+
) or bool(_logging.root.handlers)
3030

3131
if logging is True:
3232
_logger.setLevel(_logging.INFO)
@@ -39,8 +39,10 @@ def configure_logging(logging):
3939
_handler.setFormatter(_logging.Formatter("%(message)s"))
4040
setattr(_handler, _INTERNAL_HANDLER_ATTR, True)
4141
_logger.addHandler(_handler)
42+
4243
if logging is False:
4344
if has_user_level or has_user_handlers:
45+
_logger.propagate = True # ensure messages reach the user-configured handler
4446
#from .util import warning
4547
if has_user_handlers:
4648
pass

‎misc/hapi_logging_demo.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,8 @@ def reset_hapiclient_logging():
4343
# 2. Log to console using Python's standard logging module
4444
if 4 <= method <= 6:
4545
import logging
46-
logger = logging.getLogger("hapiclient")
47-
logger.setLevel(logging.INFO)
48-
handler = logging.StreamHandler()
49-
formatter = logging.Formatter("%(asctime)s [%(name)s] %(message)s", datefmt="%Y-%m-%dT%H:%M:%S")
50-
formatter.default_msec_format = '%s.%03d'
51-
handler.setFormatter(formatter)
52-
logger.addHandler(handler)
46+
47+
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(name)s] %(message)s", datefmt="%Y-%m-%dT%H:%M:%S")
5348

5449
if method == 4:
5550
# Use standard logging because defined

‎test/test_cache.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
start = '1970-01-01'
2121
stop = '1970-01-01T00:00:03'
2222

23+
import pytest
24+
2325
def test_cache_short():
2426

2527
# Compare read with empty cache with read with hot cache and usecache=True
@@ -36,23 +38,21 @@ def test_cache_short():
3638
assert compare.equal(data, data2)
3739

3840

41+
@pytest.mark.filterwarnings("ignore::hapiclient.util.HAPIWarning")
3942
def test_cache_error():
4043

4144
from unittest.mock import patch
4245

43-
import io
44-
import contextlib
4546
import pathlib
4647
import tempfile
4748
from hapiclient.util import write_atomic
4849

50+
from hapiclient.util import HAPIWarning
51+
4952
def assert_warns(fn, expected):
50-
buf = io.StringIO()
51-
with contextlib.redirect_stderr(buf):
53+
import pytest
54+
with pytest.warns(HAPIWarning, match=expected):
5255
result = fn()
53-
print(buf.getvalue())
54-
msg = f"Expected '{expected}' in stderr: {buf.getvalue()!r}"
55-
assert expected in buf.getvalue(), msg
5656
return result
5757

5858
# Direct calls to write_atomic()

0 commit comments

Comments
 (0)