Skip to content

Commit 57e2b18

Browse files
committed
Last 0.2.8 commit
1 parent cbe2b3b commit 57e2b18

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

hapiclient/log.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
_INTERNAL_HANDLER_ATTR = "_hapiclient_internal_handler"
66
_INTERNAL_LEVEL_ATTR = "_hapiclient_internal_level"
77

8+
# Disable propagation and add NullHandler by default so hapiclient
9+
# is silent unless explicitly configured by user. This is the standard
10+
# practice for library loggers.
11+
_logger.propagate = False
12+
_logger.setLevel(_logging.NOTSET)
13+
if not _logger.handlers:
14+
_null_handler = _logging.NullHandler()
15+
setattr(_null_handler, _INTERNAL_HANDLER_ATTR, True)
16+
_logger.addHandler(_null_handler)
17+
818

919
def configure_logging(opts):
1020
"""Configure the hapiclient logger based on opts['logging'].
@@ -31,13 +41,11 @@ def configure_logging(opts):
3141
_logger.addHandler(_handler)
3242
else:
3343
if has_user_level or has_user_handlers:
34-
if has_user_handlers:
35-
log("Ignoring logging=%s because standard Python logger for 'hapiclient' already configured with handlers." % opts['logging'])
36-
else:
37-
log("Ignoring logging=%s because standard Python logger for 'hapiclient' already configured with log_level != NOTSET." % opts['logging'])
44+
# Don't log when logging is disabled - would cause output during tests
45+
pass
3846
else:
39-
_logger.setLevel(_logging.WARNING)
40-
setattr(_logger, _INTERNAL_LEVEL_ATTR, _logging.WARNING)
47+
_logger.setLevel(_logging.NOTSET)
48+
setattr(_logger, _INTERNAL_LEVEL_ATTR, _logging.NOTSET)
4149

4250

4351
def log(msg, opts=None):

test/test_chunking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
logger = get_logger(__name__)
1313

14-
hapi_logging = True
14+
hapi_logging = False
1515
if logging.getLevelName(logger.level) == 'DEBUG':
1616
hapi_logging = True
1717

0 commit comments

Comments
 (0)