Skip to content

Commit

Permalink
#464 add_logger is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
aanersc committed Mar 3, 2021
1 parent 74b45bd commit ed13f95
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions nansat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,14 @@ def add_logger(logName='', logLevel=None):
"""
if logLevel is not None:
os.environ['LOG_LEVEL'] = str(logLevel)
# create (or take already existing) logger
# with default logging level WARNING

logger = logging.getLogger(logName)
logger.setLevel(int(os.environ['LOG_LEVEL']))

# if logger already exits, default stream handler has been already added
# otherwise create and add a new handler
if len(logger.handlers) == 0:
# create console handler and set level to debug
ch = logging.StreamHandler()
# create formatter
formatter = logging.Formatter('%(asctime)s|%(levelno)s|%(module)s|'
'%(funcName)s|%(message)s',
datefmt='%I:%M:%S')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)

logger.handlers[0].setLevel(int(os.environ['LOG_LEVEL']))
logger.addHandler(logging.NullHandler())
logger.handlers[0].setLevel(int(os.environ['LOG_LEVEL']))

logger.setLevel(int(os.environ['LOG_LEVEL']))

return logger

Expand Down

0 comments on commit ed13f95

Please sign in to comment.