import logging


def get_logger(log_file=None):# {{{
    """Set logger and return it.

    If the log_file is not None, log will be written into log_file.
    Else, log will be shown in the screen.

    Args:
        log_file (str): If log_file is not None, log will be written
            into the log_file.

    Return:
        ~Logger

        * **logger**: An Logger object with customed config.

    """
    # Basic config
    logging.basicConfig(
        format='%(asctime)s - %(levelname)s - %(message)s',
        datefmt='%m/%d/%Y %H:%M:%S',
        level=logging.INFO,
    )
    logger = logging.getLogger(__name__)

    # Add filehandler
    if log_file is not None:
        file_handler = logging.FileHandler(log_file, mode='w')
        file_handler.setLevel(logging.INFO)
        file_handler.setFormatter(
            logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
        )
        logger.addHandler(file_handler)

    return logger