import logging
import sys

def create_logger(file_name, level=logging.DEBUG):
    # create logger
    logger = logging.getLogger('runtime_log')
    logger.setLevel(logging.DEBUG)

    # create console handler and set level to debug
    if file_name is not None:
        ch = logging.FileHandler(file_name, mode='a', encoding=None, delay=False)
    else:
        ch = logging.StreamHandler(sys.stdout)
    # FileHandler(filename, mode='a', encoding=None, delay=False) StreamHandler()
    ch.setLevel(level)

    # create formatter
    formatter = logging.Formatter('%(asctime)s - %(name)s -%(funcName)s - %(levelname)s - %(message)s')

    # add formatter to ch
    ch.setFormatter(formatter)

    # add ch to logger
    logger.addHandler(ch)

    # 'application' code
    # logger.debug('debug message')
    # logger.info('info message')
    # logger.warning('warn message')
    # logger.error('error message')
    # logger.critical('critical message')
    return logger

LOGGER=logging.getLogger('runtime_log')
# create_logger(None, level=logging.DEBUG)