Skip to content

Commit 93b5b5f

Browse files
author
Martin Gingras
committed
Prevent logging config from screwing with root logger when DeepDiff is used as a lib.
1 parent 877234a commit 93b5b5f

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

deepdiff/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
import logging
2+
3+
4+
if __name__ == '__main__':
5+
logging.basicConfig(format='%(asctime)s %(levelname)8s %(message)s')
6+
7+
18
from .diff import DeepDiff
29
from .search import DeepSearch

deepdiff/diff.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
from itertools import izip_longest as zip_longest
3636
items = 'iteritems'
3737

38-
logging.basicConfig(format='%(asctime)s %(levelname)8s %(message)s')
39-
logger = logging.getLogger()
38+
logger = logging.getLogger(__name__)
4039

4140
IndexedHash = namedtuple('IndexedHash', 'indexes item')
4241

@@ -613,8 +612,8 @@ def add_hash(hashes, item_hash, item, i):
613612
cleaned_item = order_unordered(item)
614613
item_hash = hash(pickle.dumps(cleaned_item))
615614
except: # pragma: no cover
616-
logger.error("Can not produce a hash for %s item in %s and "
617-
"thus not counting this object." % (item, parent), exc_info=True)
615+
logger.warning("Can not produce a hash for %s item in %s and "
616+
"thus not counting this object." % (item, parent), exc_info=True)
618617
else:
619618
add_hash(hashes, item_hash, item, i)
620619
return hashes

deepdiff/search.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
numbers = (int, float, long, complex, datetime.datetime, datetime.date, Decimal)
2828
items = 'iteritems'
2929

30-
logging.basicConfig(format='%(asctime)s %(levelname)8s %(message)s')
31-
logger = logging.getLogger()
30+
logger = logging.getLogger(__name__)
3231

3332

3433
INDEX_VS_ATTRIBUTE = ('[%s]', '.%s')

0 commit comments

Comments
 (0)