Skip to content

Commit

Permalink
Remove logging to file (aws#64)
Browse files Browse the repository at this point in the history
* logger remove file

* remove import
  • Loading branch information
rahul003 authored Aug 7, 2019
1 parent eb0fdef commit 29dfdc7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
4 changes: 3 additions & 1 deletion tornasole_core/tfevent/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import numpy as np
import os, re
from tornasole_core.utils import get_immediate_subdirectories
from tornasole_core.utils import logger
from tornasole_core.utils import get_logger

logger = get_logger()

# hash value of ndarray.dtype is not the same as np.float class
# so we need to convert the type classes below to np.dtype object
Expand Down
46 changes: 20 additions & 26 deletions tornasole_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,34 @@ def flatten(lis):
new_lis.append(item)
return new_lis

logger = None
_logger_level_set = False

def get_logger(path=os.getcwd()):
global logger
if logger is None:
logger = logging.getLogger("tornasole")
fh = logging.FileHandler(os.path.join(path, 'tornasole.log'))
def get_logger():
global _logger_level_set
name = 'tornasole'
if not _logger_level_set:
log_level = os.environ.get('TORNASOLE_LOG_LEVEL', default='info')
log_level = log_level.lower()

if log_level not in ['info', 'debug', 'warning', 'error', 'critical', 'off']:
print('Invalid log level for TORNASOLE_LOG_LEVEL')
log_level = 'info'

if log_level == 'off':
logger.disabled = True
elif log_level == 'critical':
logger.setLevel(logging.CRITICAL)
elif log_level == 'error':
logger.setLevel(logging.ERROR)
elif log_level == 'warning':
logger.setLevel(logging.WARNING)
elif log_level == 'info':
logger.setLevel(logging.INFO)
elif log_level == 'debug':
logger.setLevel(logging.DEBUG)

fh.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(fh)
# logger.propagate = False
return logger
else:
return logger

logging.getLogger(name).disabled = True
else:
if log_level == 'critical':
level = logging.CRITICAL
elif log_level == 'error':
level = logging.ERROR
elif log_level == 'warning':
level = logging.WARNING
elif log_level == 'info':
level = logging.INFO
elif log_level == 'debug':
level = logging.DEBUG
logging.getLogger(name).setLevel(level)
_logger_level_set = True
return logging.getLogger(name)

def get_immediate_subdirectories(a_dir):
return [name for name in os.listdir(a_dir)
Expand Down

0 comments on commit 29dfdc7

Please sign in to comment.