Skip to content

Commit

Permalink
use handler for logging to file (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
imatiach-msft authored Oct 27, 2019
1 parent 6945bbf commit 7168a3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions python/interpret_community/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@
# Setup logging infrustructure
import logging
import os
import atexit
# Only log to disk if environment variable specified
interpretc_logs = os.environ.get('INTERPRETC_LOGS')
if interpretc_logs is not None:
logging.basicConfig(filename=interpretc_logs, level=logging.INFO)
logging.info('Initializing logging file for interpret-community')
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.FileHandler(interpretc_logs, mode='w')
handler.setLevel(logging.INFO)
logger.addHandler(handler)
logger.info('Initializing logging file for interpret-community')
def close_handler():
handler.close()
logger.removeHandler(handler)
atexit.register(close_handler)
2 changes: 1 addition & 1 deletion python/interpret_community/common/chained_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ChainedIdentity(object):

def __init__(self, **kwargs):
"""Initialize the ChainedIdentity."""
self._logger = logging.getLogger("interpret").getChild(self.__class__.__name__)
self._logger = logging.getLogger("interpret_community").getChild(self.__class__.__name__)
self._identity = self.__class__.__name__
super(ChainedIdentity, self).__init__(**kwargs)

0 comments on commit 7168a3f

Please sign in to comment.