Skip to content

Commit

Permalink
Refactor logger setup to improve clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgilbert committed Sep 10, 2018
1 parent a18e265 commit 8340f32
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pdblp/pdblp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@

def _get_logger(debug):
logger = logging.getLogger(__name__)
if (logger.parent is not None) and logger.parent.hasHandlers():
if debug:
logger.warning("'pdblp.BCon.debug=True' is ignored when user "
"specifies logging event handlers")
if (logger.parent is not None) and logger.parent.hasHandlers() and debug:
logger.warning("'pdblp.BCon.debug=True' is ignored when user "
"specifies logging event handlers")
else:
if not logger.handlers:
formatter = logging.Formatter('%(name)s:%(levelname)s:%(message)s')
sh = logging.StreamHandler()
sh.setFormatter(formatter)
logger.addHandler(sh)
if debug:
logger.setLevel(logging.INFO)
else:
logger.setLevel(logging.WARNING)
debug_level = logging.INFO if debug else logging.WARNING
logger.setLevel(debug_level)

return logger

Expand Down

0 comments on commit 8340f32

Please sign in to comment.