Skip to content

Commit a05bb77

Browse files
committed
[mwclient#82] Configure default logging handler
Add a null handler to prevent 'No handlers could be found for logger "mwclient.*"' warnings. This seems to be good practice for libraries.
1 parent a93c58a commit a05bb77

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mwclient/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@
2626
from errors import *
2727
from client import Site, __ver__
2828
import ex
29+
30+
# Logging: Add a null handler to avoid "No handler found" warnings.
31+
import logging
32+
try:
33+
from logging import NullHandler
34+
except ImportError:
35+
class NullHandler(logging.Handler):
36+
def emit(self, record):
37+
pass
38+
39+
logging.getLogger(__name__).addHandler(NullHandler())

0 commit comments

Comments
 (0)